fix: Ignore IME composition enter in select and multiselect filtering#4676
Open
greymoth-jp wants to merge 1 commit into
Open
fix: Ignore IME composition enter in select and multiselect filtering#4676greymoth-jp wants to merge 1 commit into
greymoth-jp wants to merge 1 commit into
Conversation
When composing text with an IME and pressing Enter to confirm a candidate, the filter input of Select and Multiselect selected the highlighted option and closed the dropdown instead of committing the composed text. The sibling inputs already guard this: autosuggest-input uses useIMEComposition and prompt-input checks nativeEvent.isComposing. Apply the same guard to the shared useSelect filter handler so composition keystrokes, and the spurious Enter some browsers fire right after compositionend, are ignored.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4676 +/- ##
=======================================
Coverage 97.57% 97.57%
=======================================
Files 948 948
Lines 30489 30495 +6
Branches 11148 11150 +2
=======================================
+ Hits 29749 29755 +6
+ Misses 733 693 -40
- Partials 7 47 +40 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
The filtering input of
SelectandMultiselectselects the highlighted option when Enter is pressed, but it does not account for IME composition. When a user composes text with an IME (for example Japanese, Chinese or Korean) and presses Enter to confirm a candidate, that Enter is also treated as an option selection: the highlighted option is selected and the dropdown closes, instead of the keypress just committing the composed text into the filter.The other text inputs in this repository already guard against this.
autosuggest-inputreadsuseIMECompositionand ignores Enter whileisComposing()is true, andprompt-inputchecksevent.nativeEvent.isComposing || props.isComposing?.(). The select filter input was passing its keydown straight touseMenuKeyboardwithout any such guard.This applies the same guard to the filter handler in
useSelect(shared bySelectandMultiselect).event.detail.isComposingcovers the keydown fired during composition, anduseIMEComposition(filterRef)covers the brief window aftercompositionendwhere some browsers fire a spurious Enter, matchingautosuggest-inputandprompt-input. Other key handling is unchanged.Related links, issue #, if available: n/a
How has this been tested?
Added a unit test in
src/select/__tests__/use-select.test.ts: with an option highlighted, an Enter whoseisComposingdetail istrueno longer callsupdateSelectedOptionand keeps the dropdown open, while a regular Enter still selects the option. The existinguse-selectunit tests continue to pass.