Skip to content

Commit

Permalink
Fix Combobox input mixing controlled and uncontrolled state (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
coopbri committed Jul 29, 2024
1 parent 00916b6 commit 60c6710
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/tame-pumas-buy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@omnidev/sigil": patch
---

Fix `Combobox` input mixing controlled and uncontrolled state
8 changes: 5 additions & 3 deletions src/components/core/Combobox/Combobox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,9 @@ const Combobox = ({
...rest
}: ComboboxProps) => {
const [filteredItems, setFilteredItems] = useState(items),
[inputValue, setInputValue] = useState(rest.defaultValue || "");
[defaultInputValue, setDefaultInputValue] = useState(
rest.defaultValue || "",
);

/**
* Handle input value change. Composes a custom `onInputValueChange` handler, if provided.
Expand All @@ -190,7 +192,7 @@ const Combobox = ({
evt: ComboboxValueChangeDetails,
onValueChange?: ComboboxProps["onValueChange"],
) => {
setInputValue(evt.items.map((item) => item.label).join(", "));
setDefaultInputValue(evt.items.map((item) => item.label).join(", "));

// execute custom `onValueChange` handler, if provided
onValueChange?.(evt);
Expand Down Expand Up @@ -218,7 +220,7 @@ const Combobox = ({
)}

<ComboboxControl {...controlProps}>
<ComboboxInput asChild value={inputValue} {...inputProps}>
<ComboboxInput asChild defaultValue={defaultInputValue} {...inputProps}>
<Input colorPalette={colorPalette} />
</ComboboxInput>

Expand Down

0 comments on commit 60c6710

Please sign in to comment.