From 17302a74035bd665fd86a4a1056890c0b7ec2b39 Mon Sep 17 00:00:00 2001 From: Nicholas Boll Date: Mon, 17 Jul 2023 15:44:00 -0600 Subject: [PATCH 1/2] fix(combobox): Do not clear the input when no item is selected Fixes: #2288 --- modules/react/combobox/lib/ComboboxInput.tsx | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/modules/react/combobox/lib/ComboboxInput.tsx b/modules/react/combobox/lib/ComboboxInput.tsx index e398282c9b..01df1c54c8 100644 --- a/modules/react/combobox/lib/ComboboxInput.tsx +++ b/modules/react/combobox/lib/ComboboxInput.tsx @@ -56,11 +56,8 @@ export const useComboboxInput = composeHooks( dispatchInputEvent(event.currentTarget as HTMLElement, ''); } if (event.key === 'Enter' && !event.metaKey && model.state.visibility === 'visible') { - if ( - document - .querySelector(`[data-id="${model.state.cursorId}"]`) - ?.getAttribute('aria-disabled') !== 'true' - ) { + const element = document.querySelector(`[data-id="${model.state.cursorId}"]`); + if (element && element?.getAttribute('aria-disabled') !== 'true') { model.events.select({id: model.state.cursorId}); if (model.state.mode === 'single') { model.events.hide(event); From 90854be9ecdc16605bd22263485a6c3798c54fd1 Mon Sep 17 00:00:00 2001 From: Nicholas Boll Date: Mon, 17 Jul 2023 15:46:35 -0600 Subject: [PATCH 2/2] Update Autocomplete.spec.ts --- cypress/integration/Autocomplete.spec.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/cypress/integration/Autocomplete.spec.ts b/cypress/integration/Autocomplete.spec.ts index 75f0990b05..155aa60f3a 100644 --- a/cypress/integration/Autocomplete.spec.ts +++ b/cypress/integration/Autocomplete.spec.ts @@ -332,6 +332,22 @@ describe('Autocomplete', () => { }); }); }); + + context('when the user types in a value not found', () => { + beforeEach(() => { + cy.findByRole('combobox').type('Peach'); + }); + + context('when the user hits the enter key', () => { + beforeEach(() => { + cy.findByRole('combobox').type('{enter}'); + }); + }); + + it('should not clear the input', () => { + cy.findByRole('combobox').should('have.value', 'Peach'); + }); + }); }); }); });