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

fix: In autocomplete dropdown, the item’s event has been changed from click to mousedown #16649

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

P5175
Copy link

@P5175 P5175 commented Oct 27, 2024

#16625
In an autocomplete input component, events can often lead to unintended order of execution, particularly when handling change and click events. When a user types in the input and then selects an item from the dropdown list, the change event fires first because it’s triggered as soon as the input field loses focus or updates its content. Then, the click event on the dropdown item is executed.

Problem:
change Event: This triggers first when the input value changes, such as when the user clicks outside the input or the dropdown, updating the internal value.
click Event on Dropdown Item: This triggers after the change event, potentially overriding or undoing the intended selection behavior.
Solution with mousedown Event:
To change the order and have the dropdown selection (click) execute before the change event, you can replace click with the mousedown event on the dropdown items. This way:

mousedown Event on Dropdown Item: Fires when the user presses the mouse button down on the dropdown item, executing before the input loses focus.
change Event: Now, the change event fires after mousedown, updating the input field only after the item is selected.

Copy link

vercel bot commented Oct 27, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

2 Skipped Deployments
Name Status Preview Updated (UTC)
primeng ⬜️ Ignored (Inspect) Visit Preview Oct 27, 2024 3:47pm
primeng-v18 ⬜️ Ignored (Inspect) Visit Preview Oct 27, 2024 3:47pm

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

Successfully merging this pull request may close these issues.

1 participant