--- title: Input description: "`Input` is a component used to obtain text input from the user." links: - style: https://github.com/yamada-ui/yamada-ui/tree/main/packages/react/src/components/input/input.style.ts - source: https://github.com/yamada-ui/yamada-ui/tree/main/packages/react/src/components/input - storybook: https://yamada-ui.github.io/yamada-ui?path=/story/components-input--basic --- ```tsx ``` ## Usage ```tsx import { Input, InputGroup } from "@yamada-ui/react" ``` ```tsx import { Input, InputGroup } from "@/components/ui" ``` ```tsx import { Input, InputGroup } from "@workspaces/ui" ``` ```tsx ``` ```tsx ``` ### Change Variant ```tsx {(variant) => ( )} ``` ### Change Size ```tsx preview {(size) => } ``` ### Change Color Scheme ```tsx {(colorScheme) => ( )} ``` ### Disable To disable the input, set `disabled` to `true`. ```tsx {(variant) => ( )} ``` ### Read-Only To read-only, set `readOnly` to `true`. ```tsx {(variant) => ( )} ``` ### Invalid To make invalid, set `invalid` to `true`. ```tsx {(variant) => ( )} ``` ### Add Addons To add addons, wrap the `Input` in `InputGroup` and use `InputGroup.Addon`. ```tsx {(variant) => ( https:// .com )} ``` ### Add Elements To add elements, wrap the `Input` in `InputGroup` and use `InputGroup.Element`. ```tsx {(variant) => ( )} ``` ### Change Type To change the type, set `type` to the [type](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#input_types). ```tsx ``` ### Change Border Color To change the border color, set `focusBorderColor` or `errorBorderColor` to the color. ```tsx ``` ### Change Placeholder Color To change the placeholder color, set `_placeholder` to the value. ```tsx ``` ### Floating Label ```tsx Email ``` ### Control ```tsx const [value, setValue] = useState("オッス!オラ悟空!") return setValue(ev.target.value)} /> ``` ## Uses Components & Hooks ## Used By Components & Hooks ## Props ### Input | Prop | Default | Type | Description | | ------------------ | ----------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------- | | `as` | - | `As` | The HTML element to render. | | `asChild` | - | `boolean` | Merges its props onto its immediate child. | | `css` | - | `CSSObject \| CSSObject[]` | The CSS object. | | `colorScheme` | - | `"amber" \| "black" \| "blackAlpha" \| "blue" \| "cyan" \| "danger" \| "emerald" \| "error" \| "flashy" \| "fuchsia" ...` | Set color scheme variables. | | `size` | `"md"` | `"2xl" \| "lg" \| "md" \| "sm" \| "xl" \| "xs"` | The size of the component. | | `variant` | `"outline"` | `"filled" \| "flushed" \| "outline" \| "plain"` | The variant of the component. | | `errorBorderColor` | - | `"-moz-initial" \| "AccentColor" \| "AccentColorText" \| "ActiveBorder" \| "ActiveCaption" \| "ActiveText" \| "aliceblue" \| "amber.100" \| "amber.200" \| "amber.300" ...` | The border color when the input is invalid. | | `focusBorderColor` | - | `"-moz-initial" \| "AccentColor" \| "AccentColorText" \| "ActiveBorder" \| "ActiveCaption" \| "ActiveText" \| "aliceblue" \| "amber.100" \| "amber.200" \| "amber.300" ...` | The border color when the input is focused. | | `htmlSize` | - | `number` | The native HTML `size` attribute to be passed to the `input`. | | `invalid` | `false` | `boolean` | If `true`, the field will be invalid. | ### InputGroup.Root | Prop | Default | Type | Description | | ------------------ | ----------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------- | | `as` | - | `As` | The HTML element to render. | | `asChild` | - | `boolean` | Merges its props onto its immediate child. | | `css` | - | `CSSObject \| CSSObject[]` | The CSS object. | | `colorScheme` | - | `"amber" \| "black" \| "blackAlpha" \| "blue" \| "cyan" \| "danger" \| "emerald" \| "error" \| "flashy" \| "fuchsia" ...` | Set color scheme variables. | | `size` | `"md"` | `"2xl" \| "lg" \| "md" \| "sm" \| "xl" \| "xs"` | The size of the component. | | `variant` | `"outline"` | `"filled" \| "flushed" \| "outline" \| "plain"` | The variant of the component. | | `align` | - | `"-moz-initial" \| "anchor-center" \| "baseline" \| "center" \| "end" \| "flex-end" \| "flex-start" \| "inherit" \| "initial" \| "normal" ...` | The CSS `align-items` property. | | `basis` | - | `"-moz-fit-content" \| "-moz-initial" \| "-moz-max-content" \| "-moz-min-content" \| "-webkit-auto" \| "0.5" \| "1.5" \| "1" \| "1/12" \| "1/2" ...` | The CSS `flex-basis` property. | | `direction` | - | `"-moz-initial" \| "column-reverse" \| "column" \| "inherit" \| "initial" \| "revert-layer" \| "revert" \| "row-reverse" \| "row" \| "unset" ...` | The CSS `flex-direction` property. | | `disabled` | `false` | `boolean` | If `true`, the field will be disabled. | | `errorBorderColor` | - | `"-moz-initial" \| "AccentColor" \| "AccentColorText" \| "ActiveBorder" \| "ActiveCaption" \| "ActiveText" \| "aliceblue" \| "amber.100" \| "amber.200" \| "amber.300" ...` | The border color when the input is invalid. | | `focusBorderColor` | - | `"-moz-initial" \| "AccentColor" \| "AccentColorText" \| "ActiveBorder" \| "ActiveCaption" \| "ActiveText" \| "aliceblue" \| "amber.100" \| "amber.200" \| "amber.300" ...` | The border color when the input is focused. | | `invalid` | `false` | `boolean` | If `true`, the field will be invalid. | | `justify` | - | `"-moz-initial" \| "center" \| "end" \| "flex-end" \| "flex-start" \| "inherit" \| "initial" \| "left" \| "normal" \| "revert-layer" ...` | The CSS `justify-content` property. | | `readOnly` | `false` | `boolean` | If `true`, the field will be readonly. | | `required` | `false` | `boolean` | If `true`, the field will be required. | | `shrink` | - | `"-moz-initial" \| "inherit" \| "initial" \| "revert-layer" \| "revert" \| "unset" \| number & {} ...` | The CSS `flex-shrink` property. | | `wrap` | - | `"-moz-initial" \| "inherit" \| "initial" \| "nowrap" \| "revert-layer" \| "revert" \| "unset" \| "wrap-reverse" \| "wrap" ...` | The CSS `flex-wrap` property. | ### InputGroup.Addon | Prop | Default | Type | Description | | ------------------ | ----------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------- | | `as` | - | `As` | The HTML element to render. | | `asChild` | - | `boolean` | Merges its props onto its immediate child. | | `css` | - | `CSSObject \| CSSObject[]` | The CSS object. | | `colorScheme` | - | `"amber" \| "black" \| "blackAlpha" \| "blue" \| "cyan" \| "danger" \| "emerald" \| "error" \| "flashy" \| "fuchsia" ...` | Set color scheme variables. | | `size` | `"md"` | `"2xl" \| "lg" \| "md" \| "sm" \| "xl" \| "xs"` | The size of the component. | | `variant` | `"outline"` | `"filled" \| "flushed" \| "outline" \| "plain"` | The variant of the component. | | `errorBorderColor` | - | `"-moz-initial" \| "AccentColor" \| "AccentColorText" \| "ActiveBorder" \| "ActiveCaption" \| "ActiveText" \| "aliceblue" \| "amber.100" \| "amber.200" \| "amber.300" ...` | The border color when the input is invalid. | | `focusBorderColor` | - | `"-moz-initial" \| "AccentColor" \| "AccentColorText" \| "ActiveBorder" \| "ActiveCaption" \| "ActiveText" \| "aliceblue" \| "amber.100" \| "amber.200" \| "amber.300" ...` | The border color when the input is focused. | ### InputGroup.Element | Prop | Default | Type | Description | | ------------------ | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------- | | `as` | - | `As` | The HTML element to render. | | `asChild` | - | `boolean` | Merges its props onto its immediate child. | | `css` | - | `CSSObject \| CSSObject[]` | The CSS object. | | `colorScheme` | - | `"amber" \| "black" \| "blackAlpha" \| "blue" \| "cyan" \| "danger" \| "emerald" \| "error" \| "flashy" \| "fuchsia" ...` | Set color scheme variables. | | `errorBorderColor` | - | `"-moz-initial" \| "AccentColor" \| "AccentColorText" \| "ActiveBorder" \| "ActiveCaption" \| "ActiveText" \| "aliceblue" \| "amber.100" \| "amber.200" \| "amber.300" ...` | The border color when the input is invalid. | | `focusBorderColor` | - | `"-moz-initial" \| "AccentColor" \| "AccentColorText" \| "ActiveBorder" \| "ActiveCaption" \| "ActiveText" \| "aliceblue" \| "amber.100" \| "amber.200" \| "amber.300" ...` | The border color when the input is focused. | ## Accessibility If you are not using `Field.Root`, set `aria-label` or `aria-labelledby` to `Input`. ```tsx ``` ```tsx Email address ``` ### ARIA Roles and Attributes | Component | Roles and Attributes | Usage | | --------- | -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `Input` | `aria-invalid` | Sets to `"true"` if `invalid` is set. | | | `aria-disabled` | Sets to `"true"` if `disabled` is set. | | | `aria-describedby` | If `Input` is within a `Field.Root` and `Field.Root` has an `errorMessage`, `helperMessage`, or a `Field.ErrorMessage`, `Field.HelperMessage`, sets its `id`. | | | `aria-readonly` | Sets to `"true"` if `readOnly` is set. | | | `aria-required` | Sets to `"true"` if `required` is set. |