import { Story, Canvas, ArgsTable } from '@storybook/addon-docs'; import { Input } from './input'; # Input `Input` lets user enter a text data. It’s a light-weighted borderless input used inside of custom inputs. See [TextField](/docs/components-componentlibrary-textfield--default-story#textfield) for common text input. ## Props The `Input` accepts all props below as well as all [Box](/docs/components-ui-box--default-story#props) component props ### Type Use the `type` prop to change the type of input. Possible types include: - `INPUT_TYPES.TEXT` - `INPUT_TYPES.NUMBER` - `INPUT_TYPES.PASSWORD` - `INPUT_TYPES.SEARCH` Defaults to `INPUT_TYPES.TEXT`. ```jsx import { Input, INPUT_TYPES } from '../../component-library'; ``` ### Ref Use the `ref` prop to access the ref of the `` html element of `Input`. This is useful for focusing the input from a button or other component. ```jsx import { Button, Input } from '../../component-library'; const inputRef = useRef(null); const [value, setValue] = useState(''); const handleOnClick = () => { inputRef.current.focus(); }; const handleOnChange = (e) => { setValue(e.target.value); }; ``` ### Auto Complete Use the `autoComplete` prop to set the autocomplete html attribute. It allows the browser to predict the value based on earlier typed values. ```jsx import { Input } from '../../component-library'; ; ``` ### Auto Focus Use the `autoFocus` prop to focus the `Input` during the first mount To view story see [Canvas tab](/story/components-componentlibrary-input--auto-focus). Removing it from docs because created annoying reading experience 😁 ```jsx import { Input } from '../../component-library'; ; ``` ### Default Value Use the `defaultValue` prop to set the default value of the `Input`. Used for uncontrolled inputs. ```jsx import { Input } from '../../component-library'; ; ``` ### Disabled Use the `disabled` prop to set the disabled state of the `Input` ```jsx import { Input } from '../../component-library'; ; ``` ### Error Use the `error` prop to set `aria-invalid="true"`. This helps with screen readers for accessibility. There is no visual indicator for `error` this should be handled in the parent component. ```jsx import { Input } from '../../component-library'; ; ``` ### Max Length Use the `maxLength` prop to set the maximum allowed input characters for the `Input` ```jsx import { Input } from '../../component-library'; ; ``` ### Read Only Use the `readOnly` prop to set the `Input` to read only ```jsx import { Input } from '../../component-library'; ; ``` ### Required Use the `required` prop to set the html `required` attribute used by the browser api. There is no visual indicator for `required` this should be handled in the parent component. ```jsx import { Input } from '../../component-library'; // No visual indicator. Used by the browser api ; ``` ### Disable Style States Use the `disableStyleStates` to remove disabled and focus styles #### IMPORTANT NOTE This sets the CSS to `outline: none` so ensure there is a proper fallback to enable accessibility for keyboard only and vision impaired users. Check `TextField` source code to see how it is done properly. ```jsx import { Input } from '../../component-library'; ; ``` ### Text Variant Use the `textVariant` and `TextVariant` enum to change the font size and style of the input #### IMPORTANT NOTE This should RARELY be used but it is available for custom inputs that require larger text ```jsx import { TextVariant } from '../../../helpers/constants/design-system'; import { Input } from '../../component-library'; ```