Skip to content

Commit a28dadb

Browse files
committed
Allow spaces while typing in combobox
1 parent 301f656 commit a28dadb

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

src/v2/components/forms/combobox/Combobox.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,31 @@ describe('SolidUICombobox', () => {
175175
})
176176
})
177177

178+
it('does not treat space as a selection while typing', async () => {
179+
const combobox = new Combobox()
180+
181+
combobox.options = [
182+
{ label: 'Self Employed', value: 'self-employed' },
183+
{ label: 'Microsoft', value: 'microsoft' }
184+
]
185+
186+
document.body.appendChild(combobox)
187+
await combobox.updateComplete
188+
189+
const input = combobox.shadowRoot?.querySelector('input.text-input') as HTMLInputElement
190+
191+
input.dispatchEvent(new KeyboardEvent('keydown', { key: 'ArrowDown', bubbles: true }))
192+
await combobox.updateComplete
193+
194+
const event = new KeyboardEvent('keydown', { key: ' ', bubbles: true, cancelable: true })
195+
input.dispatchEvent(event)
196+
await combobox.updateComplete
197+
198+
expect(event.defaultPrevented).toBe(false)
199+
expect(combobox.value).toBe('')
200+
expect(input.getAttribute('aria-expanded')).toBe('true')
201+
})
202+
178203
it('closes the popup when clicking outside the component', async () => {
179204
const combobox = new Combobox()
180205
combobox.options = [

src/v2/components/forms/combobox/Combobox.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,10 @@ export class Combobox extends LitElement {
431431
}
432432

433433
private _handleInputKeydown (e: KeyboardEvent) {
434+
if (e.key === ' ' || e.key === 'Spacebar') {
435+
return
436+
}
437+
434438
const popupOptions = this._getDisplayedOptions()
435439
const action = getListboxActionFromKey(e.key)
436440

0 commit comments

Comments
 (0)