Skip to content

Commit

Permalink
change implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
sai6855 committed Mar 12, 2024
1 parent 2480153 commit a357d39
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 38 deletions.
23 changes: 6 additions & 17 deletions packages/mui-material/src/Select/Select.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,10 @@ export interface OutlinedSelectProps extends Omit<OutlinedInputProps, 'value' |

export type SelectVariants = 'outlined' | 'standard' | 'filled';

export type SelectProps<
Value = unknown,
Variant extends SelectVariants = SelectVariants,
> = BaseSelectProps<Value> &
(Variant extends 'filled'
? FilledSelectProps
: Variant extends 'standard'
? StandardSelectProps
: OutlinedSelectProps);
export type SelectProps<Value = unknown> =
| (FilledSelectProps & BaseSelectProps<Value>)
| (StandardSelectProps & BaseSelectProps<Value>)
| (OutlinedSelectProps & BaseSelectProps<Value>);

/**
*
Expand All @@ -198,14 +193,8 @@ export type SelectProps<
* - [Select API](https://mui.com/material-ui/api/select/)
* - inherits [OutlinedInput API](https://mui.com/material-ui/api/outlined-input/)
*/
export default function Select<Value = unknown, Variant extends SelectVariants = 'outlined'>(
props: {
/**
* The variant to use.
* @default 'outlined'
*/
variant?: Variant;
} & SelectProps<Value, Variant>,
export default function Select<Value = unknown>(
props: SelectProps<Value>,
): JSX.Element & {
muiName: string;
};
46 changes: 25 additions & 21 deletions packages/mui-material/src/Select/Select.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,26 +76,19 @@ function genericValueTest() {
}}
/>;

// @ts-expect-error
<Select<number, 'filled'> />;
// @ts-expect-error
<Select<number, 'standard'> />;
// @ts-expect-error
<Select<number, 'standard'> variant="filled" />;
// @ts-expect-error
<Select<number, 'filled'> variant="standard" />;

<Select<number, 'outlined'> />;

<Select<number, 'filled'> variant="filled" />;
<Select<number, 'outlined'> variant="outlined" />;
<Select<number, 'standard'> variant="standard" />;

<Select variant="filled" />;
<Select variant="standard" />;
<Select variant="outlined" />;
<Select />;

<Select variant="filled" hiddenLabel />;
// @ts-expect-error hiddenLabel is not present in standard variant
<Select variant="standard" hiddenLabel />;
// @ts-expect-error hiddenLabel is not present in outlined variant
<Select variant="outlined" hiddenLabel />;
// @ts-expect-error hiddenLabel is not present in outlined variant
<Select hiddenLabel />;

const defaultProps: SelectProps<number> = {};
const outlinedProps: SelectProps<number> = {
variant: 'outlined',
Expand All @@ -113,13 +106,7 @@ function genericValueTest() {
<Select {...standardProps} />;
<Select<number> {...outlinedProps} />;
<Select<number> {...defaultProps} />;
<Select<number, 'standard'> {...standardProps} />;
// @ts-expect-error variant type mismatch
<Select<number> {...filledProps} />;
// @ts-expect-error variant type mismatch
<Select<number, 'outlined'> {...filledProps} />;
// @ts-expect-error variant type mismatch
<Select<number, 'standard'> {...filledProps} />;

const rawDefaultProps: SelectProps = {};
const rawOutlinedProps: SelectProps = {
Expand All @@ -140,6 +127,23 @@ function genericValueTest() {
<Select {...filledProps} hiddenLabel />;
// @ts-expect-error hiddenLabel is not present in standard variant
<Select {...standardProps} hiddenLabel />;

interface OtherProps {
otherProp?: number;
}

const SelectWrapper1 = <Value = unknown,>(props: SelectProps<Value> & OtherProps) => {
const { otherProp, ...materialSelectProps } = props;

return (
// how to solve this:
<Select<Value> {...materialSelectProps} />
);
};

<SelectWrapper1 />;
<SelectWrapper1<number> variant="filled" hiddenLabel />;
<SelectWrapper1 variant="filled" hiddenLabel />;
}

type Options<T> = { text: string; value: T } | T;
Expand Down

0 comments on commit a357d39

Please sign in to comment.