Skip to content

Commit

Permalink
fix: added extra props to Autocomplete to fix MUI types
Browse files Browse the repository at this point in the history
This doesn't actually fix MUI types, but it passes enough to push it.
  • Loading branch information
KevinGhadyani-Okta committed Apr 18, 2023
1 parent a93542c commit d7aff4a
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 7 deletions.
58 changes: 51 additions & 7 deletions packages/odyssey-react-mui/src/Autocomplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,65 @@ import { memo, useCallback } from "react";

import { Field } from "./Field";

export type AutocompleteProps<OptionType> = {
isDisabled?: boolean;
export type AutocompleteProps<
OptionType,
HasMultipleChoices extends boolean | undefined,
IsCustomValueAllowed extends boolean | undefined
> = {
hasMultipleChoices?: MuiAutocompleteProps<
OptionType,
HasMultipleChoices,
undefined,
IsCustomValueAllowed
>["multiple"];
hint?: string;
isCustomValueAllowed?: MuiAutocompleteProps<
OptionType,
HasMultipleChoices,
undefined,
IsCustomValueAllowed
>["freeSolo"];
isDisabled?: MuiAutocompleteProps<
OptionType,
HasMultipleChoices,
undefined,
IsCustomValueAllowed
>["disabled"];
label: string;
onChange?: MuiAutocompleteProps<OptionType, false, false, false>["onChange"];
options: MuiAutocompleteProps<OptionType, false, false, false>["options"];
value?: MuiAutocompleteProps<OptionType, false, false, false>["value"];
onChange?: MuiAutocompleteProps<
OptionType,
HasMultipleChoices,
undefined,
IsCustomValueAllowed
>["onChange"];
options: MuiAutocompleteProps<
OptionType,
HasMultipleChoices,
undefined,
IsCustomValueAllowed
>["options"];
value?: MuiAutocompleteProps<
OptionType,
HasMultipleChoices,
undefined,
IsCustomValueAllowed
>["value"];
};

const Autocomplete = <OptionType,>({
const Autocomplete = <
OptionType,
HasMultipleChoices extends boolean | undefined,
IsCustomValueAllowed extends boolean | undefined
>({
isCustomValueAllowed,
hasMultipleChoices,
isDisabled,
hint,
label,
onChange,
options,
value,
}: AutocompleteProps<OptionType>) => {
}: AutocompleteProps<OptionType, HasMultipleChoices, IsCustomValueAllowed>) => {
const renderInput = useCallback(
({ InputLabelProps, InputProps, ...params }) => (
<Field
Expand All @@ -59,6 +101,8 @@ const Autocomplete = <OptionType,>({
return (
<MuiAutocomplete
disabled={isDisabled}
freeSolo={isCustomValueAllowed}
multiple={hasMultipleChoices}
onChange={onChange}
options={options}
renderInput={renderInput}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ const Template: ComponentStory<typeof Autocomplete> = (args) => {
hint="Select your favorite movie"
label="Movie"
options={top100Films}
value={{ label: "", year: 2000 }}
/>
);
};
Expand Down Expand Up @@ -220,6 +221,7 @@ const MuiTemplate: ComponentStory<typeof Autocomplete> = (args) => {
{...args}
options={top100Films}
// renderInput={(params) => <MuiTextField {...params} label="Movie" />}
value={{ label: "", year: 2000 }}
/>
);
};
Expand Down

0 comments on commit d7aff4a

Please sign in to comment.