1 | import * as React from 'react';
|
2 | import { SxProps } from '@mui/system';
|
3 | import { OverridableStringUnion } from '@mui/types';
|
4 | import { Theme } from '../styles';
|
5 | import { InternalStandardProps as StandardProps } from '..';
|
6 | import { InputBaseClasses } from './inputBaseClasses';
|
7 |
|
8 | export interface InputBasePropsSizeOverrides {}
|
9 |
|
10 | export interface InputBasePropsColorOverrides {}
|
11 |
|
12 | export interface InputBaseComponentsPropsOverrides {}
|
13 |
|
14 | export interface InputBaseProps
|
15 | extends StandardProps<
|
16 | React.HTMLAttributes<HTMLDivElement>,
|
17 | /*
|
18 | * `onBlur`, `onChange`, `onFocus`, `onInvalid`, `onKeyDown`, `onKeyUp` are applied to the inner `InputComponent`,
|
19 | * which by default is an input or textarea. Since these handlers differ from the
|
20 | * ones inherited by `React.HTMLAttributes<HTMLDivElement>` we need to omit them.
|
21 | */
|
22 | | 'children'
|
23 | | 'defaultValue'
|
24 | | 'onBlur'
|
25 | | 'onChange'
|
26 | | 'onFocus'
|
27 | | 'onInvalid'
|
28 | | 'onKeyDown'
|
29 | | 'onKeyUp'
|
30 | > {
|
31 | 'aria-describedby'?: string;
|
32 | /**
|
33 | * This prop helps users to fill forms faster, especially on mobile devices.
|
34 | * The name can be confusing, as it's more like an autofill.
|
35 | * You can learn more about it [following the specification](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill).
|
36 | */
|
37 | autoComplete?: string;
|
38 | /**
|
39 | * If `true`, the `input` element is focused during the first mount.
|
40 | */
|
41 | autoFocus?: boolean;
|
42 | /**
|
43 | * Override or extend the styles applied to the component.
|
44 | */
|
45 | classes?: Partial<InputBaseClasses>;
|
46 | /**
|
47 | * The color of the component.
|
48 | * It supports both default and custom theme colors, which can be added as shown in the
|
49 | * [palette customization guide](https://mui.com/material-ui/customization/palette/#custom-colors).
|
50 | * The prop defaults to the value (`'primary'`) inherited from the parent FormControl component.
|
51 | */
|
52 | color?: OverridableStringUnion<
|
53 | 'primary' | 'secondary' | 'error' | 'info' | 'success' | 'warning',
|
54 | InputBasePropsColorOverrides
|
55 | >;
|
56 | /**
|
57 | * The components used for each slot inside.
|
58 | *
|
59 | * @deprecated use the `slots` prop instead. This prop will be removed in v7. See [Migrating from deprecated APIs](https://mui.com/material-ui/migration/migrating-from-deprecated-apis/) for more details.
|
60 | *
|
61 | * @default {}
|
62 | */
|
63 | components?: {
|
64 | Root?: React.ElementType;
|
65 | Input?: React.ElementType;
|
66 | };
|
67 | /**
|
68 | * The extra props for the slot components.
|
69 | * You can override the existing props or add new ones.
|
70 | *
|
71 | * @deprecated use the `slotProps` prop instead. This prop will be removed in v7. See [Migrating from deprecated APIs](https://mui.com/material-ui/migration/migrating-from-deprecated-apis/) for more details.
|
72 | *
|
73 | * @default {}
|
74 | */
|
75 | componentsProps?: {
|
76 | root?: React.HTMLAttributes<HTMLDivElement> & InputBaseComponentsPropsOverrides;
|
77 | input?: React.InputHTMLAttributes<HTMLInputElement> & InputBaseComponentsPropsOverrides;
|
78 | };
|
79 | /**
|
80 | * The default value. Use when the component is not controlled.
|
81 | */
|
82 | defaultValue?: unknown;
|
83 | /**
|
84 | * If `true`, the component is disabled.
|
85 | * The prop defaults to the value (`false`) inherited from the parent FormControl component.
|
86 | */
|
87 | disabled?: boolean;
|
88 | /**
|
89 | * If `true`, GlobalStyles for the auto-fill keyframes will not be injected/removed on mount/unmount. Make sure to inject them at the top of your application.
|
90 | * This option is intended to help with boosting the initial rendering performance if you are loading a big amount of Input components at once.
|
91 | * @default false
|
92 | */
|
93 | disableInjectingGlobalStyles?: boolean;
|
94 | /**
|
95 | * End `InputAdornment` for this component.
|
96 | */
|
97 | endAdornment?: React.ReactNode;
|
98 | /**
|
99 | * If `true`, the `input` will indicate an error.
|
100 | * The prop defaults to the value (`false`) inherited from the parent FormControl component.
|
101 | */
|
102 | error?: boolean;
|
103 | /**
|
104 | * If `true`, the `input` will take up the full width of its container.
|
105 | * @default false
|
106 | */
|
107 | fullWidth?: boolean;
|
108 | /**
|
109 | * The id of the `input` element.
|
110 | */
|
111 | id?: string;
|
112 | /**
|
113 | * The component used for the `input` element.
|
114 | * Either a string to use a HTML element or a component.
|
115 | * @default 'input'
|
116 | */
|
117 | inputComponent?: React.ElementType<InputBaseComponentProps>;
|
118 | /**
|
119 | * [Attributes](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#Attributes) applied to the `input` element.
|
120 | * @default {}
|
121 | */
|
122 | inputProps?: InputBaseComponentProps;
|
123 | /**
|
124 | * Pass a ref to the `input` element.
|
125 | */
|
126 | inputRef?: React.Ref<any>;
|
127 | /**
|
128 | * If `dense`, will adjust vertical spacing. This is normally obtained via context from
|
129 | * FormControl.
|
130 | * The prop defaults to the value (`'none'`) inherited from the parent FormControl component.
|
131 | */
|
132 | margin?: 'dense' | 'none';
|
133 | /**
|
134 | * If `true`, a [TextareaAutosize](https://mui.com/material-ui/react-textarea-autosize/) element is rendered.
|
135 | * @default false
|
136 | */
|
137 | multiline?: boolean;
|
138 | /**
|
139 | * Name attribute of the `input` element.
|
140 | */
|
141 | name?: string;
|
142 | /**
|
143 | * Callback fired when the `input` is blurred.
|
144 | *
|
145 | * Notice that the first argument (event) might be undefined.
|
146 | */
|
147 | onBlur?: React.FocusEventHandler<HTMLInputElement | HTMLTextAreaElement>;
|
148 | /**
|
149 | * Callback fired when the value is changed.
|
150 | *
|
151 | * @param {React.ChangeEvent<HTMLTextAreaElement | HTMLInputElement>} event The event source of the callback.
|
152 | * You can pull out the new value by accessing `event.target.value` (string).
|
153 | */
|
154 | onChange?: React.ChangeEventHandler<HTMLTextAreaElement | HTMLInputElement>;
|
155 | onFocus?: React.FocusEventHandler<HTMLInputElement | HTMLTextAreaElement>;
|
156 | onKeyDown?: React.KeyboardEventHandler<HTMLTextAreaElement | HTMLInputElement>;
|
157 | onKeyUp?: React.KeyboardEventHandler<HTMLTextAreaElement | HTMLInputElement>;
|
158 | /**
|
159 | * Callback fired when the `input` doesn't satisfy its constraints.
|
160 | */
|
161 | onInvalid?: React.FormEventHandler<HTMLInputElement | HTMLTextAreaElement>;
|
162 | /**
|
163 | * The short hint displayed in the `input` before the user enters a value.
|
164 | */
|
165 | placeholder?: string;
|
166 | /**
|
167 | * It prevents the user from changing the value of the field
|
168 | * (not from interacting with the field).
|
169 | */
|
170 | readOnly?: boolean;
|
171 | /**
|
172 | * If `true`, the `input` element is required.
|
173 | * The prop defaults to the value (`false`) inherited from the parent FormControl component.
|
174 | */
|
175 | required?: boolean;
|
176 | renderSuffix?: (state: {
|
177 | disabled?: boolean;
|
178 | error?: boolean;
|
179 | filled?: boolean;
|
180 | focused?: boolean;
|
181 | margin?: 'dense' | 'none' | 'normal';
|
182 | required?: boolean;
|
183 | startAdornment?: React.ReactNode;
|
184 | }) => React.ReactNode;
|
185 | /**
|
186 | * Number of rows to display when multiline option is set to true.
|
187 | */
|
188 | rows?: string | number;
|
189 | /**
|
190 | * Maximum number of rows to display when multiline option is set to true.
|
191 | */
|
192 | maxRows?: string | number;
|
193 | /**
|
194 | * Minimum number of rows to display when multiline option is set to true.
|
195 | */
|
196 | minRows?: string | number;
|
197 | /**
|
198 | * The size of the component.
|
199 | */
|
200 | size?: OverridableStringUnion<'small' | 'medium', InputBasePropsSizeOverrides>;
|
201 | /**
|
202 | * The extra props for the slot components.
|
203 | * You can override the existing props or add new ones.
|
204 | *
|
205 | * This prop is an alias for the `componentsProps` prop, which will be deprecated in the future.
|
206 | *
|
207 | * @default {}
|
208 | */
|
209 | slotProps?: {
|
210 | root?: React.HTMLAttributes<HTMLDivElement> &
|
211 | InputBaseComponentsPropsOverrides & { sx?: SxProps<Theme> };
|
212 | input?: React.InputHTMLAttributes<HTMLInputElement> &
|
213 | InputBaseComponentsPropsOverrides & { sx?: SxProps<Theme> };
|
214 | };
|
215 | /**
|
216 | * The components used for each slot inside.
|
217 | *
|
218 | * This prop is an alias for the `components` prop, which will be deprecated in the future.
|
219 | *
|
220 | * @default {}
|
221 | */
|
222 | slots?: {
|
223 | root?: React.ElementType;
|
224 | input?: React.ElementType;
|
225 | };
|
226 | /**
|
227 | * Start `InputAdornment` for this component.
|
228 | */
|
229 | startAdornment?: React.ReactNode;
|
230 | /**
|
231 | * The system prop that allows defining system overrides as well as additional CSS styles.
|
232 | */
|
233 | sx?: SxProps<Theme>;
|
234 | /**
|
235 | * Type of the `input` element. It should be [a valid HTML5 input type](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#Form_%3Cinput%3E_types).
|
236 | * @default 'text'
|
237 | */
|
238 | type?: string;
|
239 | /**
|
240 | * The value of the `input` element, required for a controlled component.
|
241 | */
|
242 | value?: unknown;
|
243 | }
|
244 |
|
245 | export interface InputBaseComponentProps
|
246 | extends React.HTMLAttributes<HTMLInputElement | HTMLTextAreaElement> {
|
247 | // Accommodate arbitrary additional props coming from the `inputProps` prop
|
248 | [arbitrary: string]: any;
|
249 | }
|
250 |
|
251 | /**
|
252 | * `InputBase` contains as few styles as possible.
|
253 | * It aims to be a simple building block for creating an input.
|
254 | * It contains a load of style reset and some state logic.
|
255 | *
|
256 | * Demos:
|
257 | *
|
258 | * - [Text Field](https://mui.com/material-ui/react-text-field/)
|
259 | *
|
260 | * API:
|
261 | *
|
262 | * - [InputBase API](https://mui.com/material-ui/api/input-base/)
|
263 | */
|
264 | export default function InputBase(props: InputBaseProps): React.JSX.Element;
|