Skip to content

Commit

Permalink
[material-ui][TablePagination] Fix type error in Select props (#39137)
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulKristoffersson authored Feb 20, 2024
1 parent 0f8d965 commit a367c25
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 8 deletions.
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';

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

/**
*
* 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,
},
}}
/>;

0 comments on commit a367c25

Please sign in to comment.