fix: Solves component paginatedMultiSelectFiltered dropdown close issue #1262
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Proposed changes (including videos or screenshots)
I've implemented an handleOnMouseDown function to manage the visibility of the dropdown menu. This handler also ensures that the dropdown remains unaffected when removing chip items by checking whether the mouseDown event occurred on the Chip component.
For the Anchor component, the onClick prop has been removed, and a custom function, handleBlur, is now assigned to onBlur prop. This function is responsible for hiding the dropdown only when necessary.
To maintain a proper sequence of actions, focusing on the box/anchor is handled separately by the handleClick function assigned as onClick prop
The order of actions is as follows: onMouseDown first, followed by onBlur, and finally onClick.
2024-01-11.13-07-28.mp4
Issue(s)
Closes #1261
Further comments
The problem happened because the onBlur event, which hides the dropdown when you click outside, runs before the onClick event. So, if you click inside the box, like on the arrow icon, the onBlur event hides the dropdown, and then the onClick event thinks it's hidden and shows it again.
To fix this, I used the onMouseDown event to handle these situations better. Another way is to delay the onBlur function using setTimeout by 100-200ms. This makes sure onBlur only happens after the click is done. I felt the first solution was better, but here's the setTimeout code in case you want to consider it.