Skip to content

Commit 043a022

Browse files
committed
Copy Select files from material v5
1 parent 572449d commit 043a022

File tree

9 files changed

+3080
-0
lines changed

9 files changed

+3080
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
import * as React from 'react';
2+
import { SxProps } from '@mui/system';
3+
import { InternalStandardProps as StandardProps, Theme } from '..';
4+
import { InputProps } from '../Input';
5+
import { MenuProps } from '../Menu';
6+
import { SelectChangeEvent, SelectInputProps } from './SelectInput';
7+
import { SelectClasses } from './selectClasses';
8+
import { OutlinedInputProps } from '../OutlinedInput';
9+
10+
export { SelectChangeEvent };
11+
12+
export interface SelectProps<Value = unknown>
13+
extends StandardProps<InputProps, 'value' | 'onChange'>,
14+
Omit<OutlinedInputProps, 'value' | 'onChange'>,
15+
Pick<SelectInputProps<Value>, 'onChange'> {
16+
/**
17+
* If `true`, the width of the popover will automatically be set according to the items inside the
18+
* menu, otherwise it will be at least the width of the select input.
19+
* @default false
20+
*/
21+
autoWidth?: boolean;
22+
/**
23+
* The option elements to populate the select with.
24+
* Can be some `MenuItem` when `native` is false and `option` when `native` is true.
25+
*
26+
* ⚠️The `MenuItem` elements **must** be direct descendants when `native` is false.
27+
*/
28+
children?: React.ReactNode;
29+
/**
30+
* Override or extend the styles applied to the component.
31+
* @default {}
32+
*/
33+
classes?: Partial<SelectClasses>;
34+
/**
35+
* If `true`, the component is initially open. Use when the component open state is not controlled (i.e. the `open` prop is not defined).
36+
* You can only use it when the `native` prop is `false` (default).
37+
* @default false
38+
*/
39+
defaultOpen?: boolean;
40+
/**
41+
* The default value. Use when the component is not controlled.
42+
*/
43+
defaultValue?: Value;
44+
/**
45+
* If `true`, a value is displayed even if no items are selected.
46+
*
47+
* In order to display a meaningful value, a function can be passed to the `renderValue` prop which
48+
* returns the value to be displayed when no items are selected.
49+
*
50+
* ⚠️ When using this prop, make sure the label doesn't overlap with the empty displayed value.
51+
* The label should either be hidden or forced to a shrunk state.
52+
* @default false
53+
*/
54+
displayEmpty?: boolean;
55+
/**
56+
* The icon that displays the arrow.
57+
* @default ArrowDropDownIcon
58+
*/
59+
IconComponent?: React.ElementType;
60+
/**
61+
* The `id` of the wrapper element or the `select` element when `native`.
62+
*/
63+
id?: string;
64+
/**
65+
* An `Input` element; does not have to be a material-ui specific `Input`.
66+
*/
67+
input?: React.ReactElement<any, any>;
68+
/**
69+
* [Attributes](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#Attributes) applied to the `input` element.
70+
* When `native` is `true`, the attributes are applied on the `select` element.
71+
*/
72+
inputProps?: InputProps['inputProps'];
73+
/**
74+
* See [OutlinedInput#label](/material-ui/api/outlined-input/#props)
75+
*/
76+
label?: React.ReactNode;
77+
/**
78+
* The ID of an element that acts as an additional label. The Select will
79+
* be labelled by the additional label and the selected value.
80+
*/
81+
labelId?: string;
82+
/**
83+
* Props applied to the [`Menu`](/material-ui/api/menu/) element.
84+
*/
85+
MenuProps?: Partial<MenuProps>;
86+
/**
87+
* If `true`, `value` must be an array and the menu will support multiple selections.
88+
* @default false
89+
*/
90+
multiple?: boolean;
91+
/**
92+
* If `true`, the component uses a native `select` element.
93+
* @default false
94+
*/
95+
native?: boolean;
96+
/**
97+
* Callback fired when a menu item is selected.
98+
*
99+
* @param {SelectChangeEvent<Value>} event The event source of the callback.
100+
* You can pull out the new value by accessing `event.target.value` (any).
101+
* **Warning**: This is a generic event, not a change event, unless the change event is caused by browser autofill.
102+
* @param {object} [child] The react element that was selected when `native` is `false` (default).
103+
*/
104+
onChange?: SelectInputProps<Value>['onChange'];
105+
/**
106+
* Callback fired when the component requests to be closed.
107+
* Use it in either controlled (see the `open` prop), or uncontrolled mode (to detect when the Select collapses).
108+
*
109+
* @param {object} event The event source of the callback.
110+
*/
111+
onClose?: (event: React.SyntheticEvent) => void;
112+
/**
113+
* Callback fired when the component requests to be opened.
114+
* Use it in either controlled (see the `open` prop), or uncontrolled mode (to detect when the Select expands).
115+
*
116+
* @param {object} event The event source of the callback.
117+
*/
118+
onOpen?: (event: React.SyntheticEvent) => void;
119+
/**
120+
* If `true`, the component is shown.
121+
* You can only use it when the `native` prop is `false` (default).
122+
*/
123+
open?: boolean;
124+
/**
125+
* Render the selected value.
126+
* You can only use it when the `native` prop is `false` (default).
127+
*
128+
* @param {any} value The `value` provided to the component.
129+
* @returns {ReactNode}
130+
*/
131+
renderValue?: (value: Value) => React.ReactNode;
132+
/**
133+
* Props applied to the clickable div element.
134+
*/
135+
SelectDisplayProps?: React.HTMLAttributes<HTMLDivElement>;
136+
/**
137+
* The system prop that allows defining system overrides as well as additional CSS styles.
138+
*/
139+
sx?: SxProps<Theme>;
140+
/**
141+
* The `input` value. Providing an empty string will select no options.
142+
* Set to an empty string `''` if you don't want any of the available options to be selected.
143+
*
144+
* If the value is an object it must have reference equality with the option in order to be selected.
145+
* If the value is not an object, the string representation must match with the string representation of the option in order to be selected.
146+
*/
147+
value?: Value | '';
148+
/**
149+
* The variant to use.
150+
* @default 'outlined'
151+
*/
152+
variant?: 'standard' | 'outlined' | 'filled';
153+
}
154+
155+
/**
156+
*
157+
* Demos:
158+
*
159+
* - [Select](https://mui.com/material-ui/react-select/)
160+
*
161+
* API:
162+
*
163+
* - [Select API](https://mui.com/material-ui/api/select/)
164+
* - inherits [OutlinedInput API](https://mui.com/material-ui/api/outlined-input/)
165+
*/
166+
declare const Select: (<Value>(props: SelectProps<Value>) => JSX.Element) & {
167+
muiName: string;
168+
};
169+
170+
export default Select;

0 commit comments

Comments
 (0)