UNPKG

@mui/material

Version:

Quickly build beautiful React apps. MUI is a simple and customizable component library to build faster, beautiful, and more accessible React applications. Follow your own design system, or start with Material Design.

221 lines (214 loc) 7.49 kB
import * as React from 'react'; import { SxProps } from '@mui/system'; import { OverridableStringUnion } from '@mui/types'; import { Theme } from '../styles'; import { InternalStandardProps as StandardProps } from '..'; import { InputBaseClasses } from './inputBaseClasses'; export interface InputBasePropsSizeOverrides {} export interface InputBasePropsColorOverrides {} export interface InputBaseComponentsPropsOverrides {} export interface InputBaseProps extends StandardProps< React.HTMLAttributes<HTMLDivElement>, /* * `onChange`, `onKeyUp`, `onKeyDown`, `onBlur`, `onFocus` are applied to the inner `InputComponent`, * which by default is an input or textarea. Since these handlers differ from the * ones inherited by `React.HTMLAttributes<HTMLDivElement>` we need to omit them. */ 'children' | 'onChange' | 'onKeyUp' | 'onKeyDown' | 'onBlur' | 'onFocus' | 'defaultValue' > { 'aria-describedby'?: string; /** * 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 is focused during the first mount. */ autoFocus?: boolean; /** * Override or extend the styles applied to the component. */ classes?: Partial<InputBaseClasses>; /** * The color of the component. It supports those theme colors that make sense for this component. * The prop defaults to the value (`'primary'`) inherited from the parent FormControl component. */ color?: OverridableStringUnion< 'primary' | 'secondary' | 'error' | 'info' | 'success' | 'warning', InputBasePropsColorOverrides >; /** * The components used for each slot inside the InputBase. * Either a string to use a HTML element or a component. * @default {} */ components?: { Root?: React.ElementType; Input?: React.ElementType; }; /** * The props used for each slot inside the Input. * @default {} */ componentsProps?: { root?: React.HTMLAttributes<HTMLDivElement> & InputBaseComponentsPropsOverrides; input?: React.InputHTMLAttributes<HTMLInputElement> & InputBaseComponentsPropsOverrides; }; /** * The default value. Use when the component is not controlled. */ defaultValue?: unknown; /** * If `true`, the component is disabled. * The prop defaults to the value (`false`) inherited from the parent FormControl component. */ disabled?: boolean; /** * 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. * This option is intended to help with boosting the initial rendering performance if you are loading a big amount of Input components at once. * @default false */ disableInjectingGlobalStyles?: boolean; /** * End `InputAdornment` for this component. */ endAdornment?: React.ReactNode; /** * If `true`, the `input` will indicate an error. * The prop defaults to the value (`false`) inherited from the parent FormControl component. */ error?: boolean; /** * If `true`, the `input` will take up the full width of its container. * @default false */ fullWidth?: boolean; /** * The id of the `input` element. */ id?: string; /** * The component used for the `input` element. * Either a string to use a HTML element or a component. * @default 'input' */ inputComponent?: React.ElementType<InputBaseComponentProps>; /** * [Attributes](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#Attributes) applied to the `input` element. * @default {} */ inputProps?: InputBaseComponentProps; /** * Pass a ref to the `input` element. */ inputRef?: React.Ref<any>; /** * If `dense`, will adjust vertical spacing. This is normally obtained via context from * FormControl. * The prop defaults to the value (`'none'`) inherited from the parent FormControl component. */ margin?: 'dense' | 'none'; /** * If `true`, a `textarea` element is rendered. * @default false */ multiline?: boolean; /** * Name attribute of the `input` element. */ name?: string; /** * Callback fired when the `input` is blurred. * * Notice that the first argument (event) might be undefined. */ onBlur?: React.FocusEventHandler<HTMLInputElement | HTMLTextAreaElement>; /** * Callback fired when the value is changed. * * @param {React.ChangeEvent<HTMLTextAreaElement | HTMLInputElement>} event The event source of the callback. * You can pull out the new value by accessing `event.target.value` (string). */ onChange?: React.ChangeEventHandler<HTMLTextAreaElement | HTMLInputElement>; onFocus?: React.FocusEventHandler<HTMLInputElement | HTMLTextAreaElement>; onKeyDown?: React.KeyboardEventHandler<HTMLTextAreaElement | HTMLInputElement>; onKeyUp?: React.KeyboardEventHandler<HTMLTextAreaElement | HTMLInputElement>; /** * The short hint displayed in the `input` before the user enters a value. */ placeholder?: string; /** * It prevents the user from changing the value of the field * (not from interacting with the field). */ readOnly?: boolean; /** * If `true`, the `input` element is required. * The prop defaults to the value (`false`) inherited from the parent FormControl component. */ required?: boolean; renderSuffix?: (state: { disabled?: boolean; error?: boolean; filled?: boolean; focused?: boolean; margin?: 'dense' | 'none' | 'normal'; required?: boolean; startAdornment?: React.ReactNode; }) => React.ReactNode; /** * 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; /** * The size of the component. */ size?: OverridableStringUnion<'small' | 'medium', InputBasePropsSizeOverrides>; /** * Start `InputAdornment` for this component. */ startAdornment?: React.ReactNode; /** * The system prop that allows defining system overrides as well as additional CSS styles. */ sx?: SxProps<Theme>; /** * 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). * @default 'text' */ type?: string; /** * The value of the `input` element, required for a controlled component. */ value?: unknown; } export interface InputBaseComponentProps extends React.HTMLAttributes<HTMLInputElement | HTMLTextAreaElement> { // Accommodate arbitrary additional props coming from the `inputProps` prop [arbitrary: string]: any; } /** * `InputBase` contains as few styles as possible. * It aims to be a simple building block for creating an input. * It contains a load of style reset and some state logic. * * Demos: * * - [Text Fields](https://mui.com/components/text-fields/) * * API: * * - [InputBase API](https://mui.com/api/input-base/) */ export default function InputBase(props: InputBaseProps): JSX.Element;