Loading
GlTokenSelector: Allow Escape key propagation when dropdown is closed
What does this MR do?
In GlTokenSelector, @keydown.stop="$emit('keydown', $event)" was previously attached directly to the text input element, stopping propagation for all keydown events.
When GlTokenSelector is placed inside a modal (such as GlModal), pressing Escape from the input never propagates to the modal container or document, preventing the modal from closing. This breaks WCAG 2.1.1 (Keyboard navigation) and violates expected modal dialog keyboard behavior.
This change:
- Replaces
@keydown.stopon the input with@keydown="handleKeydown"to control propagation programmatically. - In
handleEscape, stopsEscapepropagation (event?.stopPropagation?.()) only when the suggestions dropdown is open (dropdownIsOpen === true), so that the firstEscapecloses the suggestions dropdown. - Allows
Escapeto propagate to parent DOM containers (includingGlModal) when the suggestions dropdown is closed (dropdownIsOpen === false), enabling the modal to close onEscape. - Keeps
event.stopPropagation()for all non-Escape keys inhandleKeydown, preserving existing behavior. - Adds unit tests in
token_selector.spec.jsasserting thatstopPropagation()is called when the dropdown is open, and not called when the dropdown is closed.
Closes #3762
Related to gitlab-org/gitlab!269355
Does this MR meet the acceptance criteria?
- Relevant labels applied
- Changeset added (
.changeset/token-selector-escape-propagation.md) - All unit tests passing (
token_selector.spec.js) - Meets WCAG 2.1.1 keyboard navigation criteria