import * as React from 'react'; import { InternalStandardProps as StandardProps, PropTypes } from '..'; import { FormControlProps } from '../FormControl'; import { FormHelperTextProps } from '../FormHelperText'; import { InputBaseProps } from '../InputBase'; import { InputProps as StandardInputProps } from '../Input'; import { FilledInputProps } from '../FilledInput'; import { OutlinedInputProps } from '../OutlinedInput'; import { InputLabelProps } from '../InputLabel'; import { SelectProps } from '../Select'; export interface BaseTextFieldProps extends StandardProps< FormControlProps, // event handlers are declared on derived interfaces 'onChange' | 'onBlur' | 'onFocus' | 'defaultValue' > { /** * This prop helps users to fill forms faster, especially on mobile devices. * The name can be confusing, as it's more like an autofill. * You can learn more about it [following the specification](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill). */ autoComplete?: string; /** * If `true`, the `input` element will be focused during the first mount. * @default false */ autoFocus?: boolean; /** * @ignore */ children?: React.ReactNode; /** * Override or extend the styles applied to the component. */ classes?: { /** Styles applied to the root element. */ root?: string; }; /** * The color of the component. It supports those theme colors that make sense for this component. * @default 'primary' */ color?: 'primary' | 'secondary'; /** * The default value of the `input` element. */ defaultValue?: unknown; /** * If `true`, the `input` element will be disabled. * @default false */ disabled?: boolean; /** * If `true`, the label will be displayed in an error state. * @default false */ error?: boolean; /** * Props applied to the [`FormHelperText`](/api/form-helper-text/) element. */ FormHelperTextProps?: Partial; /** * If `true`, the input will take up the full width of its container. * @default false */ fullWidth?: boolean; /** * The helper text content. */ helperText?: React.ReactNode; /** * The id of the `input` element. * Use this prop to make `label` and `helperText` accessible for screen readers. */ id?: string; /** * Props applied to the [`InputLabel`](/api/input-label/) element. */ InputLabelProps?: Partial; /** * [Attributes](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#Attributes) applied to the `input` element. */ inputProps?: InputBaseProps['inputProps']; /** * Pass a ref to the `input` element. */ inputRef?: React.Ref; /** * The label content. */ label?: React.ReactNode; /** * If `dense` or `normal`, will adjust vertical spacing of this and contained components. */ margin?: PropTypes.Margin; /** * If `true`, a textarea element will be rendered instead of an input. * @default false */ multiline?: boolean; /** * Name attribute of the `input` element. */ name?: string; onBlur?: InputBaseProps['onBlur']; onFocus?: StandardInputProps['onFocus']; /** * The short hint displayed in the input before the user enters a value. */ placeholder?: string; /** * If `true`, the label is displayed as required and the `input` element will be required. * @default false */ required?: boolean; /** * Number of rows to display when multiline option is set to true. */ rows?: string | number; /** * Maximum number of rows to display when multiline option is set to true. */ maxRows?: string | number; /** * Minimum number of rows to display when multiline option is set to true. */ minRows?: string | number; /** * Render a [`Select`](/api/select/) element while passing the Input element to `Select` as `input` parameter. * If this option is set you must pass the options of the select as children. * @default false */ select?: boolean; /** * Props applied to the [`Select`](/api/select/) element. */ SelectProps?: Partial; /** * The size of the text field. */ size?: 'small' | 'medium'; /** * 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). */ type?: React.InputHTMLAttributes['type']; /** * The value of the `input` element, required for a controlled component. */ value?: unknown; } export interface StandardTextFieldProps extends BaseTextFieldProps { /** * Callback fired when the value is changed. * * @param {object} event The event source of the callback. * You can pull out the new value by accessing `event.target.value` (string). */ onChange?: StandardInputProps['onChange']; /** * The variant to use. * @default 'standard' */ variant?: 'standard'; /** * Props applied to the Input element. * It will be a [`FilledInput`](/api/filled-input/), * [`OutlinedInput`](/api/outlined-input/) or [`Input`](/api/input/) * component depending on the `variant` prop value. */ InputProps?: Partial; } export interface FilledTextFieldProps extends BaseTextFieldProps { /** * Callback fired when the value is changed. * * @param {object} event The event source of the callback. * You can pull out the new value by accessing `event.target.value` (string). */ onChange?: FilledInputProps['onChange']; /** * The variant to use. * @default 'standard' */ variant: 'filled'; /** * Props applied to the Input element. * It will be a [`FilledInput`](/api/filled-input/), * [`OutlinedInput`](/api/outlined-input/) or [`Input`](/api/input/) * component depending on the `variant` prop value. */ InputProps?: Partial; } export interface OutlinedTextFieldProps extends BaseTextFieldProps { /** * Callback fired when the value is changed. * * @param {object} event The event source of the callback. * You can pull out the new value by accessing `event.target.value` (string). */ onChange?: OutlinedInputProps['onChange']; /** * The variant to use. * @default 'standard' */ variant: 'outlined'; /** * Props applied to the Input element. * It will be a [`FilledInput`](/api/filled-input/), * [`OutlinedInput`](/api/outlined-input/) or [`Input`](/api/input/) * component depending on the `variant` prop value. */ InputProps?: Partial; } export type TextFieldProps = StandardTextFieldProps | FilledTextFieldProps | OutlinedTextFieldProps; export type TextFieldClassKey = keyof NonNullable; /** * The `TextField` is a convenience wrapper for the most common cases (80%). * It cannot be all things to all people, otherwise the API would grow out of control. * * ## Advanced Configuration * * It's important to understand that the text field is a simple abstraction * on top of the following components: * * * [FormControl](https://material-ui.com/api/form-control/) * * [InputLabel](https://material-ui.com/api/input-label/) * * [FilledInput](https://material-ui.com/api/filled-input/) * * [OutlinedInput](https://material-ui.com/api/outlined-input/) * * [Input](https://material-ui.com/api/input/) * * [FormHelperText](https://material-ui.com/api/form-helper-text/) * * If you wish to alter the props applied to the `input` element, you can do so as follows: * * ```jsx * const inputProps = { * step: 300, * }; * * return ; * ``` * * For advanced cases, please look at the source of TextField by clicking on the * "Edit this page" button above. Consider either: * * * using the upper case props for passing values directly to the components * * using the underlying components directly as shown in the demos * Demos: * * - [Autocomplete](https://material-ui.com/components/autocomplete/) * - [Pickers](https://material-ui.com/components/pickers/) * - [Text Fields](https://material-ui.com/components/text-fields/) * * API: * * - [TextField API](https://material-ui.com/api/text-field/) * - inherits [FormControl API](https://material-ui.com/api/form-control/) */ export default function TextField(props: TextFieldProps): JSX.Element;