mirror of
https://github.com/grafana/grafana.git
synced 2025-01-15 19:22:34 -06:00
New Select: Set highlighted index to selected item on open (#91951)
* Set highlighted index on open * Remove console log * Use defaultHighLightedIndex
This commit is contained in:
parent
f432a1713b
commit
b0031c0781
@ -48,7 +48,11 @@ function estimateSize() {
|
||||
export const Combobox = ({ options, onChange, value, ...restProps }: ComboboxProps) => {
|
||||
const MIN_WIDTH = 400;
|
||||
const [items, setItems] = useState(options);
|
||||
const selectedItem = useMemo(() => options.find((option) => option.value === value) || null, [options, value]);
|
||||
const selectedItemIndex = useMemo(
|
||||
() => options.findIndex((option) => option.value === value) || null,
|
||||
[options, value]
|
||||
);
|
||||
const selectedItem = selectedItemIndex ? options[selectedItemIndex] : null;
|
||||
|
||||
const inputRef = useRef<HTMLInputElement>(null);
|
||||
const floatingRef = useRef(null);
|
||||
@ -66,6 +70,7 @@ export const Combobox = ({ options, onChange, value, ...restProps }: ComboboxPro
|
||||
items,
|
||||
itemToString,
|
||||
selectedItem,
|
||||
defaultHighlightedIndex: selectedItemIndex ?? undefined,
|
||||
scrollIntoView: () => {},
|
||||
onInputValueChange: ({ inputValue }) => {
|
||||
setItems(options.filter(itemFilter(inputValue)));
|
||||
|
Loading…
Reference in New Issue
Block a user