@ui-sdk/vue 0.0.0-stage → 0.1.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (262) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +10 -2
  3. package/dist/accordion.d.ts +561 -0
  4. package/dist/accordion.js +24 -0
  5. package/dist/agent.d.ts +2 -0
  6. package/dist/agent.js +7 -0
  7. package/dist/alert-dialog.d.ts +231 -0
  8. package/dist/alert-dialog.js +33 -0
  9. package/dist/async-options.d.ts +18 -0
  10. package/dist/async-options.js +40 -0
  11. package/dist/autocomplete.d.ts +384 -0
  12. package/dist/autocomplete.js +344 -0
  13. package/dist/avatar.d.ts +40 -0
  14. package/dist/avatar.js +28 -0
  15. package/dist/button.d.ts +52 -0
  16. package/dist/button.js +43 -0
  17. package/dist/calendar-context.d.ts +10 -0
  18. package/dist/calendar-context.js +7 -0
  19. package/dist/calendar.d.ts +311 -0
  20. package/dist/calendar.js +349 -0
  21. package/dist/carousel.d.ts +236 -0
  22. package/dist/carousel.js +204 -0
  23. package/dist/checkbox.d.ts +211 -0
  24. package/dist/checkbox.js +151 -0
  25. package/dist/children.d.ts +41 -0
  26. package/dist/children.js +135 -0
  27. package/dist/collapsible.d.ts +54 -0
  28. package/dist/collapsible.js +18 -0
  29. package/dist/color-picker.d.ts +187 -0
  30. package/dist/color-picker.js +158 -0
  31. package/dist/color.d.ts +2 -0
  32. package/dist/color.js +21 -0
  33. package/dist/combobox.d.ts +517 -0
  34. package/dist/combobox.js +531 -0
  35. package/dist/command.d.ts +322 -0
  36. package/dist/command.js +345 -0
  37. package/dist/controller-target.d.ts +49 -0
  38. package/dist/controller-target.js +112 -0
  39. package/dist/create-parts.d.ts +126 -0
  40. package/dist/create-parts.js +206 -0
  41. package/dist/date-input.d.ts +133 -0
  42. package/dist/date-input.js +31 -0
  43. package/dist/date-picker.d.ts +328 -0
  44. package/dist/date-picker.js +354 -0
  45. package/dist/date.d.ts +2 -0
  46. package/dist/date.js +59 -0
  47. package/dist/dialog-parts.d.ts +259 -0
  48. package/dist/dialog-parts.js +300 -0
  49. package/dist/dialog.d.ts +251 -0
  50. package/dist/dialog.js +25 -0
  51. package/dist/drawer.d.ts +304 -0
  52. package/dist/drawer.js +373 -0
  53. package/dist/editor-context.d.ts +4 -0
  54. package/dist/editor-context.js +5 -0
  55. package/dist/field-context.d.ts +26 -0
  56. package/dist/field-context.js +44 -0
  57. package/dist/field.d.ts +154 -0
  58. package/dist/field.js +240 -0
  59. package/dist/file-input.d.ts +212 -0
  60. package/dist/file-input.js +255 -0
  61. package/dist/form-inputs.d.ts +16 -0
  62. package/dist/form-inputs.js +25 -0
  63. package/dist/gesture.d.ts +1 -0
  64. package/dist/gesture.js +15 -0
  65. package/dist/history.d.ts +2 -0
  66. package/dist/history.js +11 -0
  67. package/dist/hover-card.d.ts +137 -0
  68. package/dist/hover-card.js +153 -0
  69. package/dist/image-cropper.d.ts +74 -0
  70. package/dist/image-cropper.js +36 -0
  71. package/dist/image.d.ts +2 -0
  72. package/dist/image.js +5 -0
  73. package/dist/index.d.ts +59 -0
  74. package/dist/index.js +60 -0
  75. package/dist/input.d.ts +120 -0
  76. package/dist/input.js +73 -0
  77. package/dist/item-icon.d.ts +34 -0
  78. package/dist/item-icon.js +63 -0
  79. package/dist/label.d.ts +16 -0
  80. package/dist/label.js +8 -0
  81. package/dist/lifecycle.d.ts +11 -0
  82. package/dist/lifecycle.js +91 -0
  83. package/dist/list-items.d.ts +38 -0
  84. package/dist/list-items.js +59 -0
  85. package/dist/list-text.d.ts +7 -0
  86. package/dist/list-text.js +15 -0
  87. package/dist/listbox.d.ts +273 -0
  88. package/dist/listbox.js +126 -0
  89. package/dist/menu.d.ts +678 -0
  90. package/dist/menu.js +607 -0
  91. package/dist/menubar-context.d.ts +5 -0
  92. package/dist/menubar-context.js +5 -0
  93. package/dist/menubar.d.ts +61 -0
  94. package/dist/menubar.js +48 -0
  95. package/dist/meter.d.ts +41 -0
  96. package/dist/meter.js +37 -0
  97. package/dist/navigation-menu.d.ts +228 -0
  98. package/dist/navigation-menu.js +195 -0
  99. package/dist/number-input.d.ts +176 -0
  100. package/dist/number-input.js +231 -0
  101. package/dist/number.d.ts +2 -0
  102. package/dist/number.js +39 -0
  103. package/dist/nuxt/entries.json +977 -0
  104. package/dist/nuxt/module.d.ts +18 -0
  105. package/dist/nuxt/module.js +31 -0
  106. package/dist/nuxt/registrations.d.ts +22 -0
  107. package/dist/nuxt/registrations.js +22 -0
  108. package/dist/observe.d.ts +2 -0
  109. package/dist/observe.js +7 -0
  110. package/dist/otp-input.d.ts +142 -0
  111. package/dist/otp-input.js +130 -0
  112. package/dist/overlays.d.ts +40 -0
  113. package/dist/overlays.js +118 -0
  114. package/dist/pagination.d.ts +201 -0
  115. package/dist/pagination.js +146 -0
  116. package/dist/password-input.d.ts +144 -0
  117. package/dist/password-input.js +134 -0
  118. package/dist/popover.d.ts +211 -0
  119. package/dist/popover.js +258 -0
  120. package/dist/popup.d.ts +60 -0
  121. package/dist/popup.js +89 -0
  122. package/dist/preferences.d.ts +44 -0
  123. package/dist/preferences.js +102 -0
  124. package/dist/primitive.d.ts +2 -0
  125. package/dist/primitive.js +11 -0
  126. package/dist/progress.d.ts +41 -0
  127. package/dist/progress.js +37 -0
  128. package/dist/radio.d.ts +164 -0
  129. package/dist/radio.js +145 -0
  130. package/dist/rating.d.ts +149 -0
  131. package/dist/rating.js +146 -0
  132. package/dist/renderless.d.ts +4 -0
  133. package/dist/renderless.js +28 -0
  134. package/dist/resizable.d.ts +54 -0
  135. package/dist/resizable.js +22 -0
  136. package/dist/scroll-area.d.ts +72 -0
  137. package/dist/scroll-area.js +77 -0
  138. package/dist/segmented-control.d.ts +151 -0
  139. package/dist/segmented-control.js +110 -0
  140. package/dist/segmented-input.d.ts +76 -0
  141. package/dist/segmented-input.js +115 -0
  142. package/dist/select.d.ts +458 -0
  143. package/dist/select.js +468 -0
  144. package/dist/separator.d.ts +14 -0
  145. package/dist/separator.js +8 -0
  146. package/dist/shortcuts.d.ts +32 -0
  147. package/dist/shortcuts.js +56 -0
  148. package/dist/slider.d.ts +65 -0
  149. package/dist/slider.js +194 -0
  150. package/dist/switch.d.ts +103 -0
  151. package/dist/switch.js +71 -0
  152. package/dist/tabs.d.ts +338 -0
  153. package/dist/tabs.js +27 -0
  154. package/dist/text-control.d.ts +89 -0
  155. package/dist/text-control.js +51 -0
  156. package/dist/text-match.d.ts +2 -0
  157. package/dist/text-match.js +7 -0
  158. package/dist/textarea.d.ts +106 -0
  159. package/dist/textarea.js +68 -0
  160. package/dist/time-input.d.ts +131 -0
  161. package/dist/time-input.js +32 -0
  162. package/dist/timeline.d.ts +81 -0
  163. package/dist/timeline.js +30 -0
  164. package/dist/toast-parts.d.ts +203 -0
  165. package/dist/toast-parts.js +270 -0
  166. package/dist/toast.d.ts +2 -0
  167. package/dist/toast.js +21 -0
  168. package/dist/toggle-props.d.ts +22 -0
  169. package/dist/toggle-props.js +14 -0
  170. package/dist/toggle.d.ts +199 -0
  171. package/dist/toggle.js +129 -0
  172. package/dist/token-input.d.ts +136 -0
  173. package/dist/token-input.js +214 -0
  174. package/dist/toolbar-context.d.ts +7 -0
  175. package/dist/toolbar-context.js +20 -0
  176. package/dist/toolbar.d.ts +120 -0
  177. package/dist/toolbar.js +77 -0
  178. package/dist/tooltip.d.ts +160 -0
  179. package/dist/tooltip.js +224 -0
  180. package/dist/tree.d.ts +300 -0
  181. package/dist/tree.js +209 -0
  182. package/dist/trigger-menu.d.ts +452 -0
  183. package/dist/trigger-menu.js +254 -0
  184. package/dist/use-primitive.d.ts +132 -0
  185. package/dist/use-primitive.js +462 -0
  186. package/dist/waterfall.d.ts +201 -0
  187. package/dist/waterfall.js +171 -0
  188. package/docs/README.md +89 -0
  189. package/docs/agents.md +1523 -0
  190. package/docs/components/accordion.md +1369 -0
  191. package/docs/components/alert-dialog.md +799 -0
  192. package/docs/components/autocomplete.md +1857 -0
  193. package/docs/components/avatar.md +272 -0
  194. package/docs/components/button.md +435 -0
  195. package/docs/components/calendar.md +1589 -0
  196. package/docs/components/carousel.md +1171 -0
  197. package/docs/components/checkbox.md +1008 -0
  198. package/docs/components/collapsible.md +536 -0
  199. package/docs/components/color-picker.md +706 -0
  200. package/docs/components/combobox.md +3504 -0
  201. package/docs/components/command.md +1481 -0
  202. package/docs/components/date-input.md +536 -0
  203. package/docs/components/date-picker.md +1244 -0
  204. package/docs/components/dialog.md +1397 -0
  205. package/docs/components/drawer.md +1166 -0
  206. package/docs/components/field.md +538 -0
  207. package/docs/components/file-input.md +611 -0
  208. package/docs/components/hover-card.md +505 -0
  209. package/docs/components/image-cropper.md +556 -0
  210. package/docs/components/input.md +306 -0
  211. package/docs/components/label.md +203 -0
  212. package/docs/components/listbox.md +1004 -0
  213. package/docs/components/menu.md +1229 -0
  214. package/docs/components/menubar.md +443 -0
  215. package/docs/components/meter.md +315 -0
  216. package/docs/components/navigation-menu.md +1523 -0
  217. package/docs/components/number-input.md +1029 -0
  218. package/docs/components/otp-input.md +512 -0
  219. package/docs/components/pagination.md +613 -0
  220. package/docs/components/password-input.md +649 -0
  221. package/docs/components/popover.md +1448 -0
  222. package/docs/components/preferences.md +208 -0
  223. package/docs/components/progress.md +423 -0
  224. package/docs/components/radio.md +785 -0
  225. package/docs/components/rating.md +416 -0
  226. package/docs/components/resizable.md +910 -0
  227. package/docs/components/scroll-area.md +915 -0
  228. package/docs/components/segmented-control.md +435 -0
  229. package/docs/components/select.md +2015 -0
  230. package/docs/components/separator.md +229 -0
  231. package/docs/components/slider.md +1084 -0
  232. package/docs/components/switch.md +565 -0
  233. package/docs/components/tabs.md +944 -0
  234. package/docs/components/textarea.md +299 -0
  235. package/docs/components/time-input.md +224 -0
  236. package/docs/components/timeline.md +654 -0
  237. package/docs/components/toast.md +1224 -0
  238. package/docs/components/toggle.md +500 -0
  239. package/docs/components/token-input.md +953 -0
  240. package/docs/components/toolbar.md +739 -0
  241. package/docs/components/tooltip.md +818 -0
  242. package/docs/components/tree.md +1306 -0
  243. package/docs/components/trigger-menu.md +1223 -0
  244. package/docs/components/waterfall.md +717 -0
  245. package/docs/controllers.md +71 -0
  246. package/docs/core.md +8027 -0
  247. package/docs/custom-parts.md +89 -0
  248. package/docs/first-component.md +83 -0
  249. package/docs/forms.md +122 -0
  250. package/docs/installation.md +72 -0
  251. package/docs/introduction.md +32 -0
  252. package/docs/lists-and-menus.md +122 -0
  253. package/docs/llms.txt +1502 -0
  254. package/docs/parts-and-composition.md +85 -0
  255. package/docs/popups.md +108 -0
  256. package/docs/rendering.md +56 -0
  257. package/docs/server-rendering.md +180 -0
  258. package/docs/state-and-events.md +100 -0
  259. package/docs/styling-and-animation.md +148 -0
  260. package/docs/utilities/async-options.md +348 -0
  261. package/docs/utilities/shortcuts.md +159 -0
  262. package/package.json +352 -3
