@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,299 @@
1
+ # Textarea
2
+
3
+ Enter multiple lines of text, grow the field as you type, and connect it to a form.
4
+
5
+ A textarea is a native multi-line text field for messages, notes and descriptions. It works inside a field and a form, can grow with its text, and reports the same change reasons as Input.
6
+
7
+ ```vue title="basic.vue"
8
+ <script setup lang="ts">
9
+ import { Field, FieldLabel } from "@ui-sdk/vue/field"
10
+ import { Textarea } from "@ui-sdk/vue/textarea"
11
+ </script>
12
+
13
+ <template>
14
+ <Field name="message">
15
+ <FieldLabel>Message</FieldLabel>
16
+ <Textarea placeholder="Type your message here…" />
17
+ </Field>
18
+ </template>
19
+ ```
20
+
21
+ Click Message to focus the textarea, then type. Press Enter to start a new line.
22
+
23
+ ## Installation
24
+
25
+ ```bash
26
+ npm install @ui-sdk/vue @ui-sdk/core
27
+ ```
28
+
29
+ ## Usage
30
+
31
+ `Textarea` renders a native `<textarea>`. Pass `rows`, `placeholder`, `maxlength` and other native attributes directly.
32
+
33
+ ```vue
34
+ <script setup lang="ts">
35
+ import { Textarea } from "@ui-sdk/vue/textarea"
36
+ </script>
37
+
38
+ <template>
39
+ <Textarea aria-label="Message" placeholder="Type your message here…" />
40
+ </template>
41
+ ```
42
+
43
+ ## Field
44
+
45
+ Wrap the textarea in a [Field](./field.md) to give it a visible label and a description. The field also supplies its `name` when the textarea has none.
46
+
47
+ ```vue title="field.vue"
48
+ <script setup lang="ts">
49
+ import { Field, FieldDescription, FieldLabel } from "@ui-sdk/vue/field"
50
+ import { Textarea } from "@ui-sdk/vue/textarea"
51
+ </script>
52
+
53
+ <template>
54
+ <Field name="feedback">
55
+ <FieldLabel>Feedback</FieldLabel>
56
+ <Textarea placeholder="What could we do better?" />
57
+ <FieldDescription>Only the product team can see this.</FieldDescription>
58
+ </Field>
59
+ </template>
60
+ ```
61
+
62
+ Click Feedback to focus the textarea. A screen reader reads the description with the field.
63
+
64
+ ## Auto Resize
65
+
66
+ Set `auto-resize` to grow and shrink the textarea with its text. CSS `min-height` and `max-height` set its limits; past the maximum, the text scrolls inside it.
67
+
68
+ ```vue title="auto-resize.vue"
69
+ <script setup lang="ts">
70
+ import { Field, FieldDescription, FieldLabel } from "@ui-sdk/vue/field"
71
+ import { Textarea } from "@ui-sdk/vue/textarea"
72
+ </script>
73
+
74
+ <template>
75
+ <Field name="notes">
76
+ <FieldLabel>Notes</FieldLabel>
77
+ <Textarea auto-resize placeholder="Add notes for the delivery driver…" />
78
+ <FieldDescription>Your driver sees these notes.</FieldDescription>
79
+ </Field>
80
+ </template>
81
+ ```
82
+
83
+ Type several lines in Notes. The textarea grows with each line until it reaches its maximum height, then scrolls. Delete the lines and it shrinks back.
84
+
85
+ Browsers that support `field-sizing: content` size it natively. Elsewhere, the component measures it when the value changes, the form resets or its width changes.
86
+
87
+ ## Controlled
88
+
89
+ Bind `v-model:value`, or pass `value` and handle `@value-change`. Here the character count is derived from that value, and the native `maxlength` caps the text.
90
+
91
+ ```vue title="controlled.vue"
92
+ <script setup lang="ts">
93
+ import { Field, FieldDescription, FieldLabel } from "@ui-sdk/vue/field"
94
+ import { Textarea } from "@ui-sdk/vue/textarea"
95
+ import { ref } from "vue"
96
+
97
+ const bio = ref(
98
+ "Product designer in Lisbon. I write about type and interfaces."
99
+ )
100
+ </script>
101
+
102
+ <template>
103
+ <Field name="bio">
104
+ <FieldLabel>Bio</FieldLabel>
105
+ <Textarea v-model:value="bio" :maxlength="160" />
106
+ <FieldDescription>{{ bio.length }} / 160 characters</FieldDescription>
107
+ </Field>
108
+ </template>
109
+ ```
110
+
111
+ Edit Bio and watch the character count under it. The textarea stops accepting text at 160 characters.
112
+
113
+ Textarea shares Input's [change reasons](#reasons) and cancellation behavior. See [State and Events](../state-and-events.md) for the shared conventions.
114
+
115
+ ## Form
116
+
117
+ A textarea submits its value through a native form under its field's `name`. Pass a controller from `createInputController()` to change it from outside, here to empty it after sending. The native `required` constraint blocks an empty message.
118
+
119
+ ```vue title="button.vue"
120
+ <script setup lang="ts">
121
+ import { Field, FieldLabel } from "@ui-sdk/vue/field"
122
+ import { Textarea, createInputController } from "@ui-sdk/vue/textarea"
123
+ import { useLog } from "./log"
124
+
125
+ const log = useLog()
126
+ const message = createInputController()
127
+
128
+ function onSubmit(event: Event) {
129
+ const data = new FormData(event.currentTarget as HTMLFormElement)
130
+ log(`Sent “${data.get("message")}”`)
131
+ message.clear()
132
+ }
133
+ </script>
134
+
135
+ <template>
136
+ <form data-slot="stack" @submit.prevent="onSubmit">
137
+ <Field name="message">
138
+ <FieldLabel>Message</FieldLabel>
139
+ <Textarea :controller="message" required placeholder="Write a reply to Hollis Grant…" />
140
+ </Field>
141
+ <div data-slot="row">
142
+ <button type="submit" data-variant="solid">Send Message</button>
143
+ </div>
144
+ </form>
145
+ </template>
146
+ ```
147
+
148
+ Type a message and press Send Message. The console logs it and the textarea clears. Pressing Send Message while it's empty is blocked.
149
+
150
+ [Controllers](../controllers.md) covers creating and sharing a controller.
151
+
152
+ ## Disabled
153
+
154
+ Set `disabled` on the textarea or its field to prevent editing and leave it out of the tab order and the submitted values.
155
+
156
+ ```vue title="disabled.vue"
157
+ <script setup lang="ts">
158
+ import { Field, FieldLabel } from "@ui-sdk/vue/field"
159
+ import { Textarea } from "@ui-sdk/vue/textarea"
160
+ </script>
161
+
162
+ <template>
163
+ <Field disabled>
164
+ <FieldLabel>Reply</FieldLabel>
165
+ <Textarea default-value="Replies are closed for this thread." />
166
+ </Field>
167
+ </template>
168
+ ```
169
+
170
+ Try to edit Reply or reach it with Tab. The disabled textarea keeps its value but can't be changed.
171
+
172
+ ## Invalid
173
+
174
+ Set `invalid` on the field for an error your app decides. The field shows its error, associates it with the textarea and sets `aria-invalid`. [Field](./field.md#validation) covers native constraints and error matches.
175
+
176
+ ```vue title="invalid.vue"
177
+ <script setup lang="ts">
178
+ import { Field, FieldError, FieldLabel } from "@ui-sdk/vue/field"
179
+ import { Textarea } from "@ui-sdk/vue/textarea"
180
+ </script>
181
+
182
+ <template>
183
+ <Field invalid>
184
+ <FieldLabel>Review</FieldLabel>
185
+ <Textarea default-value="Great." />
186
+ <FieldError match>Write at least 20 characters.</FieldError>
187
+ </Field>
188
+ </template>
189
+ ```
190
+
191
+ Focus Review. The textarea is marked invalid, and the error below says how long the review should be.
192
+
193
+ ## Submit Shortcut
194
+
195
+ Set `submit-shortcut` to submit the textarea's form from the keyboard. With `"mod+enter"`, Enter still starts a new line and Command or Control+Enter submits. With `"enter"`, Enter submits and Shift+Enter starts a new line. Without it, Enter always starts a new line, and neither submits while an input method is composing.
196
+
197
+ ```vue
198
+ <script setup lang="ts">
199
+ import { Textarea } from "@ui-sdk/vue/textarea"
200
+ </script>
201
+
202
+ <template>
203
+ <form action="/messages" method="post">
204
+ <Textarea
205
+ name="message"
206
+ aria-label="Message"
207
+ required
208
+ submit-shortcut="mod+enter"
209
+ />
210
+ <button type="submit">Send</button>
211
+ </form>
212
+ </template>
213
+ ```
214
+
215
+ The shortcut submits like the Send button, so `required` and the form's `@submit` still apply. Listen for `@submit` on the textarea to handle the shortcut yourself instead: `@submit="(value) => …"` receives the value, and the form doesn't submit. Its first argument is the value, not an event, so there's nothing to prevent, and modifiers like `.prevent` don't apply.
216
+
217
+ ## Styling
218
+
219
+ Style the native textarea directly, with `data-filled`, `data-disabled`, `data-readonly` and `data-required` for its states. Inside a field it also receives the field's validation attributes, such as `data-invalid`. For `auto-resize`, set `min-height` and `max-height` to bound its growth. Use logical spacing so the text follows the surrounding direction.
220
+
221
+ The textarea has a `data-slot` of `textarea`, and its state attributes are listed under [Data Attributes](#data-attributes).
222
+
223
+ ## Data Attributes
224
+
225
+ ### Textarea
226
+ `[data-slot="textarea"]`
227
+
228
+ - `data-filled`: Present while the field holds any text.
229
+ - `data-disabled`: Present when the field is disabled, by its own prop or its Field.
230
+ - `data-readonly`: Present when the field is read-only.
231
+ - `data-required`: Present when the field is required.
232
+
233
+ ## API Reference
234
+
235
+ Props are the same as below, and callbacks are events, like `@value-change`. Native textarea attributes pass through.
236
+
237
+ ### Textarea
238
+
239
+ - `value?` (`string`): The value, for a controlled field.
240
+ - `defaultValue?` (`string`): The value it starts with. A form reset returns here.
241
+ - `@value-change` (`((value: string, details: ChangeDetails<InputValueChangeReason>) => void)`): Called when the user changes the value: typing (`"input-change"`), a Clear part (`"clear-press"`), a form reset (`"reset"`) or a controller (`"imperative"`). `details.cancel()` keeps the value as it was.
242
+ - `controller?` (`object`): Reads and writes the field from anywhere. Create one with `createInputController()`.
243
+ - `debug?` (`boolean`): Logs every state change with its reason to the console, in development builds.
244
+ - `autoResize?` (`boolean`): Grows and shrinks with the text. Bound it with CSS `min-height` and `max-height`; past the maximum, it scrolls.
245
+ - `@submit` (`((value: string, details: TextareaSubmitDetails) => void)`): Runs on the submit shortcut, unless an input method is composing. Without it, the shortcut submits the form the textarea is in. With neither, the key is left alone, so Enter adds a line.
246
+ - `submitShortcut?` (`"enter" | "mod+enter"`): Which keys submit: `"enter"`, with Shift+Enter for a new line, or `"mod+enter"`, with Enter for a new line. Without it, Enter always starts a new line.
247
+
248
+ - `disabled?` (`boolean`): Disables the field.
249
+ - `readOnly?` (`boolean`): Makes the field read-only.
250
+ - `required?` (`boolean`): Makes the field required.
251
+
252
+ ### State
253
+
254
+ - `filled` (`boolean`): Whether the field holds any text.
255
+ - `disabled` (`boolean`): Whether the field is disabled.
256
+ - `readOnly` (`boolean`): Whether the field is read-only.
257
+ - `required` (`boolean`): Whether the field is required.
258
+
259
+ ### Reasons
260
+
261
+ - `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.
262
+ - `clear-press` (`MouseEvent | KeyboardEvent`): A Clear part was pressed, like on an input, a select or a combobox.
263
+ - `reset` (`none`): A form reset.
264
+ - `imperative` (`none`): A controller or `api` call, or a property set on a web component.
265
+
266
+ ### Controller
267
+
268
+ Create one with `createInputController()` and pass it as `controller`.
269
+
270
+ - `getValue()` (`() => string`): The current value.
271
+ - `setValue(value, options?)` (`(value: string, options?: ChangeOptions<InputValueChangeReason> | undefined) => boolean`): Sets the value as if the user typed it, so `input` fires. Returns false when the change was canceled or nothing changed.
272
+ - `clear(options?)` (`(options?: ChangeOptions<InputValueChangeReason> | undefined) => boolean`): Empties the field, as if the user deleted the text, so `input` fires. Returns false when the change was canceled or nothing changed.
273
+ - `focus()` (`() => void`): Moves focus to the field.
274
+
275
+ ## Accessibility
276
+
277
+ There's no WAI-ARIA pattern for a multi-line text field. The textarea stays a native `<textarea>`, with standard text editing, selection, spell checking and form behavior. Give it a visible field label or an `aria-label`, and keep descriptions and errors in their field parts so they're associated with it.
278
+
279
+ ### Tested Behavior
280
+
281
+ Every line below is an automated test.
282
+
283
+ - The label names the textarea and the description describes it.
284
+
285
+ **Auto resize**
286
+
287
+ - Grows with its text and shrinks back.
288
+ - Stops at its max height and scrolls.
289
+ - Shrinks back when a reset empties it.
290
+ - Follows text written from code.
291
+
292
+ **Submit shortcut**
293
+
294
+ - Without a submit shortcut, Enter starts a new line and doesn't submit.
295
+ - With enter, Enter submits the form and Shift+Enter starts a new line.
296
+ - With mod+enter, Enter starts a new line and Cmd or Ctrl+Enter submits.
297
+ - Enter while an input method composes doesn't submit.
298
+
299
+ Runs in React, Vue and web components.
@@ -0,0 +1,224 @@
1
+ # Time Input
2
+
3
+ Type a time one part at a time, on the clock your user's language uses.
4
+
5
+ Use a Time Input for a time of day, like a meeting or an opening hour. It works like [Date Input](./date-input.md), with segments for the hour, the minute and, on a 12-hour clock, AM or PM.
6
+
7
+ ```vue title="time.vue"
8
+ <script setup lang="ts">
9
+ import { Field, FieldLabel } from "@ui-sdk/vue/field"
10
+ import { TimeInput } from "@ui-sdk/vue/time-input"
11
+ </script>
12
+
13
+ <template>
14
+ <Field>
15
+ <FieldLabel>Meeting time</FieldLabel>
16
+ <TimeInput default-value="09:30" />
17
+ </Field>
18
+ </template>
19
+ ```
20
+
21
+ Click the hour and type 230, then P. Press ArrowUp or ArrowDown on a part to step it.
22
+
23
+ ## Installation
24
+
25
+ ```bash
26
+ npm install @ui-sdk/vue @ui-sdk/core
27
+ ```
28
+
29
+ ## Composition
30
+
31
+ Use the following composition to build a `TimeInput`:
32
+
33
+ ```text
34
+ TimeInput
35
+ ├── TimeInputSegment
36
+ └── TimeInputSegment
37
+ ```
38
+
39
+ `TimeInput` renders a group with one `TimeInputSegment` for each part of the time, and the text between them.
40
+
41
+ ## Usage
42
+
43
+ Put the input in a [Field](./field.md) and give it a label:
44
+
45
+ ```vue
46
+ <script setup lang="ts">
47
+ import { Field, FieldLabel } from "@ui-sdk/vue/field"
48
+ import { TimeInput } from "@ui-sdk/vue/time-input"
49
+ </script>
50
+
51
+ <template>
52
+ <Field>
53
+ <FieldLabel>Meeting time</FieldLabel>
54
+ <TimeInput default-value="09:30" />
55
+ </Field>
56
+ </template>
57
+ ```
58
+
59
+ The value is a 24-hour time like `"14:30"`, the same as a native time input's, whatever clock the input shows. Typing, stepping and pasting work as they do in [Date Input](./date-input.md#usage).
60
+
61
+ ## Clock and Seconds
62
+
63
+ The input shows the locale's clock. Set `hour-cycle` to `12` or `24` to choose one, and `granularity` to `"second"` to add seconds, or `"hour"` to show the hour alone.
64
+
65
+ ```vue title="hour-cycle.vue"
66
+ <script setup lang="ts">
67
+ import { Field, FieldLabel } from "@ui-sdk/vue/field"
68
+ import { TimeInput } from "@ui-sdk/vue/time-input"
69
+ </script>
70
+
71
+ <template>
72
+ <div data-slot="stack">
73
+ <Field>
74
+ <FieldLabel>12-hour clock</FieldLabel>
75
+ <TimeInput :hour-cycle="12" default-value="18:45" />
76
+ </Field>
77
+ <Field>
78
+ <FieldLabel>24-hour clock</FieldLabel>
79
+ <TimeInput :hour-cycle="24" default-value="18:45" />
80
+ </Field>
81
+ <Field>
82
+ <FieldLabel>With seconds</FieldLabel>
83
+ <TimeInput granularity="second" :hour-cycle="24" default-value="18:45:30" />
84
+ </Field>
85
+ </div>
86
+ </template>
87
+ ```
88
+
89
+ The same evening time on a 12-hour clock, a 24-hour clock and with seconds. All three submit 24-hour values.
90
+
91
+ ## Min and Max
92
+
93
+ `min` and `max` take times like `"09:00"`. A time outside them is invalid: the input sets `data-invalid`, and its form won't submit.
94
+
95
+ ## Form
96
+
97
+ A hidden input submits the time under `name`. Set `required` to need a time before the form submits, and `form` to the id of a form elsewhere in the page to submit with it. The [Date Input form example](./date-input.md#form) has a time in it.
98
+
99
+ ## Controlled and Controller
100
+
101
+ Bind `v-model:value`, or drive the input with `createTimeInputController()`, as in [Date Input](./date-input.md#controlled).
102
+
103
+ ## Styling
104
+
105
+ Style it like [Date Input](./date-input.md#styling). The AM/PM segment sets `data-type="dayPeriod"`.
106
+
107
+ Each part has a `data-slot`, such as `time-input-segment`, and its state attributes are listed under [Data Attributes](#data-attributes).
108
+
109
+ ## Data Attributes
110
+
111
+ ### TimeInput
112
+ `[data-slot="time-input"]`
113
+
114
+ - `data-disabled`: Present when disabled, by its own prop or a `<fieldset>`.
115
+ - `data-readonly`: Present when read-only.
116
+ - `data-required`: Present when required.
117
+ - `data-invalid`: Present while the time is before `min` or after `max`.
118
+ - `data-empty`: Present while every segment is empty.
119
+
120
+ ### TimeInputSegment
121
+ `[data-slot="time-input-segment"]`
122
+
123
+ - `data-type` (`hour`, `minute`, `second`, `dayPeriod`, `literal`): The segment's unit, or `literal` for the text between segments.
124
+ - `data-disabled`: Present when disabled, by its own prop or a `<fieldset>`.
125
+ - `data-readonly`: Present when read-only.
126
+ - `data-required`: Present when required.
127
+ - `data-invalid`: Present while the time is before `min` or after `max`.
128
+ - `data-empty`: Present while the segment is empty. It shows its placeholder.
129
+
130
+ ## API Reference
131
+
132
+ Props are the same as below, in kebab case in templates, and callbacks are events.
133
+
134
+ ### TimeInput
135
+
136
+ - `value?` (`string | null`): The value: a time like `"14:30"`, or `"14:30:15"` with seconds, or `null`. Pass it to control the input.
137
+ - `defaultValue?` (`string | null`): The value it starts with, when uncontrolled, and goes back to when its form resets.
138
+ - `@value-change` (`((value: string | null, details: ChangeDetails<TimeInputValueChangeReason>) => void)`): Runs when the value wants to change: once every segment holds something, and again with `null` when one is emptied. `details.cancel()` keeps the value.
139
+ - `granularity?` (`TimeInputGranularity`): The smallest unit it shows.
140
+ - `hourCycle?` (`HourCycle`): A 12 or 24 hour clock. Defaults to the locale's.
141
+ - `min?` (`string`): The earliest time, like `"09:00"`. A time before it is invalid.
142
+ - `max?` (`string`): The latest time, like `"17:30"`. A time after it is invalid.
143
+ - `locale?` (`string`): The language whose separators and clock it shows. Defaults to the page's.
144
+ - `disabled?` (`boolean`): Whether it can't be used.
145
+ - `readOnly?` (`boolean`): Whether the value can be seen but not changed.
146
+ - `required?` (`boolean`): Whether a time must be entered before its form submits.
147
+ - `name?` (`string`): The name the value submits under.
148
+ - `form?` (`string`): The id of the form it belongs to, when it isn't inside it.
149
+ - `controller?` (`object`): Drives it from anywhere. Create one with `createTimeInputController()`.
150
+ - `debug?` (`boolean`): Logs every state change with its reason to the console, in development builds.
151
+
152
+ ### State
153
+
154
+ - `value` (`string | null`): The value, or `null` while empty or partly filled.
155
+ - `segments` (`DateInputSegmentData[]`): The segments in the order the locale shows them, with the text between them. Render one part for each.
156
+ - `disabled` (`boolean`): Whether it can't be used, by itself or by a `<fieldset>`.
157
+ - `readOnly` (`boolean`): Whether the value can be seen but not changed.
158
+ - `invalid` (`boolean`): Whether the value is before `min`, after `max` or an unavailable date.
159
+
160
+ ### Reasons
161
+
162
+ - `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.
163
+ - `step-key` (`KeyboardEvent`): Arrow, Page Up, Page Down, Home or End stepped a slider or a number input.
164
+ - `paste` (`ClipboardEvent`): Files were pasted, like a screenshot, or text and tokens into a token input.
165
+ - `reset` (`none`): A form reset.
166
+ - `restore` (`none`): The browser restored state, like after going back, or a saved value was read back from storage.
167
+ - `imperative` (`none`): A controller or `api` call, or a property set on a web component.
168
+
169
+ ### Controller
170
+
171
+ - `getValue()` (`() => string | null`): The value, or `null` while empty or partly filled.
172
+ - `setValue(value, options?)` (`(value: string | null, options?: DateInputChangeOptions | undefined) => boolean`): Sets the value. Returns false when it isn't a value the input can show, or when canceled.
173
+ - `clear(options?)` (`(options?: DateInputChangeOptions | undefined) => boolean`): Empties every segment.
174
+ - `focus(segment?)` (`(segment?: string | undefined) => void`): Focuses a segment, like `"month"`, or the first one.
175
+
176
+ ### Events
177
+
178
+ Events get the new value first, then the details. `v-model:value` only updates when the change wasn't canceled.
179
+
180
+ | Binding | On | Receives |
181
+ | --------------- | ----------- | ---------------------------------------------------------------------------------- |
182
+ | `v-model:value` | `TimeInput` | The time, or null while empty or partly typed |
183
+ | `@value-change` | `TimeInput` | `(value, details)`: the time, or null once it's erased, and the [reason](#reasons) |
184
+
185
+ ## Accessibility
186
+
187
+ The root is a group, named by its Field's label or by your `aria-label`. Each segment is a spinbutton named by its unit, like "hour" or "AM/PM", with its value, range and text. The keys are the same as in [Date Input](./date-input.md#keyboard).
188
+
189
+ ### Tested Behavior
190
+
191
+ Every line below is an automated test.
192
+
193
+ - Each unit is a spinbutton in the locale's order.
194
+ - Another locale orders the segments its own way.
195
+ - Typing fills each segment, moves on and reports the date once.
196
+ - A press on the box or between segments focuses the nearest segment.
197
+ - A digit that can't start a longer number moves on at once.
198
+ - A separator moves to the next segment.
199
+ - Typing with separators over a filled date or time keeps every segment.
200
+ - ArrowUp and ArrowDown step a segment and wrap around.
201
+ - PageUp and PageDown take bigger steps.
202
+ - Home and End go to a segment's first and last values.
203
+ - ArrowLeft and ArrowRight move between segments.
204
+ - Tab moves through the segments, then out.
205
+ - Backspace empties a segment, then moves back.
206
+ - A day past the end of a new month is moved back to its last day.
207
+ - Pasting a date fills every segment.
208
+ - A time takes hours, minutes and AM or PM.
209
+ - A 24-hour clock has no AM or PM.
210
+ - A date with a time shows its hour and minute too.
211
+ - A controller sets and clears the date.
212
+ - A canceled change keeps the date.
213
+ - The form submits the ISO date and time under their names.
214
+ - Enter submits the form with what was typed.
215
+ - Resetting the form brings back the default date.
216
+ - A partly filled date can't be submitted.
217
+ - A required empty date can't be submitted.
218
+ - A date after max is invalid.
219
+ - An unavailable date is invalid.
220
+ - The field's label focuses the first segment.
221
+ - A read-only date takes focus but doesn't change.
222
+ - A disabled date can't be focused.
223
+
224
+ Runs in React, Vue and web components.