Skip to content

Prevent Listbox selection while disabled - #3912

Open
Xapollon430 wants to merge 2 commits into
tailwindlabs:mainfrom
Xapollon430:codex/listbox-prevent-selection-when-disabled
Open

Xapollon430 wants to merge 2 commits into
tailwindlabs:mainfrom
Xapollon430:codex/listbox-prevent-selection-when-disabled

Conversation

@Xapollon430

@Xapollon430 Xapollon430 commented Nov 1, 2026 •

Copy link
Copy Markdown

Problem

I was playing around with the Listbox component and noticed a bug where:

  1. Open an enabled Listbox.
  2. Set disabled to true while the menu is open.
  3. Click an option. The selection changes and onChange still fires.

Here is a reproduction video of the issue:

Recorded against published @headlessui/react 2.2.10 before the fix. The disabled-state readout stays visible, and selection uses a normal pointer click.

headless-audited-repro.mp4

A prop update can send disabled=true after the menu is already open. In an application, that could happen when an asynchronous request completes or a timer fires while someone is choosing an option. The case here is the parent control becoming disabled; the options haven't been individually marked disabled.

My first thought was to close the popup, since that is what I observed with a native HTML select in Chromium. The HTML option-picking algorithm also stops without selecting an option when its select is disabled.

Closing on disable is a reasonable choice too. I'm happy to adjust the PR to follow the library's preferred behavior. The behavior I'm trying to guarantee is simply that a control stops accepting user selections once it becomes disabled.

The options inherit the parent Listbox's disabled state, so pointer and keyboard selection stop while disabled. The PR applies the same behavior to the React and Vue implementations and leaves the current menu state alone.

I started investigating this interaction while using Hegel to vary component props and Bombadil to exercise UI actions in Anta. I then reproduced this library's behavior separately; the video above is from that reproduction.

Validation

  • npx jest --runInBand --selectProjects React --runTestsByPath packages/@headlessui-react/src/components/listbox/listbox.test.tsx
  • Vue Listbox suite: 136 tests passed, including a regression that fails without the Vue change.
  • Browser checks against the updated React and Vue source in Chromium: selection stays unchanged while disabled and works after re-enabling.
  • Prettier check on changed files.

@Xapollon430
Xapollon430 marked this pull request as ready for review November 1, 2026 23:00
@vercel

vercel Bot commented Nov 1, 2026

Copy link
Copy Markdown

@Xapollon430 is attempting to deploy a commit to the Tailwind Labs Team on Vercel.

A member of the Team first needs to authorize it.

@Xapollon430
Xapollon430 marked this pull request as draft November 1, 2026 23:19
@Xapollon430
Xapollon430 marked this pull request as ready for review November 2, 2026 01:30

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.

1 participant