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

Setting a state in onChange resets focus on options to the first element #5959

Open
SetupCoding opened this issue Sep 17, 2024 · 0 comments
Open
Labels
issue/bug-unconfirmed Issues that describe a bug that hasn't been confirmed by a maintainer yet

Comments

@SetupCoding
Copy link

SetupCoding commented Sep 17, 2024

Reproduction Repository:

https://github.com/SetupCoding/react-select-test-vite

Steps to Reproduce:

  1. Clone the repository and run npm install.
  2. Start the development server using npm run dev.
  3. Navigate to localhost:5173.
  4. Interact with the react-select component using the keyboard:
    1. Press the arrow down key twice to highlight the second option (“Battery Powered Tools”).
    2. Press the space or enter key to select the second option.
  5. Observe that the focus moves back to the first element (“Top Picks”) again. This behavior repeats every time any other element is selected or deselected.

Video of Reproduction

Keyboard interaction:
https://github.com/user-attachments/assets/839b1b83-de61-4889-bbe0-53303d6cfcbb

Mouse interaction:
https://github.com/user-attachments/assets/9142d7ad-d4a6-4745-9f4d-844ef7f6cc56

Additional Observations:

  • When using the mouse to select an option other than the first (“Top Picks”), the first option “steals” the hover effect until the mouse is slightly moved to reset the hover effect to the correct element.
  • If you don’t set the state in the handleComboboxChange function, the focus remains on the selected element, and the arrow keys work as expected.

Note:

  • This issue does not occur when running the component in CodeSandbox, but it does occur in Create React App (CRA) and Vite (tested in two separate freshly initialized projects).

Many thanks in advance!

@SetupCoding SetupCoding added the issue/bug-unconfirmed Issues that describe a bug that hasn't been confirmed by a maintainer yet label Sep 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
issue/bug-unconfirmed Issues that describe a bug that hasn't been confirmed by a maintainer yet
Projects
None yet
Development

No branches or pull requests

1 participant