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] Support ChipComponent type #37112

Merged
merged 9 commits into from
May 9, 2023
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
3 changes: 2 additions & 1 deletion packages/mui-material/src/Autocomplete/Autocomplete.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,4 +293,5 @@ export default function Autocomplete<
Multiple extends boolean | undefined = false,
DisableClearable extends boolean | undefined = false,
FreeSolo extends boolean | undefined = false,
>(props: AutocompleteProps<T, Multiple, DisableClearable, FreeSolo>): JSX.Element;
ChipComponent extends React.ElementType = ChipTypeMap['defaultComponent'],
>(props: AutocompleteProps<T, Multiple, DisableClearable, FreeSolo, ChipComponent>): JSX.Element;
21 changes: 19 additions & 2 deletions packages/mui-material/src/Autocomplete/Autocomplete.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import * as React from 'react';
import Autocomplete, {
AutocompleteOwnerState,
AutocompleteProps,
AutocompleteRenderGetTagProps,
} from '@mui/material/Autocomplete';
import TextField from '@mui/material/TextField';
import { expectType } from '@mui/types';
import { ChipTypeMap } from '@mui/material/Chip';

interface MyAutocompleteProps<
T,
Multiple extends boolean | undefined,
DisableClearable extends boolean | undefined,
FreeSolo extends boolean | undefined,
> extends AutocompleteProps<T, Multiple, DisableClearable, FreeSolo> {
ChipComponent extends React.ElementType = ChipTypeMap['defaultComponent'],
sai6855 marked this conversation as resolved.
Show resolved Hide resolved
> extends AutocompleteProps<T, Multiple, DisableClearable, FreeSolo, ChipComponent> {
myProp?: string;
}

Expand All @@ -20,10 +23,24 @@ function MyAutocomplete<
Multiple extends boolean | undefined = false,
DisableClearable extends boolean | undefined = false,
FreeSolo extends boolean | undefined = false,
>(props: MyAutocompleteProps<T, Multiple, DisableClearable, FreeSolo>) {
ChipComponent extends React.ElementType = ChipTypeMap['defaultComponent'],
>(props: MyAutocompleteProps<T, Multiple, DisableClearable, FreeSolo, ChipComponent>) {
return <Autocomplete {...props} />;
}

// Test for ChipComponent generic type
<MyAutocomplete<string, false, false, false, 'span'>
options={['1', '2', '3']}
renderTags={(value, getTagProps, ownerState) => {
expectType<AutocompleteOwnerState<string, false, false, false, 'span'>, typeof ownerState>(
ownerState,
);

return '';
}}
renderInput={() => null}
/>;

// multiple prop can be assigned for components that extend AutocompleteProps
<MyAutocomplete
options={['1', '2', '3']}
Expand Down