Skip to content

Commit

Permalink
fix(dropdown): add props
Browse files Browse the repository at this point in the history
  • Loading branch information
tanmen committed Dec 10, 2023
1 parent 3e3c83b commit 0d1a78a
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
@@ -1,4 +1,4 @@
import {FC, forwardRef, ReactNode, useState} from "react";
import {DetailedHTMLProps, FC, forwardRef, InputHTMLAttributes, ReactNode, useState} from "react";
import {Input} from "../../inputs/Input";
import {Dropdown} from "../Dropdown/Dropdown";

Expand All @@ -10,15 +10,15 @@ export type SearchDropdownItem = {
export type SearchDropdownProps = {
items: SearchDropdownItem[]
onTextChange?: (text: string) => Promise<unknown> | unknown;
}
} & Omit<DetailedHTMLProps<InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>, 'type' | 'value' | 'ref'>

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

0 comments on commit 0d1a78a

Please sign in to comment.