Skip to content

Commit

Permalink
Merge 4f12618 into 608e1f3
Browse files Browse the repository at this point in the history
  • Loading branch information
it-vegard authored Aug 17, 2023
2 parents 608e1f3 + 4f12618 commit d16fb26
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/heavy-cats-jog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@navikt/ds-react": patch
---

Trigger Combobox.onChange callback in addition to onClear when clearing the value programmatically
3 changes: 2 additions & 1 deletion @navikt/core/react/src/form/combobox/Input/inputContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,11 @@ export const InputContextProvider = ({ children, value: props }) => {
const clearInput = useCallback(
(event: React.PointerEvent | React.KeyboardEvent) => {
onClear?.(event);
externalOnChange?.(null, "");
setValue("");
setSearchTerm("");
},
[onClear, setSearchTerm, setValue]
[externalOnChange, onClear, setValue]
);

const focusInput = useCallback(() => {
Expand Down
2 changes: 1 addition & 1 deletion @navikt/core/react/src/form/combobox/combobox.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,6 @@ export const TestThatCallbacksOnlyFireWhenExpected = {
await sleep(250);
expect(args.onClear.mock.calls).toHaveLength(1);
expect(args.onToggleSelected.mock.calls).toHaveLength(1);
expect(args.onChange.mock.calls).toHaveLength(searchWord.length);
expect(args.onChange.mock.calls).toHaveLength(searchWord.length + 1);
},
};
5 changes: 4 additions & 1 deletion @navikt/core/react/src/form/combobox/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ export interface ComboboxProps
* @param event
* @returns
*/
onChange?: (event: ChangeEvent<HTMLInputElement>) => void;
onChange?: (
event: ChangeEvent<HTMLInputElement> | null,
value?: string
) => void;
/**
* Callback function triggered whenever the input field is cleared
*
Expand Down

0 comments on commit d16fb26

Please sign in to comment.