@barqjs/aria 0.2.0-next.0 → 0.2.0-next.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/README.md +24 -13
- package/package.json +127 -37
- package/src/autocomplete.tsx +581 -0
- package/src/breadcrumbs.tsx +21 -20
- package/src/button.tsx +151 -25
- package/src/calendar.tsx +1019 -92
- package/src/checkbox.tsx +214 -52
- package/src/collections.ts +88 -5
- package/src/color.ts +1580 -23
- package/src/colorpicker.tsx +698 -153
- package/src/colorswatchpicker.tsx +240 -0
- package/src/combobox.tsx +635 -113
- package/src/command.tsx +78 -59
- package/src/date.ts +31 -9
- package/src/datefield.tsx +1451 -336
- package/src/datepicker.tsx +465 -114
- package/src/dialog.tsx +302 -115
- package/src/disclosure.tsx +81 -29
- package/src/dnd/clipboard.ts +125 -0
- package/src/dnd/collection.ts +1265 -0
- package/src/dnd/data.ts +409 -0
- package/src/dnd/drag-drop.ts +801 -0
- package/src/dnd/index.ts +133 -0
- package/src/dnd/manager.ts +639 -0
- package/src/dnd/strings.ts +1279 -0
- package/src/dnd/targets.ts +726 -0
- package/src/dnd/types.ts +212 -0
- package/src/dom.ts +3 -6
- package/src/drag-and-drop.tsx +669 -0
- package/src/dropzone.tsx +208 -0
- package/src/file-trigger.tsx +103 -0
- package/src/form.tsx +18 -18
- package/src/gridlist.tsx +912 -121
- package/src/group.tsx +146 -0
- package/src/index.ts +402 -0
- package/src/interactions/focus-events.ts +13 -5
- package/src/interactions/keyboard.ts +195 -2
- package/src/interactions/modality.ts +18 -6
- package/src/interactions/open-link.ts +46 -13
- package/src/interactions/press.ts +35 -18
- package/src/label.ts +18 -6
- package/src/link.tsx +146 -50
- package/src/listbox.tsx +615 -89
- package/src/live.ts +4 -0
- package/src/menu.tsx +182 -89
- package/src/menubar.tsx +21 -17
- package/src/navigation-tree.tsx +357 -0
- package/src/numberfield.tsx +164 -60
- package/src/overlay-arrow.tsx +157 -0
- package/src/overlays.ts +364 -62
- package/src/platform.ts +2 -1
- package/src/preview-trigger.tsx +582 -0
- package/src/progress-bar-context.ts +15 -0
- package/src/questionnaire.tsx +109 -104
- package/src/radio.tsx +101 -27
- package/src/select.tsx +225 -145
- package/src/selection-indicator.tsx +74 -0
- package/src/selection.ts +73 -16
- package/src/shared-element-transition.tsx +316 -0
- package/src/sheet.tsx +1461 -0
- package/src/slider.tsx +139 -44
- package/src/switch.tsx +47 -21
- package/src/table.tsx +0 -0
- package/src/tabs.tsx +198 -89
- package/src/tag.tsx +217 -32
- package/src/textarea.tsx +186 -0
- package/src/textfield.tsx +103 -37
- package/src/toast-components.tsx +589 -0
- package/src/toggle-button-group.tsx +175 -0
- package/src/toggle-input.tsx +38 -0
- package/src/toggle.ts +68 -5
- package/src/tokenfield.tsx +1673 -0
- package/src/toolbar.tsx +15 -10
- package/src/tooltip.tsx +46 -29
- package/src/tree.tsx +2075 -0
- package/src/utils.ts +30 -1
- package/src/validation.ts +79 -22
- package/src/virtualizer.tsx +186 -23
package/src/textfield.tsx
CHANGED
|
@@ -11,8 +11,9 @@
|
|
|
11
11
|
* VoiceOver and NVDA still do not announce the latter.
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
import { type Accessor, type Child
|
|
14
|
+
import { cells, type Accessor, type Child } from "@barqjs/core";
|
|
15
15
|
import { ref as makeRef, mergeRefs, type RefTarget } from "@barqjs/primitives/refs";
|
|
16
|
+
import { type AutocompleteInputValue, useAutocompleteInput } from "./autocomplete.tsx";
|
|
16
17
|
import { focusRing } from "./focus.ts";
|
|
17
18
|
import { focusable, type FocusableOptions } from "./interactions/focusable.ts";
|
|
18
19
|
import { hover } from "./interactions/hover.ts";
|
|
@@ -135,6 +136,19 @@ export function textField(
|
|
|
135
136
|
const isDisabled = (): boolean => access(options.isDisabled) === true;
|
|
136
137
|
const isReadOnly = (): boolean => access(options.isReadOnly) === true;
|
|
137
138
|
const isRequired = (): boolean => access(options.isRequired) === true;
|
|
139
|
+
const isNative = (): boolean => behavior() === "native";
|
|
140
|
+
|
|
141
|
+
// A blur commits only what was edited, as `change` would: tabbing through a
|
|
142
|
+
// field the server rejected has fixed nothing, and must not clear the error.
|
|
143
|
+
let focusedValue: string | null = null;
|
|
144
|
+
const onFocus = (): void => {
|
|
145
|
+
focusedValue = value();
|
|
146
|
+
};
|
|
147
|
+
const onBlur = (): void => {
|
|
148
|
+
const edited = focusedValue !== null && focusedValue !== value();
|
|
149
|
+
focusedValue = null;
|
|
150
|
+
if (edited) validation.commitValidation();
|
|
151
|
+
};
|
|
138
152
|
|
|
139
153
|
const onInput = (event: Event): void => {
|
|
140
154
|
const input = event.target as HTMLInputElement;
|
|
@@ -164,7 +178,9 @@ export function textField(
|
|
|
164
178
|
value,
|
|
165
179
|
disabled: isDisabled,
|
|
166
180
|
readOnly: isReadOnly,
|
|
167
|
-
required
|
|
181
|
+
// The browser refuses the submit for `required`, so only when the page
|
|
182
|
+
// asked for that; otherwise assistive technology is told instead.
|
|
183
|
+
required: () => isRequired() && isNative(),
|
|
168
184
|
placeholder: () => access(options.placeholder),
|
|
169
185
|
name: () => access(options.name),
|
|
170
186
|
form: () => access(options.form),
|
|
@@ -174,12 +190,13 @@ export function textField(
|
|
|
174
190
|
pattern: () => access(options.pattern),
|
|
175
191
|
inputmode: () => access(options.inputMode),
|
|
176
192
|
"aria-invalid": () => isInvalid() || undefined,
|
|
177
|
-
"aria-required": () => isRequired() || undefined,
|
|
193
|
+
"aria-required": () => (isRequired() && !isNative()) || undefined,
|
|
178
194
|
"aria-readonly": () => isReadOnly() || undefined,
|
|
179
195
|
onInput,
|
|
180
196
|
onKeyDown: options.onKeyDown,
|
|
181
197
|
onKeyUp: options.onKeyUp,
|
|
182
|
-
|
|
198
|
+
onFocus,
|
|
199
|
+
onBlur,
|
|
183
200
|
},
|
|
184
201
|
),
|
|
185
202
|
};
|
|
@@ -222,14 +239,22 @@ export function searchField(
|
|
|
222
239
|
};
|
|
223
240
|
|
|
224
241
|
const onKeyDown = (event: KeyboardEvent): void => {
|
|
242
|
+
if (access(options.isReadOnly) === true || access(options.isDisabled) === true) return;
|
|
225
243
|
if (event.key === "Enter") {
|
|
244
|
+
// Without a handler of its own, Enter is the form's: it submits.
|
|
245
|
+
if (options.onSubmit === undefined) return;
|
|
226
246
|
event.preventDefault();
|
|
227
|
-
options.onSubmit
|
|
247
|
+
options.onSubmit(result.value());
|
|
228
248
|
return;
|
|
229
249
|
}
|
|
230
250
|
if (event.key === "Escape") {
|
|
231
|
-
|
|
251
|
+
const input = access(ref) as HTMLInputElement | null;
|
|
252
|
+
// Nothing to clear, so the key is someone else's: the dialog around it.
|
|
253
|
+
if (result.value() === "" && (input === null || input.value === "")) return;
|
|
254
|
+
// Handled here, so it goes no further: Escape that cleared the field
|
|
255
|
+
// must not also close the dialog it is in.
|
|
232
256
|
event.preventDefault();
|
|
257
|
+
event.stopPropagation();
|
|
233
258
|
clear();
|
|
234
259
|
}
|
|
235
260
|
};
|
|
@@ -255,6 +280,22 @@ export function searchField(
|
|
|
255
280
|
// Components
|
|
256
281
|
// ---------------------------------------------------------------------------
|
|
257
282
|
|
|
283
|
+
/**
|
|
284
|
+
* Inside an {@link Autocomplete} the field's value is the query. A value the
|
|
285
|
+
* caller gave still wins, and the caller's `onChange` hears every change after
|
|
286
|
+
* the autocomplete has.
|
|
287
|
+
*/
|
|
288
|
+
function queryOf(
|
|
289
|
+
auto: AutocompleteInputValue | null,
|
|
290
|
+
options: TextFieldOptions,
|
|
291
|
+
): Partial<TextFieldOptions> {
|
|
292
|
+
if (auto === null) return {};
|
|
293
|
+
return {
|
|
294
|
+
value: () => access(options.value) ?? auto.inputOptions.value(),
|
|
295
|
+
onChange: chain((value: string) => auto.inputOptions.onChange(value), options.onChange),
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
|
|
258
299
|
export interface TextFieldComponentProps extends StyleProps {
|
|
259
300
|
label?: Child;
|
|
260
301
|
description?: Child;
|
|
@@ -295,47 +336,59 @@ export interface TextFieldComponentProps extends StyleProps {
|
|
|
295
336
|
* <TextField label="Name" onChange={(v) => name.set(v)} />
|
|
296
337
|
* ```
|
|
297
338
|
*/
|
|
298
|
-
export function TextField(props:
|
|
339
|
+
export function TextField(props: TextFieldComponentProps) {
|
|
299
340
|
const inputRef = makeRef<HTMLInputElement>();
|
|
300
|
-
const options = fromProps(props);
|
|
341
|
+
const options = fromProps(cells(props));
|
|
342
|
+
const auto = useAutocompleteInput();
|
|
301
343
|
|
|
302
344
|
const { labelProps, inputProps, descriptionProps, errorMessageProps, errors, isInvalid } =
|
|
303
345
|
textField(
|
|
304
346
|
{
|
|
305
347
|
...(options as TextFieldOptions),
|
|
306
|
-
|
|
307
|
-
|
|
348
|
+
...queryOf(auto, options as TextFieldOptions),
|
|
349
|
+
validate: callback(cells(props).validate),
|
|
350
|
+
validationBehavior: () => props.validationBehavior,
|
|
308
351
|
},
|
|
309
352
|
inputRef,
|
|
310
353
|
);
|
|
311
354
|
const { hoverProps, isHovered } = hover({ isDisabled: options.isDisabled });
|
|
312
355
|
const { focusProps, isFocused, isFocusVisible } = focusRing({ isTextInput: true });
|
|
313
356
|
|
|
314
|
-
const controlProps = mergeProps(
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
357
|
+
const controlProps = mergeProps(
|
|
358
|
+
inputProps,
|
|
359
|
+
hoverProps,
|
|
360
|
+
focusProps,
|
|
361
|
+
{
|
|
362
|
+
"data-hovered": isHovered,
|
|
363
|
+
"data-focused": isFocused,
|
|
364
|
+
"data-focus-visible": isFocusVisible,
|
|
365
|
+
"data-disabled": () => props.isDisabled === true,
|
|
366
|
+
"data-readonly": () => props.isReadOnly === true,
|
|
367
|
+
"data-required": () => props.isRequired === true,
|
|
368
|
+
"data-invalid": isInvalid,
|
|
369
|
+
},
|
|
370
|
+
auto?.inputProps,
|
|
371
|
+
);
|
|
321
372
|
|
|
322
373
|
return (
|
|
323
374
|
<div
|
|
324
|
-
{...mergeProps(styleProps(props), {
|
|
325
|
-
"data-testid": () => props["data-testid"]
|
|
375
|
+
{...mergeProps(styleProps(cells(props)), {
|
|
376
|
+
"data-testid": () => props["data-testid"],
|
|
326
377
|
})}
|
|
327
378
|
>
|
|
328
379
|
<label {...labelProps}>{props.label}</label>
|
|
329
380
|
{() =>
|
|
330
|
-
props.isMultiLine
|
|
381
|
+
props.isMultiLine === true ? (
|
|
331
382
|
<textarea
|
|
332
383
|
{...controlProps}
|
|
333
384
|
ref={
|
|
334
|
-
mergeRefs(inputRef.set, props.ref?.
|
|
385
|
+
mergeRefs(inputRef.set, props.ref, auto?.ref) as unknown as (
|
|
386
|
+
el: HTMLTextAreaElement,
|
|
387
|
+
) => void
|
|
335
388
|
}
|
|
336
389
|
/>
|
|
337
390
|
) : (
|
|
338
|
-
<input {...controlProps} ref={mergeRefs(inputRef.set, props.ref?.
|
|
391
|
+
<input {...controlProps} ref={mergeRefs(inputRef.set, props.ref, auto?.ref)} />
|
|
339
392
|
)
|
|
340
393
|
}
|
|
341
394
|
<span {...descriptionProps}>{props.description}</span>
|
|
@@ -344,7 +397,7 @@ export function TextField(props: Incoming<TextFieldComponentProps>) {
|
|
|
344
397
|
<span {...errorMessageProps}>
|
|
345
398
|
{() => {
|
|
346
399
|
if (!isInvalid()) return null;
|
|
347
|
-
const given = props.errorMessage
|
|
400
|
+
const given = props.errorMessage;
|
|
348
401
|
if (given !== undefined && given !== null) return given;
|
|
349
402
|
return errors().join(" ");
|
|
350
403
|
}}
|
|
@@ -365,9 +418,10 @@ export interface SearchFieldComponentProps extends TextFieldComponentProps {
|
|
|
365
418
|
* <SearchField label="Search" onSubmit={(q) => search(q)} />
|
|
366
419
|
* ```
|
|
367
420
|
*/
|
|
368
|
-
export function SearchField(props:
|
|
421
|
+
export function SearchField(props: SearchFieldComponentProps) {
|
|
369
422
|
const inputRef = makeRef<HTMLInputElement>();
|
|
370
|
-
const options = fromProps(props);
|
|
423
|
+
const options = fromProps(cells(props));
|
|
424
|
+
const auto = useAutocompleteInput();
|
|
371
425
|
|
|
372
426
|
const {
|
|
373
427
|
labelProps,
|
|
@@ -378,28 +432,40 @@ export function SearchField(props: Incoming<SearchFieldComponentProps>) {
|
|
|
378
432
|
value,
|
|
379
433
|
errors,
|
|
380
434
|
isInvalid,
|
|
381
|
-
} = searchField(
|
|
435
|
+
} = searchField(
|
|
436
|
+
{ ...(options as SearchFieldOptions), ...queryOf(auto, options as SearchFieldOptions) },
|
|
437
|
+
inputRef,
|
|
438
|
+
);
|
|
382
439
|
const { hoverProps, isHovered } = hover({ isDisabled: options.isDisabled });
|
|
383
440
|
const { focusProps, isFocused, isFocusVisible } = focusRing({ isTextInput: true });
|
|
384
441
|
|
|
385
|
-
const controlProps = mergeProps(
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
442
|
+
const controlProps = mergeProps(
|
|
443
|
+
inputProps,
|
|
444
|
+
hoverProps,
|
|
445
|
+
focusProps,
|
|
446
|
+
{
|
|
447
|
+
"data-hovered": isHovered,
|
|
448
|
+
"data-focused": isFocused,
|
|
449
|
+
"data-focus-visible": isFocusVisible,
|
|
450
|
+
"data-disabled": () => props.isDisabled === true,
|
|
451
|
+
"data-readonly": () => props.isReadOnly === true,
|
|
452
|
+
"data-required": () => props.isRequired === true,
|
|
453
|
+
"data-invalid": isInvalid,
|
|
454
|
+
},
|
|
455
|
+
auto?.inputProps,
|
|
456
|
+
);
|
|
391
457
|
|
|
392
458
|
return (
|
|
393
459
|
<div
|
|
394
|
-
{...mergeProps(styleProps(props), {
|
|
395
|
-
"data-testid": () => props["data-testid"]
|
|
460
|
+
{...mergeProps(styleProps(cells(props)), {
|
|
461
|
+
"data-testid": () => props["data-testid"],
|
|
396
462
|
"data-empty": () => value() === "",
|
|
397
463
|
})}
|
|
398
464
|
>
|
|
399
465
|
<label {...labelProps}>{props.label}</label>
|
|
400
|
-
<input {...controlProps} ref={mergeRefs(inputRef.set, props.ref?.
|
|
466
|
+
<input {...controlProps} ref={mergeRefs(inputRef.set, props.ref, auto?.ref)} />
|
|
401
467
|
<button type="button" {...clearButtonProps}>
|
|
402
|
-
{() => props.clearLabel
|
|
468
|
+
{() => props.clearLabel ?? "Clear search"}
|
|
403
469
|
</button>
|
|
404
470
|
<span {...descriptionProps}>{props.description}</span>
|
|
405
471
|
{/* The caller's message when it gave one, and otherwise whatever found
|
|
@@ -407,7 +473,7 @@ export function SearchField(props: Incoming<SearchFieldComponentProps>) {
|
|
|
407
473
|
<span {...errorMessageProps}>
|
|
408
474
|
{() => {
|
|
409
475
|
if (!isInvalid()) return null;
|
|
410
|
-
const given = props.errorMessage
|
|
476
|
+
const given = props.errorMessage;
|
|
411
477
|
if (given !== undefined && given !== null) return given;
|
|
412
478
|
return errors().join(" ");
|
|
413
479
|
}}
|