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

[material-ui][TablePagination] Fix type error in Select props #39137

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default function MultipleSelectNative() {
<InputLabel shrink htmlFor="select-multiple-native">
Native
</InputLabel>
<Select
<Select<string[]>
multiple
native
value={personName}
Expand Down
57 changes: 50 additions & 7 deletions packages/mui-material/src/Select/Select.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import { MenuProps } from '../Menu';
import { SelectChangeEvent, SelectInputProps } from './SelectInput';
import { SelectClasses } from './selectClasses';
import { OutlinedInputProps } from '../OutlinedInput';
import { FilledInputProps } from '../FilledInput';

export { SelectChangeEvent };

export interface SelectProps<Value = unknown>
extends StandardProps<InputProps, 'value' | 'onChange'>,
Omit<OutlinedInputProps, 'value' | 'onChange'> {
export interface BaseSelectProps<Value = unknown>
extends StandardProps<InputProps, 'value' | 'onChange'> {
/**
* If `true`, the width of the popover will automatically be set according to the items inside the
* menu, otherwise it will be at least the width of the select input.
Expand Down Expand Up @@ -148,9 +148,45 @@ export interface SelectProps<Value = unknown>
* The variant to use.
* @default 'outlined'
*/
variant?: 'standard' | 'outlined' | 'filled';
variant?: 'filled' | 'standard' | 'outlined';
}

export interface FilledSelectProps extends Omit<FilledInputProps, 'value' | 'onChange'> {
/**
* The variant to use.
* @default 'outlined'
*/
variant: 'filled';
}

export interface StandardSelectProps extends Omit<InputProps, 'value' | 'onChange'> {
/**
* The variant to use.
* @default 'outlined'
*/
variant: 'standard';
}

export interface OutlinedSelectProps extends Omit<OutlinedInputProps, 'value' | 'onChange'> {
/**
* The variant to use.
* @default 'outlined'
*/
variant: 'outlined';
}

export type SelectVariants = 'outlined' | 'standard' | 'filled';
ZeeshanTamboli marked this conversation as resolved.
Show resolved Hide resolved

export type SelectProps<
Value = unknown,
Variant extends SelectVariants = SelectVariants,
> = BaseSelectProps<Value> &
(Variant extends 'filled'
? FilledSelectProps
: Variant extends 'standard'
? StandardSelectProps
: OutlinedSelectProps);
Comment on lines +180 to +188
Copy link
Contributor

@Methuselah96 Methuselah96 Feb 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, this is breaking type change for people using SelectProps directly because the variant prop is required now when it wasn't before. I guess BaseSelectProps is a suitable replacement for most use cases?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Using BaseSelectProps instead of SelectProps fixed the build in our component library after updating mui to 5.15.11

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed it in #41359


/**
*
* Demos:
Expand All @@ -162,8 +198,15 @@ export interface SelectProps<Value = unknown>
* - [Select API](https://mui.com/material-ui/api/select/)
* - inherits [OutlinedInput API](https://mui.com/material-ui/api/outlined-input/)
*/
declare const Select: (<Value>(props: SelectProps<Value>) => JSX.Element) & {

export default function Select<Value = unknown, Variant extends SelectVariants = 'outlined'>(
props: {
/**
* The variant to use.
* @default 'outlined'
*/
variant?: Variant;
} & Omit<SelectProps<Value, Variant>, 'variant'>,
): JSX.Element & {
muiName: string;
};

export default Select;
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,11 @@ function classesTest() {
fill: 'currentColor',
},
},
select: {
size: 'small',
variant: 'filled',
hiddenLabel: true,
disableUnderline: true,
},
}}
/>;
Loading