--- title: PinInput description: "`PinInput`は、ピンコードやOTP(ワンタイムパスワード)の入力を取得するために使用されるコンポーネントです。" links: - style: https://github.com/yamada-ui/yamada-ui/tree/main/packages/react/src/components/pin-input/pin-input.style.ts - source: https://github.com/yamada-ui/yamada-ui/tree/main/packages/react/src/components/pin-input - storybook: https://yamada-ui.github.io/yamada-ui?path=/story/components-pininput--basic --- ```tsx ``` ## 使い方 ```tsx import { PinInput } from "@yamada-ui/react" ``` ```tsx import { PinInput } from "@/components/ui" ``` ```tsx import { PinInput } from "@workspaces/ui" ``` ```tsx ``` ### バリアントを変更する ```tsx {(variant) => } ``` ### サイズを変更する ```tsx {(size) => } ``` ### カラースキームを変更する ```tsx {(colorScheme) => ( )} ``` ### デフォルトの値を設定する デフォルトの値を設定する場合は、`defaultValue`に文字列を設定します。 ```tsx {(defaultValue) => ( )} ``` ### プレースホルダーを変更する プレースホルダーを変更する場合は、`placeholder`に文字列を設定します。 ```tsx ``` ### フィールド数を変更する フィールド数を変更する場合は、`items`に数値を設定します。 ```tsx {(items) => } ``` ### タイプを変更する デフォルトでは、数値のみ入力が可能です。英数字をサポートする場合は、`type`に`alphanumeric`を設定します。 ```tsx ``` ### ワンタイムパスワード ワンタイムパスワード(`autocomplete="one-time-code"`)を有効にするには、`otp`を`true`に設定します。 ```tsx ``` ### 入力された値をマスクする 入力された値をマスクする場合は、`mask`を`true`に設定します。 ```tsx ``` ### 無効にする 無効にする場合は、`disabled`を`true`に設定します。 ```tsx {(index) => } ``` ### 読み取り専用にする 読み取り専用にする場合は、`readOnly`を`true`に設定します。 ```tsx {(index) => } ``` ### 無効な入力にする 無効な入力にする場合は、`invalid`を`true`に設定します。 ```tsx {(index) => } ``` ### ボーダーの色を変更する ボーダーの色を変更する場合は、`focusBorderColor`または`errorBorderColor`に値を設定します。 ```tsx ``` ### 完了のイベントをハンドルする 完了のイベントをハンドルする場合は、`onComplete`を使用します。 ```tsx const { page } = useLoading() return page.start({ duration: 5000 })} /> ``` ### フォーカス管理を無効にする デフォルトでは、フィールドが入力されると、自動的に次のフィールドにフォーカスは移動します。また、`BackSpace`キーが入力された場合は、前のフィールドにフォーカスされます。この制御を無効にする場合は、`manageFocus`を`false`に設定します。 ```tsx ``` ### フィールドをカスタマイズする ```tsx {(index) => ( )} ``` ### 制御する ```tsx const { page } = useLoading() const [value, onChange] = useState("") const onComplete = () => page.start({ duration: 5000 }) return ( ) ``` ## Props ### PinInput.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" \| "baseline" \| "center" \| "end" \| "flex-end" \| "flex-start" \| "inherit" \| "initial" \| "normal" \| "revert-layer" ...` | The CSS `align-items` property. | | `attached` | `false` | `boolean` | If `true`, the borderRadius of button that are direct children will be altered to look flushed together. | | `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. | | `defaultValue` | - | `string` | The initial value of the pin input. | | `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" \| "ActiveBorder" \| "ActiveCaption" \| "aliceblue" \| "amber.100" \| "amber.200" \| "amber.300" \| "amber.400" \| "amber.50" \| "amber.500" ...` | The border color when the input is invalid. | | `focusBorderColor` | - | `"-moz-initial" \| "ActiveBorder" \| "ActiveCaption" \| "aliceblue" \| "amber.100" \| "amber.200" \| "amber.300" \| "amber.400" \| "amber.50" \| "amber.500" ...` | The border color when the input is focused. | | `grow` | `false` | `boolean` | If `true`, the children will grow to fill the available space. | | `invalid` | `false` | `boolean` | If `true`, the field will be invalid. | | `items` | `4` | `number` | The number of inputs to display. | | `justify` | - | `"-moz-initial" \| "center" \| "end" \| "flex-end" \| "flex-start" \| "inherit" \| "initial" \| "left" \| "normal" \| "revert-layer" ...` | The CSS `justify-content` property. | | `manageFocus` | `true` | `boolean` | If `true`, focus will move automatically to the next input once filled. | | `mask` | - | `boolean` | If `true`, the input's value will be masked just like `type=password`. | | `onChange` | - | `(value: string) => void` | Function called on input change. | | `onComplete` | - | `(value: string) => void` | Function called when all inputs have valid values. | | `orientation` | `"horizontal"` | `"horizontal" \| "vertical"` | The orientation of the group. | | `otp` | - | `boolean` | If `true`, the pin input component signals to its fields that they should. | | `placeholder` | `"◯"` | `string` | The placeholder for the pin input. | | `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. | | `stacking` | - | `"first-on-top" \| "last-on-top"` | The stacking order of the group. | | `type` | `"number"` | `"alphanumeric" \| "number"` | The type of values the pin-input should allow. | | `value` | - | `string` | The value of the pin input. | | `wrap` | - | `"-moz-initial" \| "inherit" \| "initial" \| "nowrap" \| "revert-layer" \| "revert" \| "unset" \| "wrap-reverse" \| "wrap" ...` | The CSS `flex-wrap` property. | ### PinInput.Field | 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` | - | `"2xl" \| "lg" \| "md" \| "sm" \| "xl" \| "xs"` | The size of the component. | | `variant` | - | `"filled" \| "flushed" \| "outline" \| "plain"` | The variant of the component. | | `index` | - | `number` | The index of the pin input field. | | `errorBorderColor` | - | `"-moz-initial" \| "ActiveBorder" \| "ActiveCaption" \| "aliceblue" \| "amber.100" \| "amber.200" \| "amber.300" \| "amber.400" \| "amber.50" \| "amber.500" ...` | The border color when the input is invalid. | | `focusBorderColor` | - | `"-moz-initial" \| "ActiveBorder" \| "ActiveCaption" \| "aliceblue" \| "amber.100" \| "amber.200" \| "amber.300" \| "amber.400" \| "amber.50" \| "amber.500" ...` | 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. | ## アクセシビリティ 現在、v2の移行に伴い、このセクションは更新中です。