Skip to content

Commit

Permalink
Revert "[Autocomplete] Type multiple values with readonly arrays. (#3…
Browse files Browse the repository at this point in the history
…8253)"

This reverts commit 5d8f213.
  • Loading branch information
mnajdova authored Sep 6, 2023
1 parent 95a9ebc commit b64fb92
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 27 deletions.
7 changes: 2 additions & 5 deletions docs/data/joy/components/autocomplete/GitHubLabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,8 @@ const Listbox = React.forwardRef<HTMLUListElement, any>((props, ref) => (

export default function GitHubLabel() {
const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null);
const [value, setValue] = React.useState<readonly LabelType[]>([
labels[1],
labels[11],
]);
const [pendingValue, setPendingValue] = React.useState<readonly LabelType[]>([]);
const [value, setValue] = React.useState<LabelType[]>([labels[1], labels[11]]);
const [pendingValue, setPendingValue] = React.useState<LabelType[]>([]);

const handleClick = (event: React.MouseEvent<HTMLElement>) => {
setPendingValue(value);
Expand Down
7 changes: 2 additions & 5 deletions docs/data/material/components/autocomplete/GitHubLabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,8 @@ const Button = styled(ButtonBase)(({ theme }) => ({

export default function GitHubLabel() {
const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null);
const [value, setValue] = React.useState<readonly LabelType[]>([
labels[1],
labels[11],
]);
const [pendingValue, setPendingValue] = React.useState<readonly LabelType[]>([]);
const [value, setValue] = React.useState<LabelType[]>([labels[1], labels[11]]);
const [pendingValue, setPendingValue] = React.useState<LabelType[]>([]);
const theme = useTheme();

const handleClick = (event: React.MouseEvent<HTMLElement>) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-base/src/useAutocomplete/useAutocomplete.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function createFilterOptions<Value>(
export type AutocompleteFreeSoloValueMapping<FreeSolo> = FreeSolo extends true ? string : never;

export type AutocompleteValue<Value, Multiple, DisableClearable, FreeSolo> = Multiple extends true
? ReadonlyArray<Value | AutocompleteFreeSoloValueMapping<FreeSolo>>
? Array<Value | AutocompleteFreeSoloValueMapping<FreeSolo>>
: DisableClearable extends true
? NonNullable<Value | AutocompleteFreeSoloValueMapping<FreeSolo>>
: Value | null | AutocompleteFreeSoloValueMapping<FreeSolo>;
Expand Down
20 changes: 5 additions & 15 deletions packages/mui-base/src/useAutocomplete/useAutocomplete.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function Component() {
options: ['1', '2', '3'],
multiple: true,
onChange(event, value) {
expectType<readonly string[], typeof value>(value);
expectType<string[], typeof value>(value);
value;
},
});
Expand All @@ -83,7 +83,7 @@ function Component() {
options: ['1', '2', '3', 4, true],
multiple: true,
onChange(event, value) {
expectType<ReadonlyArray<string | number | boolean>, typeof value>(value);
expectType<Array<string | number | boolean>, typeof value>(value);
},
});

Expand All @@ -92,7 +92,7 @@ function Component() {
options: persons,
multiple: true,
onChange(event, value) {
expectType<readonly Person[], typeof value>(value);
expectType<Person[], typeof value>(value);
value;
},
});
Expand All @@ -101,7 +101,7 @@ function Component() {
useAutocomplete({
options: persons,
multiple: true,
onChange(event, value: readonly Person[]) {},
onChange(event, value: Person[]) {},
});

// options accepts const and value has correct type
Expand All @@ -112,16 +112,6 @@ function Component() {
},
});

// values accepts const and value has correct type
useAutocomplete({
options: ['1', '2', '3'] as const,
multiple: true,
value: ['1', '3'] as const,
onChange(event, value) {
expectType<ReadonlyArray<'1' | '2' | '3'>, typeof value>(value);
},
});

// Disable clearable

useAutocomplete({
Expand Down Expand Up @@ -169,7 +159,7 @@ function Component() {
options: persons,
multiple: true,
onChange(event, value) {
expectType<ReadonlyArray<string | Person>, typeof value>(value);
expectType<Array<string | Person>, typeof value>(value);
},
freeSolo: true,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function MyAutocomplete<
<MyAutocomplete
options={['1', '2', '3']}
onChange={(event, value) => {
expectType<readonly string[], typeof value>(value);
expectType<string[], typeof value>(value);
}}
renderInput={() => null}
multiple
Expand Down

0 comments on commit b64fb92

Please sign in to comment.