import type { ReactNode } from "react";
import { AccentScope } from "../containers/AccentScope";
import { Popover } from "../containers/Popover";
import { View } from "../primitives/View";
import { InputText } from "./InputText";
import {
AutocompleteMenu,
type InputTextAutocompleteProps,
defaultFilterOption,
useAutocomplete,
} from "./InputTextAutocomplete.shared";
/**
* Native presents the combobox as a sheet: a `Modal` resigns the keyboard of
* whatever is behind it, so the editable input has to live inside the overlay,
* and the field left in the layout is a read-only trigger showing the current
* text.
*/
export function InputTextAutocomplete({
filterOption = defaultFilterOption,
emptyLabel = "No result",
placeholder,
disabled,
invalid,
accent,
mode,
className,
testID,
"aria-describedby": ariaDescribedby,
"aria-required": ariaRequired,
...rest
}: InputTextAutocompleteProps): ReactNode {
const {
isOpen,
currentInputValue,
inputProps,
openMenu,
closeMenu,
...menu
} = useAutocomplete({
...rest,
disabled,
filterOption,
scrollIntoView: false,
inputInPopover: true,
});
// `onKeyDown` is web-only: on native `onKeyPress` carries an RN event
// downshift cannot read, and there is no keyboard navigation to drive anyway.
const { ref: inputRef, onKeyDown, onClick, ...restInputProps } = inputProps;
return (
<>
{
if (!disabled) openMenu();
}}
/>
>
);
}