Hero Hook Form API / AutocompleteFieldProps
Type Alias: AutocompleteFieldProps<TFieldValues, TValue>
AutocompleteFieldProps<
TFieldValues,TValue> =FieldBaseProps<TFieldValues,TValue> &WithControl<TFieldValues> &object
Defined in: fields/AutocompleteField.tsx:58
Props for the AutocompleteField component.
Type Declaration
items?
optionalitems: readonlyAutocompleteOption<TValue>[]
Array of autocomplete options (for static lists)
placeholder?
optionalplaceholder:string
Placeholder text when no option is selected
autocompleteProps?
optionalautocompleteProps:Omit<React.ComponentProps<typeofAutocomplete>,"selectedKey"|"onSelectionChange"|"inputValue"|"onInputChange"|"label"|"isInvalid"|"errorMessage"|"isDisabled"|"children"|"items"|"defaultItems">
Additional props to pass to the underlying Autocomplete component
children()?
optionalchildren: (item) =>React.JSX.Element
Custom render function for items (for async loading)
Parameters
item
AutocompleteOption<TValue>
Returns
React.JSX.Element
Type Parameters
TFieldValues
TFieldValues extends FieldValues
The form data type
TValue
TValue extends string | number = string
The value type for the autocomplete field (string or number)
Example
import { AutocompleteField } from "@rachelallyson/hero-hook-form";
import { useForm } from "react-hook-form";
const form = useForm({
defaultValues: { country: "" },
});
const options = [
{ label: "United States", value: "us" },
{ label: "Canada", value: "ca" },
{ label: "Mexico", value: "mx" },
];
<AutocompleteField
control={form.control}
name="country"
label="Country"
items={options}
placeholder="Search for a country"
/>