Skip to content

Commit

Permalink
fix(dropdown): set value
Browse files Browse the repository at this point in the history
  • Loading branch information
tanmen committed Dec 10, 2023
1 parent 296268f commit 757c19f
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/dropdowns/SearchDropdown/SearchDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ export type SearchDropdownProps = {
items: SearchDropdownItem[]
onTextChange?: (text: string) => Promise<unknown> | unknown;
className?: string;
} & Omit<DetailedHTMLProps<InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>, 'type' | 'value' | 'ref' | 'className'>
} & Omit<DetailedHTMLProps<InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>, 'type' | 'ref' | 'className'>

export const SearchDropdown: FC<SearchDropdownProps> = forwardRef<HTMLInputElement, SearchDropdownProps>(
({items, onTextChange,className, ...props}, ref) => {
const [value, setValue] = useState<string>();
({items, onTextChange,className,value, ...props}, ref) => {
const [_value, setValue] = useState<string | readonly string[] | number | undefined>(value);
const [open, setOpen] = useState(false);
return <Dropdown className={className} open={open}
items={items.map(({key, body}) => <div key={key} onClick={() => setValue(key)}>{body}</div>)}>
<input ref={ref} type="hidden" value={value} {...props}/>
<input ref={ref} type="hidden" value={_value} {...props}/>
<Input className="react-actors-search-dropdown-input" onFocus={() => setOpen(true)} onBlur={() => setOpen(false)}
onChange={e => onTextChange?.(e.target.value)}/>
</Dropdown>;
Expand Down

0 comments on commit 757c19f

Please sign in to comment.