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

onFocus is not exposed for overridden #88

Closed
quockhanhle93 opened this issue Apr 22, 2020 · 9 comments
Closed

onFocus is not exposed for overridden #88

quockhanhle93 opened this issue Apr 22, 2020 · 9 comments

Comments

@quockhanhle93
Copy link

Hi there,

We are currently using the react-dropdown-select in our project. Is it possible to override the onFocus Function of index.js line 486?

We would really appreciate to handle it by ourselves because we do not want the dropdown to open automatically on focus but will receive a :focus pseudoclass, or handle some styling. We just want to open the dropdown on pressing Enter on keyboard.

Thank you and best wishes
Khanh

@sanusart
Copy link
Owner

sanusart commented Apr 22, 2020

Hi @quockhanhle93,
Exposing onFocus will not be enough, there are way more triggers for opening the dropdown.

What you can do is to toggle the dropdown using handleKeyDownFn prop and react on Enter key.

For example: https://codesandbox.io/s/open-on-top-w1yr0

handleKeyDownFn signature is:handleKeyDownFn = ({ event, state, props, methods, setState }) => {};

@quockhanhle93
Copy link
Author

Hi @sanusart,

That sounds great to use styled-components and handleKeyDownFn to toggle the dropdown as your example. It works for me, but it seems that the dropdown is still opened and onDropdownOpen Function is already triggered before pressing on Enter key.

Anyway, it is good so far. Thanks for your great helps.

@sanusart
Copy link
Owner

Hey yes I know. It is kind of triking the component visually only.
I just think it would be a bit of overkill to add drop-down open preventing mechanism. Specially when the whole point of the lib is drop-down.

We can see how your use case can be handled more properly. The example above is obviously a simple one.

@quockhanhle93
Copy link
Author

Thanks @sanusart, let me open this discussion a little bit. :)

We try to improve current user experience. In fact, we have a form of more than 10 dropdowns, it is fine to click on each dropdown to open and choose from the list of options. However, we are encouraging users on using Tab (working with keyboard is much faster than mouse click) to switch and control the input. There are some issues:

  • The dropdown is opened automatically on focus. For some reasons, user just wants to tab and pass over this dropdown, but it is now opened. User has to close it before moving to the next element.
  • Your example is useful, and can be considered as a workaround. But, we really want to provide a different stylesheet onDropdownOpen and onDropdownClose (just add/remove the element's classname).

We are looking around for finding a suitable dropdown, and realize that your repository is best fit to our need. It is appreciated to have this feature, not just for onFocus, but onClick or other props. I think it is not overkill, actually, it should have a default behavior, but can be opened for overriding. Applications which currently used react-dropdown-select are able to control the stylesheet, and provide the suitable experiences to their users.

Thanks a lot.

@sanusart
Copy link
Owner

Hey @quockhanhle93
It sounds way more appropriate from your example. Yes. Definitely needed behaviour (especially that regular HTML select behaves like this with tab focus).

I'll look into how to make it happend, unfortunately did not took this kind of case into account with all possible triggers happening now, so it may take some time to re-factor.

Thanks for taking time to describe.

@quockhanhle93
Copy link
Author

quockhanhle93 commented Apr 23, 2020

Thanks @sanusart for understanding our situation. Thanks for spending your time on helping me.
I will become one of your project contributors soon. :)

@sanusart sanusart mentioned this issue Apr 23, 2020
@sanusart
Copy link
Owner

@quockhanhle93 Any chance you can test in your setup using the branch in PR?

codesandbox autogenerates a temp package for each PR:
https://ci.codesandbox.io/status/sanusart/react-dropdown-select/pr/90/builds/23291

sanusart added a commit that referenced this issue May 8, 2020
… closes issue #88 (#90)

* FIX (keyboard navigation): fix tab navigation from outside

* CHORE (examples): cleanup basic example

* v4.4.0
See changelog: https://github.com/sanusart/react-dropdown-select/blob/master/CHANGELOG.md
@sanusart sanusart closed this as completed May 8, 2020
@sanusart
Copy link
Owner

sanusart commented May 8, 2020

Should be available since v4.4.0

@quockhanhle93
Copy link
Author

Thanks a lot @sanusart It sounds a great help. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants