From 07788a5fb2a9a61b74022d6c9436277cf637ce9a Mon Sep 17 00:00:00 2001 From: sai6855 Date: Fri, 8 Mar 2024 10:31:31 +0530 Subject: [PATCH 01/10] fix-variant-type --- packages/mui-material/src/Select/Select.d.ts | 49 ++++++++++++++----- .../mui-material/src/Select/Select.spec.tsx | 17 ++++++- 2 files changed, 54 insertions(+), 12 deletions(-) diff --git a/packages/mui-material/src/Select/Select.d.ts b/packages/mui-material/src/Select/Select.d.ts index cbf55494ba697f..fec758ad8a1a48 100644 --- a/packages/mui-material/src/Select/Select.d.ts +++ b/packages/mui-material/src/Select/Select.d.ts @@ -187,6 +187,43 @@ export type SelectProps< ? StandardSelectProps : OutlinedSelectProps); +interface SelectType { + ( + props: { + /** + * The variant to use. + * @default 'outlined' + */ + variant: Variant; + } & Omit, 'variant'>, + ): JSX.Element & { + muiName: string; + }; + ( + props: { + /** + * The variant to use. + * @default 'outlined' + */ + variant?: Variant; + } & Omit, 'variant'>, + ): JSX.Element & { + muiName: string; + }; +} +/** + * + * Demos: + * + * - [Select](https://mui.com/material-ui/react-select/) + * + * API: + * + * - [Select API](https://mui.com/material-ui/api/select/) + * - inherits [OutlinedInput API](https://mui.com/material-ui/api/outlined-input/) + */ +declare const Select: SelectType; + /** * * Demos: @@ -199,14 +236,4 @@ export type SelectProps< * - inherits [OutlinedInput API](https://mui.com/material-ui/api/outlined-input/) */ -export default function Select( - props: { - /** - * The variant to use. - * @default 'outlined' - */ - variant?: Variant; - } & Omit, 'variant'>, -): JSX.Element & { - muiName: string; -}; +export default Select; diff --git a/packages/mui-material/src/Select/Select.spec.tsx b/packages/mui-material/src/Select/Select.spec.tsx index 25283d8a874054..134ea47d6599d9 100644 --- a/packages/mui-material/src/Select/Select.spec.tsx +++ b/packages/mui-material/src/Select/Select.spec.tsx @@ -1,5 +1,5 @@ import * as React from 'react'; -import Select, { SelectChangeEvent } from '@mui/material/Select'; +import Select, { SelectChangeEvent, SelectProps } from '@mui/material/Select'; import MenuItem from '@mui/material/MenuItem'; import { createTheme } from '@mui/material/styles'; @@ -75,4 +75,19 @@ function genericValueTest() { }, }} />; + + // @ts-expect-error + />; + // @ts-expect-error + />; + // @ts-expect-error + variant="filled" />; + // @ts-expect-error + variant="standard" />; + + />; + + variant="filled" />; + variant="outlined" />; + variant="standard" />; } From a2ac82e7e47ff3c43b7ef8e8bbeb401fef287d5e Mon Sep 17 00:00:00 2001 From: sai6855 Date: Fri, 8 Mar 2024 10:37:15 +0530 Subject: [PATCH 02/10] more-tests --- packages/mui-material/src/Select/Select.spec.tsx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/mui-material/src/Select/Select.spec.tsx b/packages/mui-material/src/Select/Select.spec.tsx index 134ea47d6599d9..9e2c4961b8d698 100644 --- a/packages/mui-material/src/Select/Select.spec.tsx +++ b/packages/mui-material/src/Select/Select.spec.tsx @@ -90,4 +90,7 @@ function genericValueTest() { variant="filled" />; variant="outlined" />; variant="standard" />; + + ; } From 784af677520ba887569d61933c8a17dcc5e9fec9 Mon Sep 17 00:00:00 2001 From: sai6855 Date: Fri, 8 Mar 2024 10:38:21 +0530 Subject: [PATCH 03/10] more-tests --- packages/mui-material/src/Select/Select.spec.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/mui-material/src/Select/Select.spec.tsx b/packages/mui-material/src/Select/Select.spec.tsx index 9e2c4961b8d698..6f28c39d04a075 100644 --- a/packages/mui-material/src/Select/Select.spec.tsx +++ b/packages/mui-material/src/Select/Select.spec.tsx @@ -93,4 +93,6 @@ function genericValueTest() { ; + ; } From 0804ff7882eac799eca4f139c4956a22582bed37 Mon Sep 17 00:00:00 2001 From: sai6855 Date: Fri, 8 Mar 2024 11:37:08 +0530 Subject: [PATCH 04/10] remove-unused-import --- packages/mui-material/src/Select/Select.spec.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/mui-material/src/Select/Select.spec.tsx b/packages/mui-material/src/Select/Select.spec.tsx index 6f28c39d04a075..150d2ede09f967 100644 --- a/packages/mui-material/src/Select/Select.spec.tsx +++ b/packages/mui-material/src/Select/Select.spec.tsx @@ -1,5 +1,5 @@ import * as React from 'react'; -import Select, { SelectChangeEvent, SelectProps } from '@mui/material/Select'; +import Select, { SelectChangeEvent } from '@mui/material/Select'; import MenuItem from '@mui/material/MenuItem'; import { createTheme } from '@mui/material/styles'; From d7bda2aa8d0a39c5d168a52d178b34a2ac4b9ad0 Mon Sep 17 00:00:00 2001 From: sai6855 Date: Fri, 8 Mar 2024 18:30:41 +0530 Subject: [PATCH 05/10] fix #41356 --- packages/mui-material/src/Select/Select.d.ts | 2 +- .../mui-material/src/Select/Select.spec.tsx | 47 ++++++++++++++++++- 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/packages/mui-material/src/Select/Select.d.ts b/packages/mui-material/src/Select/Select.d.ts index fec758ad8a1a48..9aa1e668f7185f 100644 --- a/packages/mui-material/src/Select/Select.d.ts +++ b/packages/mui-material/src/Select/Select.d.ts @@ -172,7 +172,7 @@ export interface OutlinedSelectProps extends Omit; ; + + const defaultProps: SelectProps = {}; + const outlinedProps: SelectProps = { + variant: 'outlined', + }; + const filledProps: SelectProps = { + variant: 'filled', + }; + const standardProps: SelectProps = { + variant: 'standard', + }; + + ; + ; + {...outlinedProps} />; + {...defaultProps} />; + {...standardProps} />; + // @ts-expect-error variant type mismatch + {...filledProps} />; + // @ts-expect-error variant type mismatch + {...filledProps} />; + // @ts-expect-error variant type mismatch + {...filledProps} />; + + const rawDefaultProps: SelectProps = {}; + const rawOutlinedProps: SelectProps = { + variant: 'outlined', + }; + const rawFilledProps: SelectProps = { + variant: 'filled', + }; + + ; + ; + // @ts-expect-error hiddenLabel is not present in outlined variant + ; + // @ts-expect-error hiddenLabel is not present in standard variant + ; } + +type Options = { text: string; value: T } | T; + +type Props = ( + | { + value: T; + multiple?: false; + onChange: (value: T) => void; + } + | { + value: T[]; + multiple: true; + onChange: (value: T[]) => void; + } +) & { + options: Options[]; +}; + +// test for https://github.com/mui/material-ui/issues/41375 +const AppSelect = (props: Props) => { + const getOptionText = (option: Options) => { + if (typeof option === 'object') { + return option.text; + } + return option; + }; + + const getOptionValue = (option: Options) => { + if (typeof option === 'object') { + return option.value; + } + return option; + }; + + return ( + + ); +}; From c9e47429acb5f0a37994d631bb371ff05184710d Mon Sep 17 00:00:00 2001 From: sai6855 Date: Tue, 12 Mar 2024 18:49:38 +0530 Subject: [PATCH 07/10] change implementation --- packages/mui-material/src/Select/Select.d.ts | 23 +++------- .../mui-material/src/Select/Select.spec.tsx | 46 ++++++++++--------- 2 files changed, 31 insertions(+), 38 deletions(-) diff --git a/packages/mui-material/src/Select/Select.d.ts b/packages/mui-material/src/Select/Select.d.ts index 3685b99876d5bb..5d052f0a697ff4 100644 --- a/packages/mui-material/src/Select/Select.d.ts +++ b/packages/mui-material/src/Select/Select.d.ts @@ -177,15 +177,10 @@ export interface OutlinedSelectProps extends Omit = BaseSelectProps & - (Variant extends 'filled' - ? FilledSelectProps - : Variant extends 'standard' - ? StandardSelectProps - : OutlinedSelectProps); +export type SelectProps = + | (FilledSelectProps & BaseSelectProps) + | (StandardSelectProps & BaseSelectProps) + | (OutlinedSelectProps & BaseSelectProps); /** * @@ -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( - props: { - /** - * The variant to use. - * @default 'outlined' - */ - variant?: Variant; - } & SelectProps, +export default function Select( + props: SelectProps, ): JSX.Element & { muiName: string; }; diff --git a/packages/mui-material/src/Select/Select.spec.tsx b/packages/mui-material/src/Select/Select.spec.tsx index 3e324c34bf9106..a98481b8e0ee84 100644 --- a/packages/mui-material/src/Select/Select.spec.tsx +++ b/packages/mui-material/src/Select/Select.spec.tsx @@ -76,26 +76,19 @@ function genericValueTest() { }} />; - // @ts-expect-error - />; - // @ts-expect-error - />; - // @ts-expect-error - variant="filled" />; - // @ts-expect-error - variant="standard" />; - - />; - - variant="filled" />; - variant="outlined" />; - variant="standard" />; - ; ; + ; + // @ts-expect-error hiddenLabel is not present in outlined variant + ; + const defaultProps: SelectProps = {}; const outlinedProps: SelectProps = { variant: 'outlined', @@ -113,13 +106,7 @@ function genericValueTest() { ; // @ts-expect-error hiddenLabel is not present in standard variant