UNPKG

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