@ui-sdk/react 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.
- package/LICENSE +202 -0
- package/README.md +10 -2
- package/dist/accordion.d.ts +331 -0
- package/dist/accordion.js +25 -0
- package/dist/agent.d.ts +2 -0
- package/dist/agent.js +8 -0
- package/dist/alert-dialog.d.ts +56 -0
- package/dist/alert-dialog.js +45 -0
- package/dist/async-options.d.ts +22 -0
- package/dist/async-options.js +56 -0
- package/dist/autocomplete.d.ts +102 -0
- package/dist/autocomplete.js +195 -0
- package/dist/avatar.d.ts +301 -0
- package/dist/avatar.js +17 -0
- package/dist/button.d.ts +21 -0
- package/dist/button.js +45 -0
- package/dist/calendar-context.d.ts +10 -0
- package/dist/calendar-context.js +9 -0
- package/dist/calendar.d.ts +80 -0
- package/dist/calendar.js +257 -0
- package/dist/carousel.d.ts +52 -0
- package/dist/carousel.js +151 -0
- package/dist/checkbox.d.ts +24 -0
- package/dist/checkbox.js +98 -0
- package/dist/children.d.ts +38 -0
- package/dist/children.js +63 -0
- package/dist/collapsible.d.ts +302 -0
- package/dist/collapsible.js +19 -0
- package/dist/color-picker.d.ts +72 -0
- package/dist/color-picker.js +133 -0
- package/dist/color.d.ts +2 -0
- package/dist/color.js +22 -0
- package/dist/combobox.d.ts +152 -0
- package/dist/combobox.js +338 -0
- package/dist/command.d.ts +88 -0
- package/dist/command.js +233 -0
- package/dist/controller-target.d.ts +3 -0
- package/dist/controller-target.js +59 -0
- package/dist/date-input.d.ts +19 -0
- package/dist/date-input.js +58 -0
- package/dist/date-picker.d.ts +47 -0
- package/dist/date-picker.js +310 -0
- package/dist/date.d.ts +2 -0
- package/dist/date.js +60 -0
- package/dist/dialog-parts.d.ts +23 -0
- package/dist/dialog-parts.js +142 -0
- package/dist/dialog.d.ts +57 -0
- package/dist/dialog.js +32 -0
- package/dist/drawer.d.ts +70 -0
- package/dist/drawer.js +158 -0
- package/dist/editor-context.d.ts +4 -0
- package/dist/editor-context.js +9 -0
- package/dist/field-context.d.ts +47 -0
- package/dist/field-context.js +87 -0
- package/dist/field.d.ts +49 -0
- package/dist/field.js +169 -0
- package/dist/file-input.d.ts +46 -0
- package/dist/file-input.js +170 -0
- package/dist/form-inputs.d.ts +5 -0
- package/dist/form-inputs.js +22 -0
- package/dist/gesture.d.ts +1 -0
- package/dist/gesture.js +16 -0
- package/dist/history.d.ts +2 -0
- package/dist/history.js +12 -0
- package/dist/hover-card.d.ts +33 -0
- package/dist/hover-card.js +84 -0
- package/dist/image-cropper.d.ts +333 -0
- package/dist/image-cropper.js +37 -0
- package/dist/image.d.ts +2 -0
- package/dist/image.js +6 -0
- package/dist/input.d.ts +22 -0
- package/dist/input.js +51 -0
- package/dist/label.d.ts +294 -0
- package/dist/label.js +9 -0
- package/dist/list-items.d.ts +15 -0
- package/dist/list-items.js +39 -0
- package/dist/list-text.d.ts +4 -0
- package/dist/list-text.js +15 -0
- package/dist/listbox.d.ts +56 -0
- package/dist/listbox.js +122 -0
- package/dist/menu.d.ts +116 -0
- package/dist/menu.js +426 -0
- package/dist/menubar-context.d.ts +4 -0
- package/dist/menubar-context.js +7 -0
- package/dist/menubar.d.ts +11 -0
- package/dist/menubar.js +32 -0
- package/dist/meter.d.ts +312 -0
- package/dist/meter.js +30 -0
- package/dist/navigation-menu.d.ts +61 -0
- package/dist/navigation-menu.js +169 -0
- package/dist/number-input.d.ts +44 -0
- package/dist/number-input.js +185 -0
- package/dist/number.d.ts +2 -0
- package/dist/number.js +40 -0
- package/dist/observe.d.ts +2 -0
- package/dist/observe.js +8 -0
- package/dist/otp-input.d.ts +29 -0
- package/dist/otp-input.js +94 -0
- package/dist/overlays.d.ts +26 -0
- package/dist/overlays.js +82 -0
- package/dist/pagination.d.ts +336 -0
- package/dist/pagination.js +71 -0
- package/dist/password-input.d.ts +23 -0
- package/dist/password-input.js +65 -0
- package/dist/popover.d.ts +54 -0
- package/dist/popover.js +151 -0
- package/dist/popup.d.ts +41 -0
- package/dist/popup.js +180 -0
- package/dist/preferences.d.ts +35 -0
- package/dist/preferences.js +93 -0
- package/dist/primitive.d.ts +2 -0
- package/dist/primitive.js +14 -0
- package/dist/progress.d.ts +312 -0
- package/dist/progress.js +30 -0
- package/dist/radio.d.ts +22 -0
- package/dist/radio.js +86 -0
- package/dist/rating.d.ts +20 -0
- package/dist/rating.js +94 -0
- package/dist/render-element.d.ts +35 -0
- package/dist/render-element.js +103 -0
- package/dist/resizable.d.ts +302 -0
- package/dist/resizable.js +23 -0
- package/dist/scroll-area.d.ts +324 -0
- package/dist/scroll-area.js +49 -0
- package/dist/segmented-control.d.ts +24 -0
- package/dist/segmented-control.js +78 -0
- package/dist/segmented-input.d.ts +15 -0
- package/dist/segmented-input.js +48 -0
- package/dist/select.d.ts +125 -0
- package/dist/select.js +330 -0
- package/dist/separator.d.ts +290 -0
- package/dist/separator.js +9 -0
- package/dist/shortcuts.d.ts +32 -0
- package/dist/shortcuts.js +61 -0
- package/dist/slider.d.ts +38 -0
- package/dist/slider.js +163 -0
- package/dist/switch.d.ts +15 -0
- package/dist/switch.js +39 -0
- package/dist/tabs.d.ts +331 -0
- package/dist/tabs.js +28 -0
- package/dist/text-control.d.ts +22 -0
- package/dist/text-control.js +24 -0
- package/dist/text-match.d.ts +2 -0
- package/dist/text-match.js +8 -0
- package/dist/textarea.d.ts +10 -0
- package/dist/textarea.js +48 -0
- package/dist/time-input.d.ts +19 -0
- package/dist/time-input.js +63 -0
- package/dist/timeline.d.ts +327 -0
- package/dist/timeline.js +31 -0
- package/dist/toast-parts.d.ts +63 -0
- package/dist/toast-parts.js +144 -0
- package/dist/toast.d.ts +2 -0
- package/dist/toast.js +22 -0
- package/dist/toggle.d.ts +23 -0
- package/dist/toggle.js +76 -0
- package/dist/token-input.d.ts +35 -0
- package/dist/token-input.js +100 -0
- package/dist/toolbar-context.d.ts +6 -0
- package/dist/toolbar-context.js +16 -0
- package/dist/toolbar.d.ts +38 -0
- package/dist/toolbar.js +63 -0
- package/dist/tooltip.d.ts +39 -0
- package/dist/tooltip.js +108 -0
- package/dist/tree.d.ts +51 -0
- package/dist/tree.js +150 -0
- package/dist/trigger-menu.d.ts +83 -0
- package/dist/trigger-menu.js +167 -0
- package/dist/use-primitive.d.ts +178 -0
- package/dist/use-primitive.js +674 -0
- package/dist/waterfall.d.ts +80 -0
- package/dist/waterfall.js +108 -0
- package/docs/README.md +89 -0
- package/docs/agents.md +1523 -0
- package/docs/components/accordion.md +1391 -0
- package/docs/components/alert-dialog.md +850 -0
- package/docs/components/autocomplete.md +1963 -0
- package/docs/components/avatar.md +252 -0
- package/docs/components/button.md +444 -0
- package/docs/components/calendar.md +1687 -0
- package/docs/components/carousel.md +1244 -0
- package/docs/components/checkbox.md +1069 -0
- package/docs/components/collapsible.md +567 -0
- package/docs/components/color-picker.md +736 -0
- package/docs/components/combobox.md +3647 -0
- package/docs/components/command.md +1573 -0
- package/docs/components/date-input.md +608 -0
- package/docs/components/date-picker.md +1266 -0
- package/docs/components/dialog.md +1469 -0
- package/docs/components/drawer.md +1197 -0
- package/docs/components/field.md +549 -0
- package/docs/components/file-input.md +609 -0
- package/docs/components/hover-card.md +514 -0
- package/docs/components/image-cropper.md +579 -0
- package/docs/components/input.md +301 -0
- package/docs/components/label.md +217 -0
- package/docs/components/listbox.md +1130 -0
- package/docs/components/menu.md +1286 -0
- package/docs/components/menubar.md +455 -0
- package/docs/components/meter.md +304 -0
- package/docs/components/navigation-menu.md +1581 -0
- package/docs/components/number-input.md +1086 -0
- package/docs/components/otp-input.md +565 -0
- package/docs/components/pagination.md +648 -0
- package/docs/components/password-input.md +737 -0
- package/docs/components/popover.md +1552 -0
- package/docs/components/preferences.md +220 -0
- package/docs/components/progress.md +443 -0
- package/docs/components/radio.md +846 -0
- package/docs/components/rating.md +458 -0
- package/docs/components/resizable.md +982 -0
- package/docs/components/scroll-area.md +980 -0
- package/docs/components/segmented-control.md +465 -0
- package/docs/components/select.md +2133 -0
- package/docs/components/separator.md +243 -0
- package/docs/components/slider.md +1169 -0
- package/docs/components/switch.md +613 -0
- package/docs/components/tabs.md +1014 -0
- package/docs/components/textarea.md +318 -0
- package/docs/components/time-input.md +231 -0
- package/docs/components/timeline.md +677 -0
- package/docs/components/toast.md +1395 -0
- package/docs/components/toggle.md +541 -0
- package/docs/components/token-input.md +1007 -0
- package/docs/components/toolbar.md +787 -0
- package/docs/components/tooltip.md +884 -0
- package/docs/components/tree.md +1346 -0
- package/docs/components/trigger-menu.md +1257 -0
- package/docs/components/waterfall.md +754 -0
- package/docs/controllers.md +89 -0
- package/docs/core.md +8027 -0
- package/docs/custom-parts.md +120 -0
- package/docs/first-component.md +83 -0
- package/docs/forms.md +148 -0
- package/docs/hooks/async-options.md +366 -0
- package/docs/hooks/shortcuts.md +221 -0
- package/docs/installation.md +45 -0
- package/docs/introduction.md +32 -0
- package/docs/lists-and-menus.md +170 -0
- package/docs/llms.txt +1844 -0
- package/docs/parts-and-composition.md +93 -0
- package/docs/popups.md +117 -0
- package/docs/rendering.md +121 -0
- package/docs/server-rendering.md +253 -0
- package/docs/state-and-events.md +105 -0
- package/docs/styling-and-animation.md +176 -0
- package/package.json +333 -3
|
@@ -0,0 +1,318 @@
|
|
|
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
|
+
```tsx title="basic.tsx"
|
|
8
|
+
import { Field, FieldLabel } from "@ui-sdk/react/field"
|
|
9
|
+
import { Textarea } from "@ui-sdk/react/textarea"
|
|
10
|
+
|
|
11
|
+
function Example() {
|
|
12
|
+
return (
|
|
13
|
+
<Field name="message">
|
|
14
|
+
<FieldLabel>Message</FieldLabel>
|
|
15
|
+
<Textarea placeholder="Type your message here…" />
|
|
16
|
+
</Field>
|
|
17
|
+
)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export { Example }
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Click Message to focus the textarea, then type. Press Enter to start a new line.
|
|
24
|
+
|
|
25
|
+
## Installation
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
npm install @ui-sdk/react @ui-sdk/core
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Usage
|
|
32
|
+
|
|
33
|
+
`Textarea` renders a native `<textarea>`. Pass `rows`, `placeholder`, `maxLength` and other native attributes directly.
|
|
34
|
+
|
|
35
|
+
```tsx
|
|
36
|
+
import { Textarea } from "@ui-sdk/react/textarea"
|
|
37
|
+
|
|
38
|
+
function Example() {
|
|
39
|
+
return <Textarea aria-label="Message" placeholder="Type your message here…" />
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export { Example }
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Field
|
|
46
|
+
|
|
47
|
+
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.
|
|
48
|
+
|
|
49
|
+
```tsx title="field.tsx"
|
|
50
|
+
import { Field, FieldDescription, FieldLabel } from "@ui-sdk/react/field"
|
|
51
|
+
import { Textarea } from "@ui-sdk/react/textarea"
|
|
52
|
+
|
|
53
|
+
function Example() {
|
|
54
|
+
return (
|
|
55
|
+
<Field name="feedback">
|
|
56
|
+
<FieldLabel>Feedback</FieldLabel>
|
|
57
|
+
<Textarea placeholder="What could we do better?" />
|
|
58
|
+
<FieldDescription>Only the product team can see this.</FieldDescription>
|
|
59
|
+
</Field>
|
|
60
|
+
)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export { Example }
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Click Feedback to focus the textarea. A screen reader reads the description with the field.
|
|
67
|
+
|
|
68
|
+
## Auto Resize
|
|
69
|
+
|
|
70
|
+
Set `autoResize` 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.
|
|
71
|
+
|
|
72
|
+
```tsx title="auto-resize.tsx"
|
|
73
|
+
import { Field, FieldDescription, FieldLabel } from "@ui-sdk/react/field"
|
|
74
|
+
import { Textarea } from "@ui-sdk/react/textarea"
|
|
75
|
+
|
|
76
|
+
function Example() {
|
|
77
|
+
return (
|
|
78
|
+
<Field name="notes">
|
|
79
|
+
<FieldLabel>Notes</FieldLabel>
|
|
80
|
+
<Textarea autoResize placeholder="Add notes for the delivery driver…" />
|
|
81
|
+
<FieldDescription>Your driver sees these notes.</FieldDescription>
|
|
82
|
+
</Field>
|
|
83
|
+
)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export { Example }
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
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.
|
|
90
|
+
|
|
91
|
+
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.
|
|
92
|
+
|
|
93
|
+
## Controlled
|
|
94
|
+
|
|
95
|
+
Keep `value` in state and update it with `onValueChange`. Here the character count is derived from that value, and the native `maxLength` caps the text.
|
|
96
|
+
|
|
97
|
+
```tsx title="controlled.tsx"
|
|
98
|
+
import { Field, FieldDescription, FieldLabel } from "@ui-sdk/react/field"
|
|
99
|
+
import { Textarea } from "@ui-sdk/react/textarea"
|
|
100
|
+
import * as React from "react"
|
|
101
|
+
|
|
102
|
+
function Example() {
|
|
103
|
+
const [bio, setBio] = React.useState(
|
|
104
|
+
"Product designer in Lisbon. I write about type and interfaces."
|
|
105
|
+
)
|
|
106
|
+
return (
|
|
107
|
+
<Field name="bio">
|
|
108
|
+
<FieldLabel>Bio</FieldLabel>
|
|
109
|
+
<Textarea value={bio} onValueChange={setBio} maxLength={160} />
|
|
110
|
+
<FieldDescription>{bio.length} / 160 characters</FieldDescription>
|
|
111
|
+
</Field>
|
|
112
|
+
)
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export { Example }
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
Edit Bio and watch the character count under it. The textarea stops accepting text at 160 characters.
|
|
119
|
+
|
|
120
|
+
Textarea shares Input's [change reasons](#reasons) and cancellation behavior. See [State and Events](../state-and-events.md) for the shared conventions.
|
|
121
|
+
|
|
122
|
+
## Form
|
|
123
|
+
|
|
124
|
+
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.
|
|
125
|
+
|
|
126
|
+
```tsx title="button.tsx"
|
|
127
|
+
import { Field, FieldLabel } from "@ui-sdk/react/field"
|
|
128
|
+
import { Textarea, createInputController } from "@ui-sdk/react/textarea"
|
|
129
|
+
import * as React from "react"
|
|
130
|
+
import { useLog } from "./log"
|
|
131
|
+
|
|
132
|
+
function Example() {
|
|
133
|
+
const log = useLog()
|
|
134
|
+
const [message] = React.useState(createInputController)
|
|
135
|
+
return (
|
|
136
|
+
<form
|
|
137
|
+
data-slot="stack"
|
|
138
|
+
onSubmit={(event) => {
|
|
139
|
+
event.preventDefault()
|
|
140
|
+
const data = new FormData(event.currentTarget)
|
|
141
|
+
log(`Sent “${data.get("message")}”`)
|
|
142
|
+
message.clear()
|
|
143
|
+
}}
|
|
144
|
+
>
|
|
145
|
+
<Field name="message">
|
|
146
|
+
<FieldLabel>Message</FieldLabel>
|
|
147
|
+
<Textarea controller={message} required placeholder="Write a reply to Hollis Grant…" />
|
|
148
|
+
</Field>
|
|
149
|
+
<div data-slot="row">
|
|
150
|
+
<button type="submit" data-variant="solid">
|
|
151
|
+
Send Message
|
|
152
|
+
</button>
|
|
153
|
+
</div>
|
|
154
|
+
</form>
|
|
155
|
+
)
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export { Example }
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
Type a message and press Send Message. The console logs it and the textarea clears. Pressing Send Message while it's empty is blocked.
|
|
162
|
+
|
|
163
|
+
[Controllers](../controllers.md) covers creating and sharing a controller.
|
|
164
|
+
|
|
165
|
+
## Disabled
|
|
166
|
+
|
|
167
|
+
Set `disabled` on the textarea or its field to prevent editing and leave it out of the tab order and the submitted values.
|
|
168
|
+
|
|
169
|
+
```tsx title="disabled.tsx"
|
|
170
|
+
import { Field, FieldLabel } from "@ui-sdk/react/field"
|
|
171
|
+
import { Textarea } from "@ui-sdk/react/textarea"
|
|
172
|
+
|
|
173
|
+
function Example() {
|
|
174
|
+
return (
|
|
175
|
+
<Field disabled>
|
|
176
|
+
<FieldLabel>Reply</FieldLabel>
|
|
177
|
+
<Textarea defaultValue="Replies are closed for this thread." />
|
|
178
|
+
</Field>
|
|
179
|
+
)
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export { Example }
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
Try to edit Reply or reach it with Tab. The disabled textarea keeps its value but can't be changed.
|
|
186
|
+
|
|
187
|
+
## Invalid
|
|
188
|
+
|
|
189
|
+
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.
|
|
190
|
+
|
|
191
|
+
```tsx title="invalid.tsx"
|
|
192
|
+
import { Field, FieldError, FieldLabel } from "@ui-sdk/react/field"
|
|
193
|
+
import { Textarea } from "@ui-sdk/react/textarea"
|
|
194
|
+
|
|
195
|
+
function Example() {
|
|
196
|
+
return (
|
|
197
|
+
<Field invalid>
|
|
198
|
+
<FieldLabel>Review</FieldLabel>
|
|
199
|
+
<Textarea defaultValue="Great." />
|
|
200
|
+
<FieldError match>Write at least 20 characters.</FieldError>
|
|
201
|
+
</Field>
|
|
202
|
+
)
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export { Example }
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
Focus Review. The textarea is marked invalid, and the error below says how long the review should be.
|
|
209
|
+
|
|
210
|
+
## Submit Shortcut
|
|
211
|
+
|
|
212
|
+
Set `submitShortcut` 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.
|
|
213
|
+
|
|
214
|
+
```tsx
|
|
215
|
+
import { Textarea } from "@ui-sdk/react/textarea"
|
|
216
|
+
|
|
217
|
+
function Example() {
|
|
218
|
+
return (
|
|
219
|
+
<form action="/messages" method="post">
|
|
220
|
+
<Textarea
|
|
221
|
+
name="message"
|
|
222
|
+
aria-label="Message"
|
|
223
|
+
required
|
|
224
|
+
submitShortcut="mod+enter"
|
|
225
|
+
/>
|
|
226
|
+
<button type="submit">Send</button>
|
|
227
|
+
</form>
|
|
228
|
+
)
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
export { Example }
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
The shortcut submits like the Send button, so `required` and the form's `onSubmit` still apply. Pass `onSubmit` to the textarea to handle the shortcut yourself instead. It receives the value, and the form doesn't submit.
|
|
235
|
+
|
|
236
|
+
## Styling
|
|
237
|
+
|
|
238
|
+
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 `autoResize`, set `min-height` and `max-height` to bound its growth. Use logical spacing so the text follows the surrounding direction.
|
|
239
|
+
|
|
240
|
+
The textarea has a `data-slot` of `textarea`, and its state attributes are listed under [Data Attributes](#data-attributes).
|
|
241
|
+
|
|
242
|
+
## Data Attributes
|
|
243
|
+
|
|
244
|
+
### Textarea
|
|
245
|
+
`[data-slot="textarea"]`
|
|
246
|
+
|
|
247
|
+
- `data-filled`: Present while the field holds any text.
|
|
248
|
+
- `data-disabled`: Present when the field is disabled, by its own prop or its Field.
|
|
249
|
+
- `data-readonly`: Present when the field is read-only.
|
|
250
|
+
- `data-required`: Present when the field is required.
|
|
251
|
+
|
|
252
|
+
## API Reference
|
|
253
|
+
|
|
254
|
+
Props are the same as below, as React props, plus every native textarea prop.
|
|
255
|
+
|
|
256
|
+
### Textarea
|
|
257
|
+
|
|
258
|
+
- `value?` (`string`): The value, for a controlled field.
|
|
259
|
+
- `defaultValue?` (`string`): The value it starts with. A form reset returns here.
|
|
260
|
+
- `onValueChange?` (`((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.
|
|
261
|
+
- `controller?` (`object`): Reads and writes the field from anywhere. Create one with `createInputController()`.
|
|
262
|
+
- `debug?` (`boolean`): Logs every state change with its reason to the console, in development builds.
|
|
263
|
+
- `autoResize?` (`boolean`): Grows and shrinks with the text. Bound it with CSS `min-height` and `max-height`; past the maximum, it scrolls.
|
|
264
|
+
- `onSubmit?` (`((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.
|
|
265
|
+
- `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.
|
|
266
|
+
|
|
267
|
+
- `disabled?` (`boolean`): Disables the field.
|
|
268
|
+
- `readOnly?` (`boolean`): Makes the field read-only.
|
|
269
|
+
- `required?` (`boolean`): Makes the field required.
|
|
270
|
+
|
|
271
|
+
### State
|
|
272
|
+
|
|
273
|
+
- `filled` (`boolean`): Whether the field holds any text.
|
|
274
|
+
- `disabled` (`boolean`): Whether the field is disabled.
|
|
275
|
+
- `readOnly` (`boolean`): Whether the field is read-only.
|
|
276
|
+
- `required` (`boolean`): Whether the field is required.
|
|
277
|
+
|
|
278
|
+
### Reasons
|
|
279
|
+
|
|
280
|
+
- `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.
|
|
281
|
+
- `clear-press` (`MouseEvent | KeyboardEvent`): A Clear part was pressed, like on an input, a select or a combobox.
|
|
282
|
+
- `reset` (`none`): A form reset.
|
|
283
|
+
- `imperative` (`none`): A controller or `api` call, or a property set on a web component.
|
|
284
|
+
|
|
285
|
+
### Controller
|
|
286
|
+
|
|
287
|
+
Create one with `createInputController()` and pass it as `controller`.
|
|
288
|
+
|
|
289
|
+
- `getValue()` (`() => string`): The current value.
|
|
290
|
+
- `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.
|
|
291
|
+
- `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.
|
|
292
|
+
- `focus()` (`() => void`): Moves focus to the field.
|
|
293
|
+
|
|
294
|
+
## Accessibility
|
|
295
|
+
|
|
296
|
+
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.
|
|
297
|
+
|
|
298
|
+
### Tested Behavior
|
|
299
|
+
|
|
300
|
+
Every line below is an automated test.
|
|
301
|
+
|
|
302
|
+
- The label names the textarea and the description describes it.
|
|
303
|
+
|
|
304
|
+
**Auto resize**
|
|
305
|
+
|
|
306
|
+
- Grows with its text and shrinks back.
|
|
307
|
+
- Stops at its max height and scrolls.
|
|
308
|
+
- Shrinks back when a reset empties it.
|
|
309
|
+
- Follows text written from code.
|
|
310
|
+
|
|
311
|
+
**Submit shortcut**
|
|
312
|
+
|
|
313
|
+
- Without a submit shortcut, Enter starts a new line and doesn't submit.
|
|
314
|
+
- With enter, Enter submits the form and Shift+Enter starts a new line.
|
|
315
|
+
- With mod+enter, Enter starts a new line and Cmd or Ctrl+Enter submits.
|
|
316
|
+
- Enter while an input method composes doesn't submit.
|
|
317
|
+
|
|
318
|
+
Runs in React, Vue and web components.
|
|
@@ -0,0 +1,231 @@
|
|
|
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
|
+
```tsx title="time.tsx"
|
|
8
|
+
"use client"
|
|
9
|
+
|
|
10
|
+
import { Field, FieldLabel } from "@ui-sdk/react/field"
|
|
11
|
+
import { TimeInput } from "@ui-sdk/react/time-input"
|
|
12
|
+
|
|
13
|
+
function Example() {
|
|
14
|
+
return (
|
|
15
|
+
<Field>
|
|
16
|
+
<FieldLabel>Meeting time</FieldLabel>
|
|
17
|
+
<TimeInput defaultValue="09:30" />
|
|
18
|
+
</Field>
|
|
19
|
+
)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { Example }
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Click the hour and type 230, then P. Press ArrowUp or ArrowDown on a part to step it.
|
|
26
|
+
|
|
27
|
+
## Installation
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
npm install @ui-sdk/react @ui-sdk/core
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Composition
|
|
34
|
+
|
|
35
|
+
Use the following composition to build a `TimeInput`:
|
|
36
|
+
|
|
37
|
+
```text
|
|
38
|
+
TimeInput
|
|
39
|
+
├── TimeInputSegment
|
|
40
|
+
└── TimeInputSegment
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
`TimeInput` renders a group with one `TimeInputSegment` for each part of the time, and the text between them.
|
|
44
|
+
|
|
45
|
+
## Usage
|
|
46
|
+
|
|
47
|
+
Put the input in a [Field](./field.md) and give it a label:
|
|
48
|
+
|
|
49
|
+
```tsx
|
|
50
|
+
import { Field, FieldLabel } from "@ui-sdk/react/field"
|
|
51
|
+
import { TimeInput } from "@ui-sdk/react/time-input"
|
|
52
|
+
|
|
53
|
+
function Example() {
|
|
54
|
+
return (
|
|
55
|
+
<Field>
|
|
56
|
+
<FieldLabel>Meeting time</FieldLabel>
|
|
57
|
+
<TimeInput defaultValue="09:30" />
|
|
58
|
+
</Field>
|
|
59
|
+
)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export { Example }
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
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).
|
|
66
|
+
|
|
67
|
+
## Clock and Seconds
|
|
68
|
+
|
|
69
|
+
The input shows the locale's clock. Set `hourCycle` to `12` or `24` to choose one, and `granularity` to `"second"` to add seconds, or `"hour"` to show the hour alone.
|
|
70
|
+
|
|
71
|
+
```tsx title="hour-cycle.tsx"
|
|
72
|
+
"use client"
|
|
73
|
+
|
|
74
|
+
import { Field, FieldLabel } from "@ui-sdk/react/field"
|
|
75
|
+
import { TimeInput } from "@ui-sdk/react/time-input"
|
|
76
|
+
|
|
77
|
+
function Example() {
|
|
78
|
+
return (
|
|
79
|
+
<div data-slot="stack">
|
|
80
|
+
<Field>
|
|
81
|
+
<FieldLabel>12-hour clock</FieldLabel>
|
|
82
|
+
<TimeInput hourCycle={12} defaultValue="18:45" />
|
|
83
|
+
</Field>
|
|
84
|
+
<Field>
|
|
85
|
+
<FieldLabel>24-hour clock</FieldLabel>
|
|
86
|
+
<TimeInput hourCycle={24} defaultValue="18:45" />
|
|
87
|
+
</Field>
|
|
88
|
+
<Field>
|
|
89
|
+
<FieldLabel>With seconds</FieldLabel>
|
|
90
|
+
<TimeInput granularity="second" hourCycle={24} defaultValue="18:45:30" />
|
|
91
|
+
</Field>
|
|
92
|
+
</div>
|
|
93
|
+
)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export { Example }
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
The same evening time on a 12-hour clock, a 24-hour clock and with seconds. All three submit 24-hour values.
|
|
100
|
+
|
|
101
|
+
## Min and Max
|
|
102
|
+
|
|
103
|
+
`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.
|
|
104
|
+
|
|
105
|
+
## Form
|
|
106
|
+
|
|
107
|
+
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.
|
|
108
|
+
|
|
109
|
+
## Controlled and Controller
|
|
110
|
+
|
|
111
|
+
Pass `value` and update it in `onValueChange`, or drive the input with `createTimeInputController()`, as in [Date Input](./date-input.md#controlled).
|
|
112
|
+
|
|
113
|
+
## Styling
|
|
114
|
+
|
|
115
|
+
Style it like [Date Input](./date-input.md#styling). The AM/PM segment sets `data-type="dayPeriod"`.
|
|
116
|
+
|
|
117
|
+
Each part has a `data-slot`, such as `time-input-segment`, and its state attributes are listed under [Data Attributes](#data-attributes).
|
|
118
|
+
|
|
119
|
+
## Data Attributes
|
|
120
|
+
|
|
121
|
+
### TimeInput
|
|
122
|
+
`[data-slot="time-input"]`
|
|
123
|
+
|
|
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 every segment is empty.
|
|
129
|
+
|
|
130
|
+
### TimeInputSegment
|
|
131
|
+
`[data-slot="time-input-segment"]`
|
|
132
|
+
|
|
133
|
+
- `data-type` (`hour`, `minute`, `second`, `dayPeriod`, `literal`): The segment's unit, or `literal` for the text between segments.
|
|
134
|
+
- `data-disabled`: Present when disabled, by its own prop or a `<fieldset>`.
|
|
135
|
+
- `data-readonly`: Present when read-only.
|
|
136
|
+
- `data-required`: Present when required.
|
|
137
|
+
- `data-invalid`: Present while the time is before `min` or after `max`.
|
|
138
|
+
- `data-empty`: Present while the segment is empty. It shows its placeholder.
|
|
139
|
+
|
|
140
|
+
## API Reference
|
|
141
|
+
|
|
142
|
+
Props and callbacks are the same as below, as React props.
|
|
143
|
+
|
|
144
|
+
### TimeInput
|
|
145
|
+
|
|
146
|
+
- `value?` (`string | null`): The value: a time like `"14:30"`, or `"14:30:15"` with seconds, or `null`. Pass it to control the input.
|
|
147
|
+
- `defaultValue?` (`string | null`): The value it starts with, when uncontrolled, and goes back to when its form resets.
|
|
148
|
+
- `onValueChange?` (`((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.
|
|
149
|
+
- `granularity?` (`TimeInputGranularity`): The smallest unit it shows.
|
|
150
|
+
- `hourCycle?` (`HourCycle`): A 12 or 24 hour clock. Defaults to the locale's.
|
|
151
|
+
- `min?` (`string`): The earliest time, like `"09:00"`. A time before it is invalid.
|
|
152
|
+
- `max?` (`string`): The latest time, like `"17:30"`. A time after it is invalid.
|
|
153
|
+
- `locale?` (`string`): The language whose separators and clock it shows. Defaults to the page's.
|
|
154
|
+
- `disabled?` (`boolean`): Whether it can't be used.
|
|
155
|
+
- `readOnly?` (`boolean`): Whether the value can be seen but not changed.
|
|
156
|
+
- `required?` (`boolean`): Whether a time must be entered before its form submits.
|
|
157
|
+
- `name?` (`string`): The name the value submits under.
|
|
158
|
+
- `form?` (`string`): The id of the form it belongs to, when it isn't inside it.
|
|
159
|
+
- `controller?` (`object`): Drives it from anywhere. Create one with `createTimeInputController()`.
|
|
160
|
+
- `debug?` (`boolean`): Logs every state change with its reason to the console, in development builds.
|
|
161
|
+
|
|
162
|
+
### State
|
|
163
|
+
|
|
164
|
+
- `value` (`string | null`): The value, or `null` while empty or partly filled.
|
|
165
|
+
- `segments` (`DateInputSegmentData[]`): The segments in the order the locale shows them, with the text between them. Render one part for each.
|
|
166
|
+
- `disabled` (`boolean`): Whether it can't be used, by itself or by a `<fieldset>`.
|
|
167
|
+
- `readOnly` (`boolean`): Whether the value can be seen but not changed.
|
|
168
|
+
- `invalid` (`boolean`): Whether the value is before `min`, after `max` or an unavailable date.
|
|
169
|
+
|
|
170
|
+
### Reasons
|
|
171
|
+
|
|
172
|
+
- `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.
|
|
173
|
+
- `step-key` (`KeyboardEvent`): Arrow, Page Up, Page Down, Home or End stepped a slider or a number input.
|
|
174
|
+
- `paste` (`ClipboardEvent`): Files were pasted, like a screenshot, or text and tokens into a token input.
|
|
175
|
+
- `reset` (`none`): A form reset.
|
|
176
|
+
- `restore` (`none`): The browser restored state, like after going back, or a saved value was read back from storage.
|
|
177
|
+
- `imperative` (`none`): A controller or `api` call, or a property set on a web component.
|
|
178
|
+
|
|
179
|
+
### Controller
|
|
180
|
+
|
|
181
|
+
- `getValue()` (`() => string | null`): The value, or `null` while empty or partly filled.
|
|
182
|
+
- `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.
|
|
183
|
+
- `clear(options?)` (`(options?: DateInputChangeOptions | undefined) => boolean`): Empties every segment.
|
|
184
|
+
- `focus(segment?)` (`(segment?: string | undefined) => void`): Focuses a segment, like `"month"`, or the first one.
|
|
185
|
+
|
|
186
|
+
### Events
|
|
187
|
+
|
|
188
|
+
| Prop | On | Receives |
|
|
189
|
+
| --------------- | ----------- | ---------------------------------------------------------------------------------- |
|
|
190
|
+
| `onValueChange` | `TimeInput` | `(value, details)`: the time, or null once it's erased, and the [reason](#reasons) |
|
|
191
|
+
|
|
192
|
+
## Accessibility
|
|
193
|
+
|
|
194
|
+
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).
|
|
195
|
+
|
|
196
|
+
### Tested Behavior
|
|
197
|
+
|
|
198
|
+
Every line below is an automated test.
|
|
199
|
+
|
|
200
|
+
- Each unit is a spinbutton in the locale's order.
|
|
201
|
+
- Another locale orders the segments its own way.
|
|
202
|
+
- Typing fills each segment, moves on and reports the date once.
|
|
203
|
+
- A press on the box or between segments focuses the nearest segment.
|
|
204
|
+
- A digit that can't start a longer number moves on at once.
|
|
205
|
+
- A separator moves to the next segment.
|
|
206
|
+
- Typing with separators over a filled date or time keeps every segment.
|
|
207
|
+
- ArrowUp and ArrowDown step a segment and wrap around.
|
|
208
|
+
- PageUp and PageDown take bigger steps.
|
|
209
|
+
- Home and End go to a segment's first and last values.
|
|
210
|
+
- ArrowLeft and ArrowRight move between segments.
|
|
211
|
+
- Tab moves through the segments, then out.
|
|
212
|
+
- Backspace empties a segment, then moves back.
|
|
213
|
+
- A day past the end of a new month is moved back to its last day.
|
|
214
|
+
- Pasting a date fills every segment.
|
|
215
|
+
- A time takes hours, minutes and AM or PM.
|
|
216
|
+
- A 24-hour clock has no AM or PM.
|
|
217
|
+
- A date with a time shows its hour and minute too.
|
|
218
|
+
- A controller sets and clears the date.
|
|
219
|
+
- A canceled change keeps the date.
|
|
220
|
+
- The form submits the ISO date and time under their names.
|
|
221
|
+
- Enter submits the form with what was typed.
|
|
222
|
+
- Resetting the form brings back the default date.
|
|
223
|
+
- A partly filled date can't be submitted.
|
|
224
|
+
- A required empty date can't be submitted.
|
|
225
|
+
- A date after max is invalid.
|
|
226
|
+
- An unavailable date is invalid.
|
|
227
|
+
- The field's label focuses the first segment.
|
|
228
|
+
- A read-only date takes focus but doesn't change.
|
|
229
|
+
- A disabled date can't be focused.
|
|
230
|
+
|
|
231
|
+
Runs in React, Vue and web components.
|