Skip to content

Commit

Permalink
fix(OverlayTrigger): Do not increase delay of hiding/showing if asked to
Browse files Browse the repository at this point in the history
show or hide multiple times

[fixes #131134283]

Signed-off-by: Yucheng Tu <ytu@pivotal.io>
  • Loading branch information
charleshansen committed Sep 27, 2016
1 parent 2346806 commit c08e13e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,17 @@ describe('OverlayTrigger', function() {
jasmine.clock().tick(3000);
expect(subject.setState).not.toHaveBeenCalled();
});

it('does not delay an action if it happens repeatedly', () => {
subject::setProps({delay: 3000});
subject.show();
expect('.tooltip-text').not.toExist();
jasmine.clock().tick(1000);
subject.show();
expect('.tooltip-text').not.toExist();
jasmine.clock().tick(2000);
expect('.tooltip-text').toExist();
});
});
});

Expand Down
18 changes: 15 additions & 3 deletions library/src/pivotal-ui-react/overlay-trigger/overlay-trigger.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,24 @@ class OverlayTrigger extends mixin(React.Component).with(Scrim) {
};

setDisplay = (display) => {
clearTimeout(privates.get(this).timeout);
if(display === this.state.display) return;
const oldTimeout = privates.get(this).timeout;

if(display === this.state.display) {
clearTimeout(oldTimeout);
privates.set(this, {timeout: null});
return;
}

const delay = this.getDelay(display);

if(oldTimeout && delay) return;

let timeout;
if(delay) {
timeout = setTimeout(() => {this.setState({display})}, delay);
timeout = setTimeout(() => {
privates.set(this, {timeout: null});
this.setState({display})
}, delay);
} else {
this.setState({display});
}
Expand Down

0 comments on commit c08e13e

Please sign in to comment.