@@ -0,0 +1,512 @@
1
+ # OTP Input
2
+
3
+ Enter a one-time code with support for pasting, autofill, and native form validation.
4
+
5
+ Use an OTP Input for a short code sent by text or email, like a sign-in or verification code. Each character gets its own slot, and a pasted or autofilled code fills them all at once.
6
+
7
+ ```vue title="basic.vue"
8
+ <script setup lang="ts">
9
+ import { MinusIcon } from "@lucide/vue"
10
+ import { Field, FieldLabel } from "@ui-sdk/vue/field"
11
+ import {
12
+ OTPInput,
13
+ OTPInputGroup,
14
+ OTPInputSeparator,
15
+ OTPInputSlot,
16
+ } from "@ui-sdk/vue/otp-input"
17
+ </script>
18
+
19
+ <template>
20
+ <Field>
21
+ <FieldLabel>Verification code</FieldLabel>
22
+ <OTPInput :max-length="6">
23
+ <OTPInputGroup>
24
+ <OTPInputSlot :index="0" />
25
+ <OTPInputSlot :index="1" />
26
+ <OTPInputSlot :index="2" />
27
+ </OTPInputGroup>
28
+ <OTPInputSeparator>
29
+ <MinusIcon aria-hidden="true" />
30
+ </OTPInputSeparator>
31
+ <OTPInputGroup>
32
+ <OTPInputSlot :index="3" />
33
+ <OTPInputSlot :index="4" />
34
+ <OTPInputSlot :index="5" />
35
+ </OTPInputGroup>
36
+ </OTPInput>
37
+ </Field>
38
+ </template>
39
+ ```
40
+
41
+ Type a six-digit code or paste 123-456. Click a slot to edit it, use the arrow keys to move, and use your usual undo shortcut to undo a change.
42
+
43
+ ## Installation
44
+
45
+ ```bash
46
+ npm install @ui-sdk/vue @ui-sdk/core
47
+ ```
48
+
49
+ ## Composition
50
+
51
+ Use the following composition to build an `OTPInput`:
52
+
53
+ ```text
54
+ OTPInput
55
+ └── OTPInputGroup
56
+ ├── OTPInputSlot
57
+ └── OTPInputSlot
58
+ ```
59
+
60
+ `OTPInput` creates the native input and holds the code. `OTPInputGroup` lays out a run of slots. Each `OTPInputSlot` displays the character at its zero-based `index`. Add `OTPInputSeparator` between groups when the code is easier to read in sections, like the dash in the example above.
61
+
62
+ Groups and separators change the presentation of one value. They do not create additional fields or tab stops: the slots display the value of a single native input, which handles selection, paste, undo, form submission, and autofill. It uses `autocomplete="one-time-code"` so supported browsers and password managers can offer a saved or received code.
63
+
64
+ ## Usage
65
+
66
+ Import the parts and put them together:
67
+
68
+ ```vue
69
+ <script setup lang="ts">
70
+ import { OTPInput, OTPInputGroup, OTPInputSlot } from "@ui-sdk/vue/otp-input"
71
+ </script>
72
+
73
+ <template>
74
+ <OTPInput :max-length="4" aria-label="Verification code">
75
+ <OTPInputGroup>
76
+ <OTPInputSlot :index="0" />
77
+ <OTPInputSlot :index="1" />
78
+ <OTPInputSlot :index="2" />
79
+ <OTPInputSlot :index="3" />
80
+ </OTPInputGroup>
81
+ </OTPInput>
82
+ </template>
83
+ ```
84
+
85
+ ## Four Digits
86
+
87
+ Set `max-length` to the code's length and render that many slots. The default length is six.
88
+
89
+ ```vue title="four-digits.vue"
90
+ <script setup lang="ts">
91
+ import { Field, FieldLabel } from "@ui-sdk/vue/field"
92
+ import { OTPInput, OTPInputGroup, OTPInputSlot } from "@ui-sdk/vue/otp-input"
93
+ </script>
94
+
95
+ <template>
96
+ <Field>
97
+ <FieldLabel>PIN</FieldLabel>
98
+ <OTPInput :max-length="4" text-align="center">
99
+ <OTPInputGroup>
100
+ <OTPInputSlot v-for="index in [0, 1, 2, 3]" :key="index" :index="index" />
101
+ </OTPInputGroup>
102
+ </OTPInput>
103
+ </Field>
104
+ </template>
105
+ ```
106
+
107
+ Enter four digits in PIN. Once it is full, typing another digit replaces the selected slot. Click another slot to edit it.
108
+
109
+ ## Alphanumeric
110
+
111
+ Set `pattern` to `digits`, `letters`, or `alphanumeric`. The default is `digits`. The pattern filters characters and selects a suitable keyboard on touch devices.
112
+
113
+ ```vue title="alphanumeric.vue"
114
+ <script setup lang="ts">
115
+ import { MinusIcon } from "@lucide/vue"
116
+ import { Field, FieldLabel } from "@ui-sdk/vue/field"
117
+ import {
118
+ OTPInput,
119
+ OTPInputGroup,
120
+ OTPInputSeparator,
121
+ OTPInputSlot,
122
+ } from "@ui-sdk/vue/otp-input"
123
+ </script>
124
+
125
+ <template>
126
+ <Field>
127
+ <FieldLabel>Recovery code</FieldLabel>
128
+ <OTPInput :max-length="8" pattern="alphanumeric">
129
+ <OTPInputGroup>
130
+ <OTPInputSlot v-for="index in [0, 1, 2, 3]" :key="index" :index="index" />
131
+ </OTPInputGroup>
132
+ <OTPInputSeparator>
133
+ <MinusIcon aria-hidden="true" />
134
+ </OTPInputSeparator>
135
+ <OTPInputGroup>
136
+ <OTPInputSlot v-for="index in [4, 5, 6, 7]" :key="index" :index="index" />
137
+ </OTPInputGroup>
138
+ </OTPInput>
139
+ </Field>
140
+ </template>
141
+ ```
142
+
143
+ Type letters and digits into Recovery code, or paste ab12-cd34. The hyphen is removed and the eight characters fill the slots.
144
+
145
+ ## Custom Pattern
146
+
147
+ Pass a regular expression, such as `/[0-9A-F]/i` to accept hexadecimal characters. Use `input-mode` to choose the keyboard separately. The example displays letters in uppercase without changing their stored case.
148
+
149
+ ```vue title="pattern.vue"
150
+ <script setup lang="ts">
151
+ import { Field, FieldLabel } from "@ui-sdk/vue/field"
152
+ import { OTPInput, OTPInputGroup, OTPInputSlot } from "@ui-sdk/vue/otp-input"
153
+ </script>
154
+
155
+ <template>
156
+ <Field>
157
+ <FieldLabel>Device code</FieldLabel>
158
+ <OTPInput :max-length="6" :pattern="/[0-9A-F]/i" input-mode="text">
159
+ <OTPInputGroup>
160
+ <OTPInputSlot v-for="index in [0, 1, 2, 3, 4, 5]" :key="index" :index="index" />
161
+ </OTPInputGroup>
162
+ </OTPInput>
163
+ </Field>
164
+ </template>
165
+ ```
166
+
167
+ Try typing 12zzab into Device code. The z characters are rejected; the accepted value is 12ab, displayed as 12AB.
168
+
169
+ ## Validation
170
+
171
+ Inside a [Field](./field.md), pass `invalid` when your code rejects the value, such as a code the server didn't accept. The field marks the input with `aria-invalid` and connects its `FieldError`. Outside a field, pass `aria-invalid` and `aria-describedby` yourself.
172
+
173
+ ```vue title="invalid.vue"
174
+ <script setup lang="ts">
175
+ import { Field, FieldError, FieldLabel } from "@ui-sdk/vue/field"
176
+ import { OTPInput, OTPInputGroup, OTPInputSlot } from "@ui-sdk/vue/otp-input"
177
+ import { ref } from "vue"
178
+
179
+ const invalid = ref(true)
180
+ </script>
181
+
182
+ <template>
183
+ <Field :invalid="invalid">
184
+ <FieldLabel>Verification code</FieldLabel>
185
+ <OTPInput default-value="482913" @value-change="invalid = false">
186
+ <OTPInputGroup>
187
+ <OTPInputSlot v-for="index in [0, 1, 2, 3, 4, 5]" :key="index" :index="index" />
188
+ </OTPInputGroup>
189
+ </OTPInput>
190
+ <FieldError>That code has expired. Request a new one.</FieldError>
191
+ </Field>
192
+ </template>
193
+ ```
194
+
195
+ Verification code is marked invalid, and the error below explains why. Edit any digit to clear the error.
196
+
197
+ ## Controlled
198
+
199
+ Use `v-model:value` to bind the code. `@value-change` also receives the change details. Call `details.cancel()` in the change callback to reject a change. Incoming values are filtered by the pattern and limited to `max-length`, just like typed values.
200
+
201
+ ```vue title="controlled.vue"
202
+ <script setup lang="ts">
203
+ import { Field, FieldLabel } from "@ui-sdk/vue/field"
204
+ import { OTPInput, OTPInputGroup, OTPInputSlot } from "@ui-sdk/vue/otp-input"
205
+ import { ref } from "vue"
206
+ import { useLog } from "./log"
207
+
208
+ const log = useLog()
209
+ const value = ref("")
210
+ </script>
211
+
212
+ <template>
213
+ <Field>
214
+ <FieldLabel>One-time password</FieldLabel>
215
+ <OTPInput
216
+ v-model:value="value"
217
+ @value-change="
218
+ (next, details) => log(`${next || 'Empty'} (${details.reason})`)
219
+ "
220
+ >
221
+ <OTPInputGroup>
222
+ <OTPInputSlot v-for="index in [0, 1, 2, 3, 4, 5]" :key="index" :index="index" />
223
+ </OTPInputGroup>
224
+ </OTPInput>
225
+ </Field>
226
+ </template>
227
+ ```
228
+
229
+ Enter, paste, or delete digits in One-time password. The console logs each new code and its reason.
230
+
231
+ See [State and Events](../state-and-events.md) for the shared state conventions. The [reason](#reasons) distinguishes typing, pasting, undo, and controller actions.
232
+
233
+ ## On Complete
234
+
235
+ `@value-commit` runs when a change fills every slot, including typing, paste, autofill, and controller writes. Changing an already-full code runs it again. Form resets and page restoration do not.
236
+
237
+ ```vue title="complete.vue"
238
+ <script setup lang="ts">
239
+ import { Field, FieldLabel } from "@ui-sdk/vue/field"
240
+ import { OTPInput, OTPInputGroup, OTPInputSlot } from "@ui-sdk/vue/otp-input"
241
+ import { useLog } from "./log"
242
+
243
+ const log = useLog()
244
+ </script>
245
+
246
+ <template>
247
+ <Field>
248
+ <FieldLabel>Verification code</FieldLabel>
249
+ <OTPInput
250
+ @value-commit="
251
+ (value, details) => log(`Checking ${value} (${details.reason})`)
252
+ "
253
+ >
254
+ <OTPInputGroup>
255
+ <OTPInputSlot v-for="index in [0, 1, 2, 3, 4, 5]" :key="index" :index="index" />
256
+ </OTPInputGroup>
257
+ </OTPInput>
258
+ </Field>
259
+ </template>
260
+ ```
261
+
262
+ Fill all six slots. The console logs the complete code and the change reason. Replace a digit to log it again; deleting one logs nothing.
263
+
264
+ ## Forms
265
+
266
+ Set `name` to include the code in `FormData`. `required` blocks an empty code, and a partial code fails length validation. Reset restores the default value. Use `form` to associate a control outside the form with its ID.
267
+
268
+ ```vue title="form.vue"
269
+ <script setup lang="ts">
270
+ import {
271
+ Field,
272
+ FieldDescription,
273
+ FieldError,
274
+ FieldLabel,
275
+ } from "@ui-sdk/vue/field"
276
+ import { OTPInput, OTPInputGroup, OTPInputSlot } from "@ui-sdk/vue/otp-input"
277
+ import { useLog } from "./log"
278
+
279
+ const log = useLog()
280
+
281
+ function onSubmit(event: Event) {
282
+ const data = [...new FormData(event.currentTarget as HTMLFormElement)].map(
283
+ ([name, value]) => `${name}=${value}`
284
+ )
285
+ log(`Submitted ${data.join(", ")}`)
286
+ }
287
+ </script>
288
+
289
+ <template>
290
+ <div data-slot="stack">
291
+ <form id="verify-sign-in" @submit.prevent="onSubmit">
292
+ <Field>
293
+ <FieldLabel>Verification code</FieldLabel>
294
+ <OTPInput name="code" required>
295
+ <OTPInputGroup>
296
+ <OTPInputSlot v-for="index in [0, 1, 2, 3, 4, 5]" :key="index" :index="index" />
297
+ </OTPInputGroup>
298
+ </OTPInput>
299
+ <FieldDescription
300
+ >Enter the six-digit code we sent to
301
+ hollis@example.com.</FieldDescription
302
+ >
303
+ <FieldError />
304
+ </Field>
305
+ </form>
306
+ <Field>
307
+ <FieldLabel>Recovery code (optional)</FieldLabel>
308
+ <OTPInput name="recovery" form="verify-sign-in" :max-length="8" pattern="alphanumeric">
309
+ <OTPInputGroup>
310
+ <OTPInputSlot v-for="index in [0, 1, 2, 3, 4, 5, 6, 7]" :key="index" :index="index" />
311
+ </OTPInputGroup>
312
+ </OTPInput>
313
+ <FieldError />
314
+ </Field>
315
+ <div data-slot="row">
316
+ <button type="reset" form="verify-sign-in">Reset</button>
317
+ <button type="submit" form="verify-sign-in" data-variant="solid">
318
+ Verify
319
+ </button>
320
+ </div>
321
+ </div>
322
+ </template>
323
+ ```
324
+
325
+ Choose Verify with an empty or partial code to see validation. Enter all six digits and choose Verify to log the form values. Recovery code sits outside the form but submits with it. Reset clears both fields.
326
+
327
+ A typed partial code reports `tooShort`. Partial default values and controller writes are checked through the native input's pattern, because browsers do not apply minlength validation to those values.
328
+
329
+ ## Disabled and Read-Only
330
+
331
+ A disabled input cannot be focused, changed, or submitted. `read-only` prevents changes while keeping the input focusable and included in form data.
332
+
333
+ ```vue
334
+ <OTPInput disabled default-value="123456" aria-label="Disabled code">
335
+ ...
336
+ </OTPInput>
337
+ <OTPInput read-only default-value="654321" aria-label="Read-only code">
338
+ ...
339
+ </OTPInput>
340
+ ```
341
+
342
+ ## Controller
343
+
344
+ Create a `createOTPInputController()` and pass it as `controller` to read, fill, clear, or focus the input from another control. Writes use the `imperative` reason and pass through the same filtering and change callbacks as typing.
345
+
346
+ ```vue
347
+ <script setup lang="ts">
348
+ const code = createOTPInputController()
349
+ </script>
350
+
351
+ <template>
352
+ <button @click="code.setValue('123456')">Fill</button>
353
+ <button @click="code.clear()">Clear</button>
354
+ <button @click="console.log(code.getValue())">Read</button>
355
+ <button @click="code.focus()">Focus</button>
356
+ <OTPInput :controller="code" aria-label="Verification code"> ... </OTPInput>
357
+ </template>
358
+ ```
359
+
360
+ [Controllers](../controllers.md) covers creating and sharing a controller.
361
+
362
+ ## Custom Rendering
363
+
364
+ The root's state exposes all `slots`. Each slot exposes `char`, `active`, and `hasFakeCaret` if you want to draw its contents yourself. See [Parts and Composition](../parts-and-composition.md) for the rendering conventions.
365
+
366
+ ## Styling
367
+
368
+ Draw the active slot and caret with `data-active` and `data-fake-caret`. The examples include the caret animation and disable it for reduced motion. Keep `position: relative` on each slot so its caret stays inside it.
369
+
370
+ Each part has a `data-slot`, such as `otp-input-slot`, and its state attributes are listed under [Data Attributes](#data-attributes).
371
+
372
+ ## Data Attributes
373
+
374
+ ### OTPInput
375
+ `[data-slot="otp-input"]`
376
+
377
+ - `data-complete`: Present while every slot is filled.
378
+ - `data-filled`: Present while the code holds any character.
379
+ - `data-disabled`: Present when disabled, by its own prop or a `<fieldset>`.
380
+ - `data-focused`: Present while the input has focus.
381
+
382
+ ### OTPInputGroup
383
+ `[data-slot="otp-input-group"]`
384
+
385
+ - `data-complete`: Present while every slot is filled.
386
+ - `data-filled`: Present while the code holds any character.
387
+ - `data-disabled`: Present when disabled, by its own prop or a `<fieldset>`.
388
+ - `data-focused`: Present while the input has focus.
389
+
390
+ ### OTPInputSlot
391
+ `[data-slot="otp-input-slot"]`
392
+
393
+ - `data-filled`: Present while the slot holds a character.
394
+ - `data-disabled`: Present when disabled, by its own prop or a `<fieldset>`.
395
+ - `data-active`: Present on the slot typing goes to: the selected character, or the empty slot after the last one. Only while focused.
396
+ - `data-fake-caret`: Present on the active slot while it's empty. Draw a blinking caret in it; the input's own caret is hidden.
397
+
398
+ ### OTPInputSeparator
399
+ `[data-slot="otp-input-separator"]`
400
+
401
+ - `data-disabled`: Present when disabled, by its own prop or a `<fieldset>`.
402
+
403
+ ## API Reference
404
+
405
+ Props are the same as below, and callbacks are events. `id`, `autofocus`, `aria-label`,
406
+ `aria-labelledby`, `aria-describedby` and `aria-invalid` go to the input.
407
+
408
+ ### OTPInput
409
+
410
+ - `debug?` (`boolean`): Logs every state change with its reason to the console, in development builds.
411
+ - `value?` (`string`): The code, for a controlled input.
412
+ - `defaultValue?` (`string`): The code it starts with, when uncontrolled. A form reset returns here.
413
+ - `@value-change` (`((value: string, details: ChangeDetails<OTPInputValueChangeReason>) => void)`): Runs when the code changes: typing or deleting (`"input-change"`), a paste (`"paste"`), the browser's undo and redo, a form reset, or a controller. Autofill and codes from the keyboard's suggestions are `"input-change"`. `details.cancel()` keeps the code as it was.
414
+ - `@value-commit` (`((value: string, details: CommitDetails<OTPInputValueChangeReason>) => void)`): Runs when a change fills every slot, with the whole code, like to verify it. A controller filling it counts, so does a code that changes while full.
415
+ - `maxLength?` (`number`): How many characters the code has, one slot each.
416
+ - `pattern?` (`OTPInputPattern`): Which characters it accepts: `"digits"`, `"letters"`, `"alphanumeric"`, or a regular expression each character must match, like `/[A-F0-9]/i`. Anything else typed, pasted or dropped is ignored.
417
+ - `inputMode?` (`"decimal" | "none" | "numeric" | "tel" | "text"`): The keyboard touch screens show.
418
+ - `textAlign?` (`"center" | "end" | "start"`): Where the invisible input keeps its text and caret. It decides where the browser puts its own popups, like the paste menu on phones. `"start"` and `"end"` follow the reading direction.
419
+ - `autoComplete?` (`string`): The input's `autocomplete`. `"one-time-code"` lets phones offer a code from a message, and password managers fill it.
420
+ - `disabled?` (`boolean`): Disables it like a native input: it can't be focused, and isn't submitted.
421
+ - `readOnly?` (`boolean`): Makes it read-only: focusable and submitted, but the code can't change.
422
+ - `required?` (`boolean`): Requires a code before the form submits. A partial code is too short either way.
423
+ - `name?` (`string`): The name it submits the code under.
424
+ - `form?` (`string`): The id of a form to belong to, when it isn't inside that form.
425
+ - `controller?` (`{ getValue: () => string; setValue: (value: string, options?: OTPInputChangeOptions) => boolean; clear: (options?: OTPInputChangeOptions) => boolean; focus: () => void; }`): Reads and writes the code from anywhere. Create one with `createOTPInputController()`.
426
+
427
+ ### OTPInputSlot
428
+
429
+ - `index` (`number`): Which character of the code the slot shows, from 0.
430
+
431
+ ### State
432
+
433
+ What render functions, state-based class names and slots receive. The root, groups and separators get the
434
+ input's state.
435
+
436
+ - `value` (`string`): The code.
437
+ - `slots` (`OTPInputSlotData[]`): One entry per slot: its character, whether it's active, and whether it draws a caret.
438
+ - `focused` (`boolean`): Whether the input has focus.
439
+ - `complete` (`boolean`): Whether every slot is filled.
440
+ - `disabled` (`boolean`): Whether it's disabled, by itself or by a `<fieldset>`.
441
+
442
+ Slots get their own:
443
+
444
+ - `char` (`string | null`): The character in the slot, or null when it's empty.
445
+ - `active` (`boolean`): Whether the slot is where typing goes: the selected character, or the empty slot after the last one.
446
+ - `hasFakeCaret` (`boolean`): Whether the slot should draw a caret: it's active and empty. The real caret is hidden.
447
+ - `index` (`number`): Which character of the code the slot shows.
448
+ - `focused` (`boolean`): Whether the input has focus.
449
+ - `disabled` (`boolean`): Whether it's disabled, by itself or by a `<fieldset>`.
450
+
451
+ ### Reasons
452
+
453
+ `details.reason` says why the code changed. Autofill and a code from the keyboard's suggestions are `input-change`.
454
+
455
+ - `input-change` (`Event`): Typing, pasting or dropping changed a text field's value; in a combobox it can also open or close it, or Enter keeps the typed text as the value.
456
+ - `paste` (`ClipboardEvent`): Files were pasted, like a screenshot, or text and tokens into a token input.
457
+ - `undo` (`KeyboardEvent | InputEvent`): Undo, from the keyboard, the Edit menu or a controller.
458
+ - `redo` (`KeyboardEvent | InputEvent`): Redo, from the keyboard, the Edit menu or a controller.
459
+ - `reset` (`none`): A form reset.
460
+ - `restore` (`none`): The browser restored state, like after going back, or a saved value was read back from storage.
461
+ - `imperative` (`none`): A controller or `api` call, or a property set on a web component.
462
+
463
+ ### Controller
464
+
465
+ Create one with `createOTPInputController()` and pass it as `controller`.
466
+
467
+ `setValue()` and `clear()` take an optional `{ reason, event }`, and run the change callback like typing.
468
+
469
+ - `getValue()` (`() => string`): The code.
470
+ - `setValue(value, options?)` (`(value: string, options?: OTPInputChangeOptions | undefined) => boolean`): Sets the code, as typing it would. Characters that don't fit the pattern are dropped. Returns false when the change was canceled or nothing changed.
471
+ - `clear(options?)` (`(options?: OTPInputChangeOptions | undefined) => boolean`): Empties the code. Returns false when the change was canceled or nothing changed.
472
+ - `focus()` (`() => void`): Moves focus to the input.
473
+
474
+ ### Events
475
+
476
+ Events get the code first, then the details. `v-model` only updates when the change event wasn't canceled.
477
+
478
+ | Binding | On | Receives |
479
+ | --------------- | ---------- | --------------------------------------------------------------- |
480
+ | `v-model:value` | `OTPInput` | The code |
481
+ | `@value-change` | `OTPInput` | `(value, details)`: the new code and the [reason](#reasons) |
482
+ | `@value-commit` | `OTPInput` | `(value, details)`: the full code and the reason that filled it |
483
+
484
+ ## Accessibility
485
+
486
+ Name the input with FieldLabel, a native label, `aria-label`, or `aria-labelledby`. Screen readers encounter one input with the whole code; the visual slots, groups, and separators are hidden from them.
487
+
488
+ ### Keyboard
489
+
490
+ The input keeps its native keys. Arrow keys, Home, and End move the selection between slots, Backspace deletes, and your usual shortcuts undo and redo. Pasting a code such as `123-456` removes the separators.
491
+
492
+ ### Tested Behavior
493
+
494
+ Every line below is an automated test.
495
+
496
+ - Typing fills the slots in order.
497
+ - Characters the pattern doesn't accept are ignored.
498
+ - Filling every slot completes the code.
499
+ - Backspace deletes the last character.
500
+ - ArrowLeft goes back a slot, and typing replaces its character.
501
+ - Pressing a filled slot lets you retype it.
502
+ - Pasting a code with a dash fills every slot.
503
+ - The form submits the code under its name.
504
+ - A partial default code is too short to submit.
505
+ - A typed partial code is too short, not the wrong format.
506
+ - A canceled change keeps the code.
507
+ - A disabled code can't be typed into.
508
+ - A code of letters and digits takes both.
509
+ - The input asks for a one-time code and a numeric keyboard.
510
+ - Typing a whole code with no waits fills it.
511
+
512
+ Runs in React, Vue and web components.