-
Notifications
You must be signed in to change notification settings - Fork 408
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
Add onMenuHide
callback
#210
Comments
onMenuHide
callback
Thanks for the in-depth explanation and code examples. Seems pretty reasonable to add an In the meantime, you might be able to just set the timeout to |
Added in v2.0.0-alpha.1 |
No, a zero timeout didn't work - I tried this first of all, but something to do with React update cycle and/or DOM events apparently causes a significant delay between onBlur and onClick - even at 100ms delay it was intermittent (testing on a slowish laptop). 500ms was definitely enough so I didn't spend further time analysing but it's probably worth being aware of this, I'm guessing it would affect low spec computers more. Anyway thanks for the really fast update, much happier to have the proper solution ;) |
Firstly thanks for this component, I looked at a few autocomplete components and they all seemed bloated and didn't really solve my fairly simple requirements, but this one was almost perfect right out of the box. However there is a small use case that it doesn't answer and I've worked around with a horrible hack for now ;) Hopefully it's a fairly simple feature request.
My use case is as follows:
a) user chooses a year from the list (by clicking an item, or by typing / cursoring and pressing enter)
b) user cancels by pressing esc
c) control loses focus due to tabbing or by clicking elsewhere on the page
With the current API I'm unable to answer all three of these requirements. onBlur is not helpful here because destroying the Typeahead during the onBlur event means that (a) doesn't work - the input blurs and the component gets unmounted before the component can respond to the click on the menu item; so onChange never gets fired. My onBlur handler was simply this:
And my render method (simplified for clarity) was like this:
So, a tweak to onBlur to ensure that it happens after any menu clicks would partially solve this, but I still don't think it could solve (b). So all that is needed to fully solve my case would be a callback like "onCloseMenu" which gets fired any time the component closes the menu for any reason. Presumably it would be natural for this to happen after the onChange handler caused by clicking on the menu. Additionally for parity maybe there should be an onOpenMenu (but I don't have a use case for this).
Hopefully this sounds like a reasonable feature request and potentially not too hard to implement! My current hacky workaround is really a bit flaky and looks like this:
The text was updated successfully, but these errors were encountered: