Skip to content

Commit 0f80347

Browse files
committed
Combobox: Only reset virtual focus on input blur if focus is moving to a button
1 parent b91ce57 commit 0f80347

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

.changeset/cold-ghosts-brake.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@navikt/ds-react": patch
3+
---
4+
5+
Combobox: Only reset virtual focus on input blur if focus is moving to a button

@navikt/core/react/src/form/combobox/Input/Input.tsx

+7-1
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,13 @@ const Input = forwardRef<HTMLInputElement, InputProps>(
253253
type="text"
254254
role="combobox"
255255
value={value}
256-
onBlur={composeEventHandlers(onBlur, virtualFocus.resetFocus)}
256+
onBlur={composeEventHandlers(onBlur, (event) => {
257+
if (isListOpen && event.relatedTarget?.tagName === "BUTTON") {
258+
// Remove virtual focus when focus is moved to a chip.
259+
// This prevents a value from being selected when pressing enter to remove a chip.
260+
virtualFocus.resetFocus();
261+
}
262+
})}
257263
onClick={() => {
258264
setHideCaret(!!maxSelected?.isLimitReached);
259265
value !== searchTerm && onChange(value);

0 commit comments

Comments
 (0)