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

AutoComplete: onSelect incorrectly called on mouse down, resulting in two selections with forceSelection #7412

Open
inad9300 opened this issue Nov 13, 2024 · 2 comments
Labels
Type: Bug Issue contains a defect related to a specific component.

Comments

@inad9300
Copy link
Contributor

inad9300 commented Nov 13, 2024

Reproducer

https://stackblitz.com/edit/drzc4t?file=src%2FApp.jsx

Steps to reproduce the behavior

  1. Open the console
  2. Write "tea" in the input box
  3. Click and hold "black tea"
  4. See how "tea" is reported as selected!
  5. Release the click
  6. "black tea" is now reported as selected, as expected – but it is too late, the onSelect callback has already run and done all the side effects it needed, only with the wrong item

To complicate matters further, if you are adding elements to a list above the autocomplete element on select, the autocomplete and its dropdown will be pushed down as you click down, such that the element that you were going to click is no longer under the cursor, and nothing else is selected when you release the click, so only the undesired item ends up selected.

@inad9300 inad9300 added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Nov 13, 2024
@inad9300
Copy link
Contributor Author

Any luck with this one?

@tnowad
Copy link
Contributor

tnowad commented Dec 22, 2024

I think this issue comes from the forceSelection prop you pass. When it's set, the forceItemSelection function runs during the blur event.

const onInputBlur = (event) => {
setFocusedState(false);
if (props.forceSelection) {
forceItemSelection(event);
}
props.onBlur && props.onBlur(event);
};

@melloware melloware added Type: Bug Issue contains a defect related to a specific component. and removed Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible labels Dec 23, 2024
@melloware melloware changed the title AutoComplete: onSelect incorrectly called on mouse down, resulting in two selections AutoComplete: onSelect incorrectly called on mouse down, resulting in two selections with forceSelection Dec 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Issue contains a defect related to a specific component.
Projects
None yet
Development

No branches or pull requests

3 participants