fix(suggestion): narrow the trigger keyboard guard to the keys BaseSelect breaks - #183
Merged
Merged
Conversation
…lect breaks The content wrapper stopped every keydown except Enter while the popup was open, so nothing typed in the trigger reached the app around it. Modal and Drawer never saw Escape — the portal esc stack listens on window — and application shortcuts died while the trigger had focus. Stop only what BaseSelect's non-editable keyboard model actually breaks: Space, Backspace while the popup is open, and an Enter the popup cannot use. Everything else keeps bubbling. Enter now reaches Cascader only when the popup owns it, meaning a plain Enter (no modifier, no IME composition) with a leaf item highlighted. Enter on a parent item expands it like ArrowRight instead of doing nothing, and an Enter with nothing to select falls back to the trigger so Sender can submit or insert a newline again. Escape stops at the popup it closes, so a Modal behind it survives the first press. Also remember the info of the last trigger. A function `items` is usually an inline arrow with a new identity on every parent render, and re-evaluating it without that info rebuilt the list as if nothing had triggered it.
3 tasks
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.
中文版模板 / Chinese template
🤔 This is a ...
🔗 Related Issues
close: Suggestion 快捷指令导致 Sender 无法输入空格、换行 #171 is already closed.)💡 Background and Solution
#177 fixed #171 by stopping every keydown on the
-contentwrapper except Enter while the popup is open. That does keep Space and Enter away fromBaseSelect, but it is wider than the problem and leaves four holes. Each one below was reproduced with a realmountbefore writing the fix.1. The trigger became a keyboard black hole
stopPropagation()sits below every ancestor listener, so nothing typed in the trigger reaches the host app. Measured: with a listener onwindow, anEscapeand aCmd+Ktyped in the trigger produced 0 calls.That breaks, among others, Modal/Drawer Esc —
@v-c/portal's esc stack listens in the bubble phase onwindow:A
Senderinside aModalis a common layout in chat UIs, and Esc stopped closing it.2. Enter was a dead key whenever the popup could not use it
useActivereturnsfalsefor Enter as long as the popup is open, which makesSenderskip submitting, and the wrapper then forwarded the event toBaseSelect, whichpreventDefault()s Enter unconditionally. When the option list has nothing to select, the key does nothing at all — no selection, no newline, no submit. Two reachable cases:children(thebasicdemo's Explore a topic) — measureddefaultPrevented: true,selectnever fired;itemsfiltered down to[]while the popup is still open.3. Enter from an IME composition, or with a modifier, selected a suggestion
Measured with the popup open: an Enter carrying
isComposing: truewas forwarded,preventDefault()ed, and emittedselect("report")— so confirming a Chinese candidate picks a suggestion instead.Shift+Enterbehaved the same way, which also means asubmitType="shiftEnter"user cannot send at all while the popup is open (submits: [],selected: ["report"]).Senderalready guards onisComposingand on modifiers inTextArea.tsx;Suggestiondid not.4. Unrelated: a function
itemslost its trigger infoitemsis usually an inline arrow (see thetriggerdemo), so it gets a new identity on every parent render, the watcher re-evaluates it with no argument and the list is rebuilt as if nothing had triggered it —Trigger by 'undefined'. SinceSenderre-renders the parent on every keystroke, this fires constantly in real usage.Solution
Stop only what BaseSelect's non-editable keyboard model actually breaks, and let everything else bubble:
Space and Backspace keep #177's behaviour (
onInternalKeyDownalwayspreventDefault()s Space; the option list turns Backspace intoprevColumn()/ close, which is wrong inside a textarea). Escape, arrows and application shortcuts now reach the app again.Who owns an Enter is decided in one place, in
useActive, and reused by the wrapper:useActive's own Enter branch follows the same rule: a modifier or IME Enter is left to the trigger, an Enter with nothing to select falls through (soSendersubmits or inserts a newline), and an Enter on a parent item expands it like ArrowRight instead of doing nothing. Escape additionally callsstopPropagation()— consistent with the arrow branches — so the popup absorbs the first Esc and the Modal behind it survives.Finally,
Suggestionremembers the lastonTriggerinfo and passes it back when a functionitemsis re-evaluated.Tests
15 → 22 cases. New: keys still bubble to
window(with Esc layering), Enter expands a parent item, Enter falls back to the trigger on an empty list, IME and modifier Enter are not hijacked, Backspace does not close the popup, a functionitemskeeps its trigger info, plus oneSuggestion+ realSenderintegration case walking the original #171 flow — space types while the popup is open, Enter selects instead of sending, Enter sends again once it is closed.Full suite: 472 passed (46 files).
vp checkandtype-checkboth pass.📝 Change Log
Suggestionswallowing keyboard events that belong to the app around it, such as Esc closing a Modal, and fix Enter doing nothing when the highlighted item has children or the list is empty. Enter from an IME composition or with a modifier now stays with the trigger, and a functionitemsno longer loses its trigger info.Suggestion吞掉宿主应用按键的问题(如 Esc 无法关闭外层 Modal),以及高亮项含子项或列表为空时回车无响应的问题。输入法组合中或带修饰键的回车不再被建议列表接管,函数式items也不会再丢失触发信息。