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

Select onFocus called way too many times #44505

Open
shoxter opened this issue Nov 21, 2024 · 2 comments
Open

Select onFocus called way too many times #44505

shoxter opened this issue Nov 21, 2024 · 2 comments
Labels
component: select This is the name of the generic UI component, not the React module! enhancement This is not a bug, nor a new feature performance

Comments

@shoxter
Copy link

shoxter commented Nov 21, 2024

Steps to reproduce

Steps:

  1. Open this link to live example: https://codesandbox.io/p/sandbox/q649qz
  2. Open console to see logs
  3. Click into the select box
  4. Click off the select box
  5. Click off the select box again

Current behavior

On the initial focus, onFocus is called 4 times. On initial blur, onFocus is called 2 more times and onBlur is not called. On second blur, onBlur is called.

Expected behavior

On initial focus, onFocus should be called once and not again until component is blurred and refocused. onBlur should be called when input is initially blurred.

Context

I have a code associated to with onFocus event that is being called 4 times when I expect it to be called once.

Your environment

npx @mui/envinfo
  Don't forget to mention which browser you used.
  Output from `npx @mui/envinfo` goes here.

Search keywords: mui select onfocus multiple times

@shoxter shoxter added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Nov 21, 2024
@siriwatknp siriwatknp added enhancement This is not a bug, nor a new feature performance component: select This is the name of the generic UI component, not the React module! and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Nov 25, 2024
@siriwatknp
Copy link
Member

In the future, we will rely on Base UI Select. I don't think we want to change the behavior now.

Also, do you experience the bottleneck with it? or just an observation.

@shoxter
Copy link
Author

shoxter commented Nov 25, 2024

I was experiencing a bottleneck but I manually implemented the expected behavior by adding a ref that gets set when onFocus is called and unset when onBlur is called. Then I check this refs value to be sure what I want to do in onFocus is only called once per onBlur.

Thank you!

@DiegoAndai DiegoAndai added this to the Material UI with Base UI milestone Nov 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: select This is the name of the generic UI component, not the React module! enhancement This is not a bug, nor a new feature performance
Projects
None yet
Development

No branches or pull requests

3 participants