feat: add delay prop to Tooltip#143
Conversation
| toggle: PropTypes.func, | ||
| children: PropTypes.node | ||
| children: PropTypes.node, | ||
| delay: PropTypes.oneOfType([PropTypes.object, PropTypes.number]) |
There was a problem hiding this comment.
Why not use PropTypes.shape to define the object instead of just the generic object since you are mandating that show and hide have to be a number in getDelay. It avoids the NaN check and would give developers a specific message when they don't use the right shape.
If you do not use shape and keep the NaN check, then you should probably add a test for when something other than a number is passed.
Speaking of tests, I don't really see one that tests what happens when only hide or show(not both) are in the object. The code does account for this scenario, but the tests do not ensure it works (in the future, someone may break this and without tests, no one will know)
There was a problem hiding this comment.
Yeah good idea, I'll use shape instead. And I can add a couple of tests to check that the hide or show defaults are picked up 👍
| onTimeout() { | ||
| if (this.props.isOpen) { | ||
| this.toggle(); | ||
| getDelay(key) { |
There was a problem hiding this comment.
Instead of running this on every mouse over and mouse leave, why not do this when it mounts and each time props update. It will help avoid overhead.
There was a problem hiding this comment.
It's true that that would reduce some overhead, but I feel the tiny performance increase would not be worth complicating the code with extra lifecycle logic.
It's only a couple of direct accesses from the props and an if statement, and mouseover and mouseleave events aren't realistically going to happen very often unless the user is flailing the mouse around.
| clearTimeout(this._hideTimeout); | ||
| } | ||
| if (this._showTimeout) { | ||
| clearTimeout(this._showTimeout); |
There was a problem hiding this comment.
You need to clear out this.showTimeout and this.hideTimeout. You can simply set them to undefined. Without clearing them out, they will still be truthy and thus, every click after the have been set will trigger the clearTimeout, even if the timeout has already been cleared.
There was a problem hiding this comment.
If fact, everywhere you use clearTimeout you will have this problem. It needs to clear the timeout and unset the var that contains the timeout id (this._showTimeout and this.hideTimeout).
Also, when the timeout triggers the function (show/hide) they need to clear the var containing their respective timeout id (this._showTimeout and this.hideTimeout respectfully).
It would probably be useful to have a helper method to do this. like clearShowTimeout and clearHideTimeout since this code is already duplicated in a few places.
There was a problem hiding this comment.
Yeah that's true, it would run clearTimeout unnecessarily. That must have already been an issue before this PR though, because there was no unsetting of the timeout property either. But I may as well include that change in this PR just to tidy it up.
ddc1164 to
dd9fd68
Compare
|
When |
|
Well now the propType for delay is |
|
I think the shape will ensure that there are no extra properties/the properties are of the type defined, but it will not ensure that the properties are there. You have to add isRequired to ensure they are there. Something like http://stackoverflow.com/a/26924696/1873485 Edit: Sorry, I didn't mean to indicate that this should be done here, but it illustrate the difference between defining the shape and mandating the shape by showing how to require the props. |
Previous delay was harcoded value of 250ms for the 'hide', and 0 for the
'show'.
New prop 'delay' allows for either an object of form: { show: 100, hide:
200 } or simply a number to set these delays.
Default is { show: 0, hide: 250 }
Closes reactstrap#115
dd9fd68 to
be8a2b4
Compare
be8a2b4 to
968596c
Compare
|
@TheSharpieOne Ok I think this is ready |
|
If |
| expect(isOpen).toBe(false); | ||
| }); | ||
| }); | ||
|
|
There was a problem hiding this comment.
this comment mentions adding a test here for partial delay object. It's fine to add a test case that expects an error, and then fix in another pr or grab the value from the default object which I'd like to eventually be the way this works.
There was a problem hiding this comment.
Yep OK fair enough, it should be a quick fix so I'll just get it in this PR.
|
thanks for working through this @alisd23 & @TheSharpieOne |
| tether: PropTypes.oneOfType([PropTypes.object, PropTypes.bool]), | ||
| // optionally overide tether config http://tether.io/#options | ||
| delay: PropTypes.oneOfType([ | ||
| PropTypes.shape({ show: PropTypes.number.isRequired, hide: PropTypes.number.isRequired }), |
There was a problem hiding this comment.
Tiny thing. Docs still showing it was required.
b8394ec to
1923fe6
Compare
Previous delay was a harcoded value of 250ms for the hide, and no delay for the
show.
New prop
delayallows for either an object of form:{ show: 100, hide: 200 }or simply a number to set these delays.Default is
{ show: 0, hide: 250 }Closes #115