Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Combobox] Only open dropdown onClick, not onFocus. #3440

Merged
merged 3 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/forty-rules-ring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@navikt/ds-react": patch
---

Combobox: Only open dropdown-list onClick, not onFocus.
1 change: 0 additions & 1 deletion @navikt/core/react/src/form/combobox/ComboboxWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ const ComboboxWrapper = ({
!wrapperRef.current?.contains(event.relatedTarget) &&
toggleOpenButtonRef?.current !== event.target
) {
toggleIsListOpen(true);
setHasFocusWithin(true);
}
}
Expand Down
12 changes: 10 additions & 2 deletions @navikt/core/react/src/form/combobox/Input/InputController.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const InputController = forwardRef<
toggleListButton = true,
inputClassName,
shouldShowSelectedOptions = true,

...rest
} = props;

Expand All @@ -45,7 +46,7 @@ export const InputController = forwardRef<
readOnly,
} = useInputContext();

const { activeDecendantId } = useFilteredOptionsContext();
const { activeDecendantId, toggleIsListOpen } = useFilteredOptionsContext();
const { selectedOptions } = useSelectedOptionsContext();

const mergedInputRef = useMergeRefs(inputRef, ref);
Expand All @@ -57,7 +58,14 @@ export const InputController = forwardRef<
"navds-combobox__wrapper-inner--virtually-unfocused":
activeDecendantId !== undefined,
})}
onClick={focusInput}
onClick={() => {
if (inputProps.disabled || readOnly) {
return;
}
Comment on lines +62 to +64
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we technically need to check this, but it doesn't hurt either.


toggleIsListOpen(true);
focusInput();
}}
>
{!shouldShowSelectedOptions ? (
<Input
Expand Down
Loading