Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[hover card] fix bug for quickly enter/leave card cannot dismiss card correctly #3606

Merged
merged 2 commits into from
Jan 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"packageName": "office-ui-fabric-react",
"comment": "fix hover card dismiss issue",
"type": "patch"
}
],
"packageName": "office-ui-fabric-react",
"email": "lingge@microsoft.com"
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ export class HoverCard extends BaseComponent<IHoverCardProps, IHoverCardState> {
}
}

public componentWillUpdate(newProps: IHoverCardProps, newState: IHoverCardState) {
if (newState.isHoverCardVisible !== this.state.isHoverCardVisible) {
if (newState.isHoverCardVisible) {
public componentDidUpdate(prevProps: IHoverCardProps, prevState: IHoverCardState) {
if (prevState.isHoverCardVisible !== this.state.isHoverCardVisible) {
if (this.state.isHoverCardVisible) {
this._async.setTimeout(() => {
this.setState({
mode: ExpandingCardMode.expanded
Expand Down Expand Up @@ -162,14 +162,17 @@ export class HoverCard extends BaseComponent<IHoverCardProps, IHoverCardState> {

@autobind
private _executeCardOpen(ev: MouseEvent) {
this._async.clearTimeout(this._openTimerId);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we move this._async.clearTimeout(this._dismissTimerId) in _cardOpen here for consistency with _executeCardDismiss?

this._openTimerId = this._async.setTimeout(() => {
if (!this.state.isHoverCardVisible) {
this.setState({
isHoverCardVisible: true,
mode: ExpandingCardMode.compact,
openMode: ev.type === 'keydown' ? OpenCardMode.hotKey : OpenCardMode.hover
});
}
this.setState((prevState: IHoverCardState) => {
if (!prevState.isHoverCardVisible) {
return ({
isHoverCardVisible: true,
mode: ExpandingCardMode.compact,
openMode: ev.type === 'keydown' ? OpenCardMode.hotKey : OpenCardMode.hover
});
}
});
}, this.props.cardOpenDelay!);
}

Expand All @@ -179,7 +182,6 @@ export class HoverCard extends BaseComponent<IHoverCardProps, IHoverCardState> {
if (ev.type === 'keydown' && (ev.which !== KeyCodes.escape)) {
return;
}
this._async.clearTimeout(this._openTimerId);

// Dismiss if not sticky and currentTarget is the same element that mouse last entered
if (!this.props.sticky && (this._currentMouseTarget === ev.currentTarget || (ev.which === KeyCodes.escape))) {
Expand All @@ -189,6 +191,8 @@ export class HoverCard extends BaseComponent<IHoverCardProps, IHoverCardState> {

@autobind
private _executeCardDimiss() {
this._async.clearTimeout(this._openTimerId);
this._async.clearTimeout(this._dismissTimerId);
this._dismissTimerId = this._async.setTimeout(() => {
this.setState({
isHoverCardVisible: false,
Expand All @@ -201,9 +205,15 @@ export class HoverCard extends BaseComponent<IHoverCardProps, IHoverCardState> {
// Instant Open the card in Expanded mode
@autobind
private _instantOpenExpanded(ev: React.MouseEvent<HTMLDivElement>) {
this.setState({
isHoverCardVisible: true,
mode: ExpandingCardMode.expanded
this._async.clearTimeout(this._dismissTimerId);

this.setState((prevState: IHoverCardState) => {
if (!prevState.isHoverCardVisible) {
return ({
isHoverCardVisible: true,
mode: ExpandingCardMode.expanded
});
}
});
}
}