Skip to content

fix: size the options list for a new option added in single select - #495

Merged
gnbm merged 4 commits into
masterfrom
fix/single-select-new-option-height
Nov 23, 2026
Merged

gnbm merged 4 commits into
masterfrom
fix/single-select-new-option-height

Conversation

@gnbm

@gnbm gnbm commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Issue number: resolves #496


What is the current behavior?

With allowNewOption: true and multiple: false, adding a new option leaves the options list one row short. On an empty list the list is 0px tall and has-no-options stays on, so the option just added is hidden. Each later addition stays one row behind. Multi select works because it never closes on select.

The cause is an ordering issue in selectOption():

  1. closeDropbox() runs first and clears the search. setVisibleOptionsCount() then drops the temporary isCurrentNew option and sizes .vscomp-options-list and has-no-options without it.
  2. beforeSelectNewValue() then takes the fallback branch added in feature(search): Include option descriptions in search when searchNormalize is true; fix add-new-option crash #464. It re-adds the option through setNewOption() → addOption(), which does not rerender.
  3. The deferred setSearchValue('') returns early because the search is already empty, so nothing recounts.

What is the new behavior?

  • The fallback branch in beforeSelectNewValue() calls setVisibleOptionsCount() after the option is persisted. The list height, the visible count and has-no-options now include the new option.
  • setVisibleOptionsCount() was chosen over forcing setSearchValue('', false, true) because it has no announce or focus side effects. addOption(data, true) was ruled out because afterSetOptions() without keepValue calls reset() and would clear the selected value.
  • New spec cypress/e2e/single-select-new-option-height.cy.ts adds two options to an empty single select and checks the list height after each one.

Does this introduce a breaking change?

  • Yes
  • No

Other information

Check Result
New spec on the v1.4.0 bundle, before the fix 2 failing (0px vs 40px, 40px vs 80px)
New spec after the fix 2 passing
Full Cypress suite after the fix 422 / 422 passing
lint:js and typecheck clean

Built dist/, docs/assets/ and dist-archive/ files are not part of this PR, matching earlier fix PRs.

With allowNewOption in single select, selectOption() closes the dropbox
before beforeSelectNewValue() persists the new option. The close clears
the search, and setVisibleOptionsCount() drops the temporary current-new
option and sizes the list without it. The fallback branch then re-adds
the option through addOption() with no rerender, and the deferred
setSearchValue('') is a no-op because the search is already empty.

The list therefore came back one row short: 0px on an empty list, with
has-no-options still applied. Recount once the option is persisted.

Multi select is unaffected because it never closes on select.
@gnbm gnbm added the bug Something isn't working label Nov 17, 2026
@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

PR Test Results — ✅ all checks passed

Check Result Time
Typecheck ✅ 2s
ESLint ✅ 1s
Stylelint ✅ 1s
CI Scripts ✅ 1s
Build ✅ 2s
a11y-aria-label.cy.ts ✅ 10/10 4s
a11y-close-clears-highlight.cy.ts ✅ 7/7 4s
a11y-escape-close.cy.ts ✅ 6/6 1s
a11y-listbox-multiselectable.cy.ts ✅ 3/3 1s
a11y-live-region.cy.ts ✅ 18/18 5s
a11y-reduced-motion.cy.ts ✅ 3/3 1s
a11y-required-error.cy.ts ✅ 20/20 3s
a11y-search-arrow-navigation.cy.ts ✅ 13/13 5s
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 1m13s
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: 015af36 · Run #41

"uses the singular form for a single match" typed "Option 3" key by key.
Only the full term narrows the list to one match, so it is the one search
case where a lost keystroke changes the result. In CI the search box ended
with "Opt" and the region correctly said "5 results available"; the rest of
the keys went elsewhere.

Wait until the component has focused the search input itself, then set the
term with a single input event and assert the input holds it before checking
the region. The announcement still goes through the real input handler and
its focus check, and a singular/plural regression still fails the test.
@gnbm
gnbm marked this pull request as ready for review November 17, 2026 11:28
@gnbm
gnbm merged commit 63be504 into master Nov 23, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Single select with allowNewOption: options list not resized for the option just added

2 participants