Skip to content

Prevent Enter from selecting after Virtual Select is disabled - #494

Open
Xapollon430 wants to merge 3 commits into
sa-si-dev:masterfrom
Xapollon430:codex/prevent-disabled-keyboard-selection
Open

Xapollon430 wants to merge 3 commits into
sa-si-dev:masterfrom
Xapollon430:codex/prevent-disabled-keyboard-selection

Conversation

@Xapollon430

@Xapollon430 Xapollon430 commented Nov 9, 2026 •

Copy link
Copy Markdown

Problem

  1. Open an enabled searchable Select with Apple selected.
  2. Call disable() while its search field has focus and the dropdown is open.
  3. Press ArrowDown twice, then Enter. Orange becomes selected and change fires.

Watch the Chromium reproduction. The recording uses ordinary keyboard input and the library’s stylesheet against current master at 129b893. Pointer selection is already blocked in this layout; the focused search input can still commit the highlighted option.

Check the root disabled state before Enter can either open the dropdown or select the focused option. The popup’s existing visibility behavior is unchanged.

I investigated this transition in Anta with Hegel and Bombadil, then reproduced it independently here.

Validation

  • The new Cypress regression fails on the original source because the selected value changes to the next option.
  • All 14 tests across the new regression and existing search keyboard suite pass with the fix.
  • The real Chromium sequence still selects Orange when enabled. After disabling, Apple stays selected and no additional change event fires.
  • Build, TypeScript, and JavaScript lint pass.

AI-assisted implementation and testing.

Reviewer follow-up: added a standalone reproduction at docs/examples/disabled-keyboard.html. Run npm ci, npm run build, and npx docsify serve docs -p 3001, then open http://localhost:3001/examples/disabled-keyboard.html and follow the instructions.

The reported CI failure was caused by shared page state in the live-region suite. Enabling page isolation for that suite fixes it. All 421 browser tests pass in Chrome, including the disabled-keyboard regression. Build, source lint, and type check pass.

@github-actions

github-actions Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

PR Test Results — ✅ all checks passed

Check Result Time
Typecheck ✅ 3s
ESLint ✅ 2s
Stylelint ✅ 1s
CI Scripts ✅ 1s
Build ✅ 3s
a11y-aria-label.cy.ts ✅ 10/10 5s
a11y-close-clears-highlight.cy.ts ✅ 7/7 5s
a11y-disable-while-open.cy.ts ✅ 1/1 1s
a11y-escape-close.cy.ts ✅ 6/6 2s
a11y-listbox-multiselectable.cy.ts ✅ 3/3 1s
a11y-live-region.cy.ts ✅ 18/18 9s
a11y-reduced-motion.cy.ts ✅ 3/3 1s
a11y-required-error.cy.ts ✅ 20/20 4s
a11y-search-arrow-navigation.cy.ts ✅ 13/13 6s
a11y-select-all.cy.ts ✅ 7/7 3s
a11y-server-search-announcements.cy.ts ✅ 6/6 4s
a11y-target-size.cy.ts ✅ 5/5 2s
build-stylesheet-integrity.cy.ts ✅ 4/4 1s
examples.cy.ts ✅ 219/219 1m20s
observer-listener-lifecycle.cy.ts ✅ 7/7 1s
perf-resize-throttle.cy.ts ✅ 3/3 1s
perf-scroll-aria.cy.ts ✅ 6/6 3s
secure-option-values.cy.ts ✅ 2/2 1s
secure-text-warning.cy.ts ✅ 4/4 1s
security-ampersand-storage.cy.ts ✅ 16/16 3s
security-chrome-label-props.cy.ts ✅ 10/10 1s
security-classnames-xss.cy.ts ✅ 2/2 1s
security-customdata-xss.cy.ts ✅ 2/2 1s
security-global-defaults.cy.ts ✅ 11/11 1s
security-hidden-input-name.cy.ts ✅ 7/7 1s
security-proto-value.cy.ts ✅ 9/9 1s
security-quote-escaping.cy.ts ✅ 12/12 2s
single-select-new-option-height.cy.ts ✅ 2/2 2s
tag-tooltip-overflow.cy.ts ✅ 6/6 11s
timer-cleanup.cy.ts ✅ 2/2 1s

Tested commit: fe0ae7a · Run #43

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues remain for the change preventing Enter actions while Virtual Select is disabled.

No open issues 🎉

What changed in this PR

Prevents Enter from opening the dropdown or committing a focused option after Virtual Select is disabled, while preserving existing popup visibility behavior.

Changes:

  • Checks the root disabled state before handling either Enter action.
  • Adds a Cypress regression confirming that disabling an open, focused Select prevents keyboard selection and emits no change event.
File Description
src/​virtual-select.js Returns early from the Enter handler when the Select is disabled.
cypress/​e2e/​a11y-disable-while-open.cy.ts Tests keyboard navigation and Enter after disabling an open searchable Select.

Review effort: Balanced

@gnbm

gnbm commented Nov 21, 2026

Copy link
Copy Markdown
Collaborator

@Xapollon430 can you please share a reproduction sample we can validate?
Also, check the PR checks (including a test that started to fail)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues were identified in the change to block Enter handling when Virtual Select is disabled.

No open issues 🎉

Review effort: Balanced

@gnbm gnbm left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix! Two small notes on the test and the manual repro page below.

<div id="fruit"></div>
<p id="status" role="status">Enabled</p>
<p>Change count <output id="changes">0</output></p>
<script src="../assets/virtual-select.js"></script>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This page loads ../assets/virtual-select.js, but the committed bundle in docs/assets still has the old onEnterPress (else if (this.$ele.disabled === false)), since the PR only changes src/. Following the steps on the page as committed (open, ArrowDown to Orange, wait for "Disabled", Enter) still selects Orange and bumps the change count to 1.

Could you rebuild docs/assets in this PR, or add a note on the page that it needs a fresh build?

Comment on lines +31 to +33
keydown('ArrowDown', 40);
keydown('ArrowDown', 40);
cy.get(`#${mountId} .vscomp-option.focused`).should('not.have.attr', 'data-value', 'o1');

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assertion requires ArrowDown to keep moving the highlight after disable(), which locks in behaviour we probably don't want. A more complete fix (closing the dropbox on disable, or ignoring arrow keys while disabled) would make this line fail.

Suggestion: move the ArrowDown presses and highlight check before host.disable(), then after disabling assert that Enter (and ideally ArrowDown) are ignored.

This branch has not been deployed

No deployments
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.

3 participants