Skip to content

Commit

Permalink
Fix initial loading of the item
Browse files Browse the repository at this point in the history
  • Loading branch information
vineethasok committed Sep 16, 2023
1 parent cc6131f commit f8a798d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/components/MultiSelect/MultiSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
MouseEvent,
ReactNode,
forwardRef,
useEffect,
useId,
useRef,
useState,
Expand Down Expand Up @@ -157,6 +158,7 @@ const Trigger = forwardRef<HTMLButtonElement, TriggerProps>(
},
ref
) => {
const [, forceUpate] = useState(0);
const {
disabled,
id,
Expand All @@ -175,6 +177,10 @@ const Trigger = forwardRef<HTMLButtonElement, TriggerProps>(
updateSearch("");
};

useEffect(() => {
forceUpate(n => n + 1);
}, []);

return (
<ComboboxTrigger
ref={ref}
Expand Down
6 changes: 6 additions & 0 deletions src/components/Select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
MouseEvent,
ReactNode,
forwardRef,
useEffect,
useId,
useRef,
useState,
Expand Down Expand Up @@ -172,6 +173,7 @@ interface TriggerProps extends Omit<HTMLAttributes<HTMLButtonElement>, "id"> {

const Trigger = forwardRef<HTMLButtonElement, TriggerProps>(
({ placeholder = "Select an option", onClick: onClickProp, ...props }, ref) => {
const [, forceUpate] = useState(0);
const { disabled, id, hasError, selectedValues, updateSearch, getValueProps } =
useCombobox();
const onClick = (e: MouseEvent<HTMLButtonElement>) => {
Expand All @@ -182,6 +184,10 @@ const Trigger = forwardRef<HTMLButtonElement, TriggerProps>(
};
const nodeProps =
selectedValues.length === 0 ? null : getValueProps(selectedValues[0]);
useEffect(() => {
forceUpate(n => n + 1);
}, []);

return (
<ComboboxTrigger
ref={ref}
Expand Down

0 comments on commit f8a798d

Please sign in to comment.