diff --git a/.changeset/cold-ghosts-brake.md b/.changeset/cold-ghosts-brake.md new file mode 100644 index 0000000000..f2b34a0b22 --- /dev/null +++ b/.changeset/cold-ghosts-brake.md @@ -0,0 +1,5 @@ +--- +"@navikt/ds-react": patch +--- + +Combobox: Only reset virtual focus on input blur if focus is moving to a button diff --git a/@navikt/core/react/src/form/combobox/Input/Input.tsx b/@navikt/core/react/src/form/combobox/Input/Input.tsx index aab4f4fe9c..6469adc7c3 100644 --- a/@navikt/core/react/src/form/combobox/Input/Input.tsx +++ b/@navikt/core/react/src/form/combobox/Input/Input.tsx @@ -253,7 +253,13 @@ const Input = forwardRef( type="text" role="combobox" value={value} - onBlur={composeEventHandlers(onBlur, virtualFocus.resetFocus)} + onBlur={composeEventHandlers(onBlur, (event) => { + if (isListOpen && event.relatedTarget?.tagName === "BUTTON") { + // Remove virtual focus when focus is moved to a chip. + // This prevents a value from being selected when pressing enter to remove a chip. + virtualFocus.resetFocus(); + } + })} onClick={() => { setHideCaret(!!maxSelected?.isLimitReached); value !== searchTerm && onChange(value);