Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Autocomplete] Fix useAutocomplete groupedOptions type #23854

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/src/pages/components/autocomplete/CustomizedHook.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export default function CustomizedHook() {
</div>
{groupedOptions.length > 0 ? (
<Listbox {...getListboxProps()}>
{groupedOptions.map((option, index) => (
{(groupedOptions as typeof top100Films).map((option, index) => (
<li {...getOptionProps({ option, index })}>
<span>{option.title}</span>
<CheckIcon fontSize="small" />
Expand Down
2 changes: 1 addition & 1 deletion docs/src/pages/components/autocomplete/UseAutocomplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export default function UseAutocomplete() {
</div>
{groupedOptions.length > 0 ? (
<ul className={classes.listbox} {...getListboxProps()}>
{groupedOptions.map((option, index) => (
{(groupedOptions as typeof top100Films).map((option, index) => (
<li {...getOptionProps({ option, index })}>{option.title}</li>
))}
</ul>
Expand Down
12 changes: 11 additions & 1 deletion packages/material-ui/src/useAutocomplete/useAutocomplete.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ export interface FilterOptionsState<T> {
getOptionLabel: (option: T) => string;
}

export interface AutocompleteGroupedOption<T = string> {
key: number;
index: number;
group: string;
options: T[];
}

export function createFilterOptions<T>(
config?: CreateFilterOptionsConfig<T>
): (options: T[], state: FilterOptionsState<T>) => T[];
Expand Down Expand Up @@ -311,5 +318,8 @@ export default function useAutocomplete<
anchorEl: null | HTMLElement;
setAnchorEl: () => void;
focusedTag: number;
groupedOptions: T[];
/**
* The options to render. It's either `T[]` or `AutocompleteGroupedOption<T>[]` if the groupBy prop is provided.
*/
groupedOptions: T[] | Array<AutocompleteGroupedOption<T>>;
};