From 6deb2a67cea968f33bc81eca080785ea30dacab0 Mon Sep 17 00:00:00 2001 From: gnbm Date: Tue, 17 Nov 2026 01:34:55 +0000 Subject: [PATCH 1/3] fix: size the options list for a new option added in single select 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. --- .../e2e/single-select-new-option-height.cy.ts | 73 +++++++++++++++++++ src/virtual-select.js | 11 +++ 2 files changed, 84 insertions(+) create mode 100644 cypress/e2e/single-select-new-option-height.cy.ts diff --git a/cypress/e2e/single-select-new-option-height.cy.ts b/cypress/e2e/single-select-new-option-height.cy.ts new file mode 100644 index 0000000..05bb6a5 --- /dev/null +++ b/cypress/e2e/single-select-new-option-height.cy.ts @@ -0,0 +1,73 @@ +/** + * Single select + allowNewOption: the options list must be sized for the option the user just + * added. selectOption() closes the dropbox before it persists the new option, and the close + * recomputes the list height without it - so the list came back one row short (0px on an + * empty list) and `has-no-options` stayed on until something else happened to recompute. + */ +describe('Single select: adding a new option keeps the options list sized', () => { + const id = 'vs-single-new-option-height'; + const optionHeight = 40; + + const addNewOption = (value: string) => { + cy.getVs(id).click(); + cy.getVs(id).find('.vscomp-wrapper').should('not.have.class', 'closed'); + cy.getVs(id).typeValue(value); + cy.getDropbox(null, id).find('.vscomp-option.current-new.focused').should('contain.text', value); + /** + * Enter rather than click: each keystroke re-renders the option rows, so a click can lose + * its target between query and action. Enter selects the focused row through the same + * selectOption() path a click takes. + */ + cy.getVs(id).pressKeys('Enter'); + /** single select closes on select; wait for the close to land before reopening */ + cy.getVs(id).find('.vscomp-wrapper').should('have.class', 'closed'); + }; + + const reopen = () => { + cy.getVs(id).click(); + cy.getVs(id).find('.vscomp-wrapper').should('not.have.class', 'closed'); + }; + + before(() => { + cy.visit('get-started'); + + cy.window().then((win) => { + const $ele = win.document.createElement('div'); + $ele.id = id; + win.document.body.appendChild($ele); + + // @ts-expect-error - VirtualSelect is attached to window by the bundle + win.VirtualSelect.init({ + ele: $ele, + allowNewOption: true, + multiple: false, + options: [], + }); + }); + }); + + it('sizes the list for the option added to an empty list', () => { + addNewOption('Alpha'); + cy.getVs(id).hasValueText('Alpha'); + + reopen(); + + cy.getVs(id).find('.vscomp-wrapper').should('not.have.class', 'has-no-options'); + cy.getDropbox(null, id).find('.vscomp-options-list').should('have.css', 'height', `${optionHeight}px`); + cy.getDropbox(null, id).find('.vscomp-option[data-value="Alpha"]').should('be.visible'); + }); + + it('grows the list by one row for the next option added', () => { + cy.getVs(id).click(); + cy.getVs(id).find('.vscomp-wrapper').should('have.class', 'closed'); + + addNewOption('Beta'); + cy.getVs(id).hasValueText('Beta'); + + reopen(); + + cy.getDropbox(null, id).find('.vscomp-options-list').should('have.css', 'height', `${optionHeight * 2}px`); + cy.getDropbox(null, id).find('.vscomp-option[data-value="Alpha"]').should('be.visible'); + cy.getDropbox(null, id).find('.vscomp-option[data-value="Beta"]').should('be.visible'); + }); +}); diff --git a/src/virtual-select.js b/src/virtual-select.js index 2b6a02c..91f3e55 100644 --- a/src/virtual-select.js +++ b/src/virtual-select.js @@ -1058,6 +1058,17 @@ export class VirtualSelect { // when dropdown close resets search, so re-add as a persisted new option. this.setNewOption(selectedValue); this.toggleSelectedProp(this.lastOptionIndex, true); + + /** + * The close that removed the temporary option also recomputed the visible count, the + * list height and `has-no-options` without it, and nothing after this point recomputes + * them: setNewOption() re-adds through addOption() with no rerender, and the deferred + * setSearchValue('') below is a no-op because the close already emptied the search. + * So the list came back one row short - 0px on an empty list, with the "no options" + * message still showing - until some later filter change happened to recount. + * Recount now that the option is a regular one; the count includes it from here on. + */ + this.setVisibleOptionsCount(); } /** using setTimeout to fix the issue of dropbox getting closed on select */ From b3bdbcf689e660cf67f7c0381302dab80406e703 Mon Sep 17 00:00:00 2001 From: gnbm Date: Tue, 17 Nov 2026 07:26:59 +0000 Subject: [PATCH 2/3] test(a11y): enter the single-match search term in one input event "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. --- cypress/e2e/a11y-live-region.cy.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/cypress/e2e/a11y-live-region.cy.ts b/cypress/e2e/a11y-live-region.cy.ts index d66240c..d77db65 100644 --- a/cypress/e2e/a11y-live-region.cy.ts +++ b/cypress/e2e/a11y-live-region.cy.ts @@ -68,9 +68,21 @@ describe('A11y: status announcements via a live region', () => { liveRegion().should('have.text', '5 results available'); }); + /** + * The term is entered in one input event rather than typed key by key. Only the full term + * "Option 3" narrows the list to one match - "Opt", "Option" and "Option " all match five - + * so this is the one search case where a lost keystroke changes the outcome. In CI the run + * ended with "Opt" in the box and "5 results available" in the region: the component + * announced correctly for what it received, the rest of the keys went elsewhere. Waiting for + * the component to move focus into the input itself (the last step of opening) and then + * setting the value in one step leaves nothing to lose, and still goes through the real + * input handler and its focus check. + */ it('uses the singular form for a single match', () => { cy.get(`#${mountId}`).find('.vscomp-toggle-button').click(); - cy.get(`#${mountId}`).find('.vscomp-search-input').focus().type('Option 3'); + cy.get(`#${mountId}`).find('.vscomp-search-input').should('have.focus'); + cy.get(`#${mountId}`).find('.vscomp-search-input').invoke('val', 'Option 3').trigger('input'); + cy.get(`#${mountId}`).find('.vscomp-search-input').should('have.value', 'Option 3').and('have.focus'); liveRegion().should('have.text', '1 result available'); }); From 015af36aafbb919ac07fa1dba415093e9783a78c Mon Sep 17 00:00:00 2001 From: gnbm Date: Sat, 21 Nov 2026 18:50:35 +0000 Subject: [PATCH 3/3] Update eslint.config.mjs --- eslint.config.mjs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index dbe546b..99b000f 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -74,7 +74,22 @@ export default [ '@stylistic/linebreak-style': ['error', 'unix'], '@stylistic/max-len': ['error', { code: 120 }], '@stylistic/no-trailing-spaces': 'error', - '@stylistic/object-curly-newline': ['error', { ObjectPattern: { multiline: true } }], + // Successor of the deprecated object-curly-newline. list-style covers every bracketed list by default, + // which would fight Prettier (e.g. argument hugging), so it is scoped to destructuring patterns only: + // a pattern is either fully on one line or has every property on its own line. + '@stylistic/list-style': [ + 'error', + { + overrides: { + '()': 'off', + '[]': 'off', + '{}': 'off', + '<>': 'off', + // Must restate the spacing: the plugin's '{}' default (spacing: always) is dropped once '{}' is off. + ObjectPattern: { singleLine: { spacing: 'always' } }, + }, + }, + ], '@stylistic/operator-linebreak': ['error', 'after', { overrides: { '?': 'before', ':': 'before' } }], '@stylistic/quote-props': ['error', 'consistent'], },