@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/questionnaire.tsx
CHANGED
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
*/
|
|
35
35
|
|
|
36
36
|
import {
|
|
37
|
+
cells,
|
|
37
38
|
type Accessor,
|
|
38
39
|
type Child,
|
|
39
40
|
createContext,
|
|
@@ -478,30 +479,30 @@ export interface QuestionnaireProps extends StyleProps {
|
|
|
478
479
|
* </Questionnaire>
|
|
479
480
|
* ```
|
|
480
481
|
*/
|
|
481
|
-
export function Questionnaire(props:
|
|
482
|
-
const options = fromProps(props);
|
|
482
|
+
export function Questionnaire(props: QuestionnaireProps) {
|
|
483
|
+
const options = fromProps(cells(props));
|
|
483
484
|
const direction = useDirection();
|
|
484
485
|
|
|
485
|
-
const shortcuts = (): QuestionnaireShortcutMode | null => props.shortcuts
|
|
486
|
-
const noValidate = (): boolean => props.noValidate
|
|
486
|
+
const shortcuts = (): QuestionnaireShortcutMode | null => props.shortcuts ?? null;
|
|
487
|
+
const noValidate = (): boolean => props.noValidate ?? true;
|
|
487
488
|
const backKey = (): "ArrowLeft" | "ArrowRight" =>
|
|
488
489
|
direction() === "rtl" ? "ArrowRight" : "ArrowLeft";
|
|
489
490
|
const forwardKey = (): "ArrowLeft" | "ArrowRight" =>
|
|
490
491
|
direction() === "rtl" ? "ArrowLeft" : "ArrowRight";
|
|
491
492
|
|
|
492
|
-
const collection = createMemo(() => createCollection(props.items
|
|
493
|
+
const collection = createMemo(() => createCollection(props.items));
|
|
493
494
|
const [handles, register] = registry<ItemHandle>();
|
|
494
495
|
// `ownedWrite`: the form's own `ref` bumps it, and a ref is called while this
|
|
495
496
|
// component is still being built.
|
|
496
497
|
const [domVersion, setDomVersion] = createSignal(0, { ownedWrite: true });
|
|
497
498
|
const [uncontrolled, setUncontrolled] = createSignal<string | null>(
|
|
498
|
-
untrack(() => initialItemName(collection(), props.defaultItem
|
|
499
|
+
untrack(() => initialItemName(collection(), props.defaultItem)),
|
|
499
500
|
);
|
|
500
501
|
let form: HTMLFormElement | null = null;
|
|
501
502
|
let observer: MutationObserver | undefined;
|
|
502
503
|
let pendingFocus: { name: string; target: "invalid" | "item" } | null = null;
|
|
503
504
|
|
|
504
|
-
const controlled = (): boolean => props.item
|
|
505
|
+
const controlled = (): boolean => props.item !== undefined;
|
|
505
506
|
|
|
506
507
|
const runtimeItems = createMemo(() => {
|
|
507
508
|
domVersion();
|
|
@@ -515,7 +516,7 @@ export function Questionnaire(props: Incoming<QuestionnaireProps>) {
|
|
|
515
516
|
? runtimeItems().map((handle) => handle.name())
|
|
516
517
|
: declared.enabled.map((definition) => definition.name);
|
|
517
518
|
});
|
|
518
|
-
const requested = (): string | null => props.item
|
|
519
|
+
const requested = (): string | null => props.item ?? uncontrolled();
|
|
519
520
|
// Before the first question has been made current, the first one is.
|
|
520
521
|
const activeName = (): string | null =>
|
|
521
522
|
requested() ?? (controlled() ? null : (names()[0] ?? null));
|
|
@@ -642,7 +643,7 @@ export function Questionnaire(props: Incoming<QuestionnaireProps>) {
|
|
|
642
643
|
for (const handle of handles()) handle.reset();
|
|
643
644
|
|
|
644
645
|
const declared = collection();
|
|
645
|
-
const wanted = props.defaultItem
|
|
646
|
+
const wanted = props.defaultItem;
|
|
646
647
|
const name =
|
|
647
648
|
declared === null
|
|
648
649
|
? (runtimeItems()
|
|
@@ -780,7 +781,7 @@ export function Questionnaire(props: Incoming<QuestionnaireProps>) {
|
|
|
780
781
|
|
|
781
782
|
const formProps = mergeProps(
|
|
782
783
|
filterDOMProps(options, { global: true, labelable: true, propNames: FORM_PROPS }),
|
|
783
|
-
styleProps(props),
|
|
784
|
+
styleProps(cells(props)),
|
|
784
785
|
{
|
|
785
786
|
noValidate,
|
|
786
787
|
"data-shortcuts": () => shortcuts() ?? undefined,
|
|
@@ -799,7 +800,7 @@ export function Questionnaire(props: Incoming<QuestionnaireProps>) {
|
|
|
799
800
|
);
|
|
800
801
|
|
|
801
802
|
return (
|
|
802
|
-
<form {...formProps} ref={mergeRefs(attach, props.ref
|
|
803
|
+
<form {...formProps} ref={mergeRefs(attach, props.ref)}>
|
|
803
804
|
{props.children}
|
|
804
805
|
</form>
|
|
805
806
|
);
|
|
@@ -817,9 +818,9 @@ export interface QuestionnaireProgressProps extends StyleProps {
|
|
|
817
818
|
render?: RenderPart<QuestionnaireProgressState>;
|
|
818
819
|
}
|
|
819
820
|
|
|
820
|
-
export function QuestionnaireProgress(props:
|
|
821
|
+
export function QuestionnaireProgress(props: QuestionnaireProgressProps) {
|
|
821
822
|
const root = useRoot();
|
|
822
|
-
const options = fromProps(props);
|
|
823
|
+
const options = fromProps(cells(props));
|
|
823
824
|
const known = (): boolean => root.total() > 0;
|
|
824
825
|
const label = (): string | undefined =>
|
|
825
826
|
known() ? `Question ${String(root.current())} of ${String(root.total())}` : undefined;
|
|
@@ -839,10 +840,10 @@ export function QuestionnaireProgress(props: Incoming<QuestionnaireProgressProps
|
|
|
839
840
|
"data-last": () => present(root.last()),
|
|
840
841
|
},
|
|
841
842
|
filterDOMProps(options, { global: true, labelable: true }),
|
|
842
|
-
styleProps(props),
|
|
843
|
+
styleProps(cells(props)),
|
|
843
844
|
);
|
|
844
845
|
|
|
845
|
-
const render = props.render
|
|
846
|
+
const render = props.render;
|
|
846
847
|
if (render !== undefined) {
|
|
847
848
|
const state: QuestionnaireProgressState = {
|
|
848
849
|
current: root.current,
|
|
@@ -850,11 +851,11 @@ export function QuestionnaireProgress(props: Incoming<QuestionnaireProgressProps
|
|
|
850
851
|
last: root.last,
|
|
851
852
|
total: root.total,
|
|
852
853
|
};
|
|
853
|
-
return render(partRender({ ...elementProps, ref: props.ref
|
|
854
|
+
return render(partRender({ ...elementProps, ref: props.ref }), state) as JSXElement;
|
|
854
855
|
}
|
|
855
856
|
|
|
856
857
|
return (
|
|
857
|
-
<div {...elementProps} ref={mergeRefs(props.ref
|
|
858
|
+
<div {...elementProps} ref={mergeRefs(props.ref)}>
|
|
858
859
|
{props.children === undefined ? () => label() : props.children}
|
|
859
860
|
</div>
|
|
860
861
|
);
|
|
@@ -880,15 +881,15 @@ export interface QuestionnaireItemProps extends StyleProps {
|
|
|
880
881
|
ref?: RefTarget<HTMLFieldSetElement>;
|
|
881
882
|
}
|
|
882
883
|
|
|
883
|
-
export function QuestionnaireItem(props:
|
|
884
|
+
export function QuestionnaireItem(props: QuestionnaireItemProps) {
|
|
884
885
|
const root = useRoot();
|
|
885
|
-
const options = fromProps(props);
|
|
886
|
+
const options = fromProps(cells(props));
|
|
886
887
|
|
|
887
|
-
const name = (): string => props.name
|
|
888
|
-
const disabled = (): boolean => props.disabled
|
|
889
|
-
const required = (): boolean => props.required
|
|
890
|
-
const multiple = (): boolean => props.multiple
|
|
891
|
-
const externallyInvalid = (): boolean => props.invalid
|
|
888
|
+
const name = (): string => props.name;
|
|
889
|
+
const disabled = (): boolean => props.disabled ?? false;
|
|
890
|
+
const required = (): boolean => props.required ?? false;
|
|
891
|
+
const multiple = (): boolean => props.multiple ?? false;
|
|
892
|
+
const externallyInvalid = (): boolean => props.invalid ?? false;
|
|
892
893
|
|
|
893
894
|
// Each of these is written by a child while this question is being built: a
|
|
894
895
|
// choice that starts checked, a description announcing its id.
|
|
@@ -1105,36 +1106,40 @@ export function QuestionnaireItem(props: Incoming<QuestionnaireItemProps>) {
|
|
|
1105
1106
|
const ids = [
|
|
1106
1107
|
...descriptionIds(),
|
|
1107
1108
|
...(invalid() ? errorIds() : []),
|
|
1108
|
-
props["aria-describedby"]
|
|
1109
|
+
props["aria-describedby"],
|
|
1109
1110
|
].filter((id) => id !== undefined && id !== "");
|
|
1110
1111
|
return ids.length === 0 ? undefined : ids.join(" ");
|
|
1111
1112
|
};
|
|
1112
1113
|
|
|
1113
|
-
const fieldsetProps = mergeProps(
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1114
|
+
const fieldsetProps = mergeProps(
|
|
1115
|
+
filterDOMProps(options, { global: true }),
|
|
1116
|
+
styleProps(cells(props)),
|
|
1117
|
+
{
|
|
1118
|
+
"aria-describedby": describedBy,
|
|
1119
|
+
"aria-invalid": () => (invalid() ? true : undefined),
|
|
1120
|
+
"aria-keyshortcuts": () =>
|
|
1121
|
+
keyShortcuts(
|
|
1122
|
+
props["aria-keyshortcuts"],
|
|
1123
|
+
active() && "Meta+Enter Control+Enter",
|
|
1124
|
+
active() && answers().length > 0 && "ArrowUp ArrowDown",
|
|
1125
|
+
active() && !root.first() && root.backKey(),
|
|
1126
|
+
active() && !root.last() && status() !== "unanswered" && root.forwardKey(),
|
|
1127
|
+
),
|
|
1128
|
+
disabled,
|
|
1129
|
+
hidden: () => !active(),
|
|
1130
|
+
inert: () => !active(),
|
|
1131
|
+
tabIndex: -1,
|
|
1132
|
+
"data-active": () => present(active()),
|
|
1133
|
+
"data-disabled": () => present(disabled()),
|
|
1134
|
+
"data-invalid": () => present(invalid()),
|
|
1135
|
+
"data-multiple": () => present(multiple()),
|
|
1136
|
+
"data-required": () => present(required()),
|
|
1137
|
+
"data-status": status,
|
|
1138
|
+
},
|
|
1139
|
+
);
|
|
1135
1140
|
|
|
1136
1141
|
return (
|
|
1137
|
-
<fieldset {...fieldsetProps} ref={mergeRefs(attach, props.ref
|
|
1142
|
+
<fieldset {...fieldsetProps} ref={mergeRefs(attach, props.ref)}>
|
|
1138
1143
|
{props.children}
|
|
1139
1144
|
</fieldset>
|
|
1140
1145
|
);
|
|
@@ -1150,29 +1155,29 @@ export interface QuestionnairePartProps extends StyleProps {
|
|
|
1150
1155
|
}
|
|
1151
1156
|
|
|
1152
1157
|
/** The question itself: a `<legend>`, so it names the group. */
|
|
1153
|
-
export function QuestionnaireTitle(props:
|
|
1158
|
+
export function QuestionnaireTitle(props: QuestionnairePartProps) {
|
|
1154
1159
|
useItem();
|
|
1155
1160
|
const elementProps = mergeProps(
|
|
1156
|
-
filterDOMProps(fromProps(props), { global: true }),
|
|
1157
|
-
styleProps(props),
|
|
1161
|
+
filterDOMProps(fromProps(cells(props)), { global: true }),
|
|
1162
|
+
styleProps(cells(props)),
|
|
1158
1163
|
);
|
|
1159
|
-
const render = props.render
|
|
1164
|
+
const render = props.render;
|
|
1160
1165
|
if (render !== undefined) return render(partRender(elementProps)) as JSXElement;
|
|
1161
1166
|
return <legend {...elementProps}>{props.children}</legend>;
|
|
1162
1167
|
}
|
|
1163
1168
|
|
|
1164
|
-
export function QuestionnaireDescription(props:
|
|
1169
|
+
export function QuestionnaireDescription(props: QuestionnairePartProps) {
|
|
1165
1170
|
const item = useItem();
|
|
1166
1171
|
const generated = createUniqueId();
|
|
1167
|
-
const descriptionId = (): string => props.id
|
|
1172
|
+
const descriptionId = (): string => props.id ?? generated;
|
|
1168
1173
|
onCleanup(item.registerDescription(untrack(descriptionId)));
|
|
1169
1174
|
|
|
1170
1175
|
const elementProps = mergeProps(
|
|
1171
|
-
filterDOMProps(fromProps(props), { global: true }),
|
|
1172
|
-
styleProps(props),
|
|
1176
|
+
filterDOMProps(fromProps(cells(props)), { global: true }),
|
|
1177
|
+
styleProps(cells(props)),
|
|
1173
1178
|
{ id: descriptionId },
|
|
1174
1179
|
);
|
|
1175
|
-
const render = props.render
|
|
1180
|
+
const render = props.render;
|
|
1176
1181
|
if (render !== undefined) return render(partRender(elementProps)) as JSXElement;
|
|
1177
1182
|
return <p {...elementProps}>{props.children}</p>;
|
|
1178
1183
|
}
|
|
@@ -1184,18 +1189,18 @@ export interface QuestionnaireErrorProps extends StyleProps {
|
|
|
1184
1189
|
}
|
|
1185
1190
|
|
|
1186
1191
|
/** Shown, and announced, only while the question is invalid. */
|
|
1187
|
-
export function QuestionnaireError(props:
|
|
1192
|
+
export function QuestionnaireError(props: QuestionnaireErrorProps) {
|
|
1188
1193
|
const item = useItem();
|
|
1189
1194
|
const generated = createUniqueId();
|
|
1190
|
-
const errorId = (): string => props.id
|
|
1195
|
+
const errorId = (): string => props.id ?? generated;
|
|
1191
1196
|
onCleanup(item.registerError(untrack(errorId)));
|
|
1192
1197
|
|
|
1193
1198
|
const message = (): string =>
|
|
1194
1199
|
item.required() ? "Choose an answer to continue." : "Choose an answer or skip this question.";
|
|
1195
1200
|
|
|
1196
1201
|
const elementProps = mergeProps(
|
|
1197
|
-
filterDOMProps(fromProps(props), { global: true }),
|
|
1198
|
-
styleProps(props),
|
|
1202
|
+
filterDOMProps(fromProps(cells(props)), { global: true }),
|
|
1203
|
+
styleProps(cells(props)),
|
|
1199
1204
|
{
|
|
1200
1205
|
id: errorId,
|
|
1201
1206
|
hidden: () => !item.invalid(),
|
|
@@ -1203,7 +1208,7 @@ export function QuestionnaireError(props: Incoming<QuestionnaireErrorProps>) {
|
|
|
1203
1208
|
"data-invalid": () => present(item.invalid()),
|
|
1204
1209
|
},
|
|
1205
1210
|
);
|
|
1206
|
-
const render = props.render
|
|
1211
|
+
const render = props.render;
|
|
1207
1212
|
if (render !== undefined) {
|
|
1208
1213
|
return render(partRender(elementProps), { invalid: item.invalid }) as JSXElement;
|
|
1209
1214
|
}
|
|
@@ -1219,14 +1224,14 @@ export interface QuestionnaireChoicesProps extends StyleProps {
|
|
|
1219
1224
|
render?: RenderPart<QuestionnaireChoicesState>;
|
|
1220
1225
|
}
|
|
1221
1226
|
|
|
1222
|
-
export function QuestionnaireChoices(props:
|
|
1227
|
+
export function QuestionnaireChoices(props: QuestionnaireChoicesProps) {
|
|
1223
1228
|
const item = useItem();
|
|
1224
1229
|
const elementProps = mergeProps(
|
|
1225
|
-
filterDOMProps(fromProps(props), { global: true, labelable: true }),
|
|
1226
|
-
styleProps(props),
|
|
1230
|
+
filterDOMProps(fromProps(cells(props)), { global: true, labelable: true }),
|
|
1231
|
+
styleProps(cells(props)),
|
|
1227
1232
|
{ "data-shortcuts": () => item.shortcuts() ?? undefined },
|
|
1228
1233
|
);
|
|
1229
|
-
const render = props.render
|
|
1234
|
+
const render = props.render;
|
|
1230
1235
|
if (render !== undefined) {
|
|
1231
1236
|
return render(partRender(elementProps), { shortcuts: item.shortcuts }) as JSXElement;
|
|
1232
1237
|
}
|
|
@@ -1248,15 +1253,15 @@ export interface QuestionnaireChoiceProps extends StyleProps {
|
|
|
1248
1253
|
* One fixed answer: a `<label>` around its input, so the whole row is the
|
|
1249
1254
|
* target.
|
|
1250
1255
|
*/
|
|
1251
|
-
export function QuestionnaireChoice(props:
|
|
1256
|
+
export function QuestionnaireChoice(props: QuestionnaireChoiceProps) {
|
|
1252
1257
|
const item = useItem();
|
|
1253
|
-
const options = fromProps(props);
|
|
1258
|
+
const options = fromProps(cells(props));
|
|
1254
1259
|
const answerId = createUniqueId();
|
|
1255
1260
|
|
|
1256
|
-
const value = (): string => props.value
|
|
1257
|
-
const ownDisabled = (): boolean => props.disabled
|
|
1261
|
+
const value = (): string => props.value;
|
|
1262
|
+
const ownDisabled = (): boolean => props.disabled ?? false;
|
|
1258
1263
|
const disabled = (): boolean => item.disabled() || ownDisabled();
|
|
1259
|
-
const controlledChecked = (): boolean | undefined => props.checked
|
|
1264
|
+
const controlledChecked = (): boolean | undefined => props.checked;
|
|
1260
1265
|
const checked = (): boolean => {
|
|
1261
1266
|
const controlled = controlledChecked();
|
|
1262
1267
|
if (controlled === undefined) return item.isSelected(answerId);
|
|
@@ -1268,7 +1273,7 @@ export function QuestionnaireChoice(props: Incoming<QuestionnaireChoiceProps>) {
|
|
|
1268
1273
|
onCleanup(
|
|
1269
1274
|
item.registerSelection(
|
|
1270
1275
|
answerId,
|
|
1271
|
-
untrack(() => props.defaultChecked
|
|
1276
|
+
untrack(() => props.defaultChecked ?? false),
|
|
1272
1277
|
),
|
|
1273
1278
|
);
|
|
1274
1279
|
const initial = untrack(controlledChecked);
|
|
@@ -1293,7 +1298,7 @@ export function QuestionnaireChoice(props: Incoming<QuestionnaireChoiceProps>) {
|
|
|
1293
1298
|
onCleanup(() => unregister?.());
|
|
1294
1299
|
|
|
1295
1300
|
createEffect(
|
|
1296
|
-
() => props.defaultChecked
|
|
1301
|
+
() => props.defaultChecked ?? false,
|
|
1297
1302
|
(now) => item.setDefault(answerId, now),
|
|
1298
1303
|
);
|
|
1299
1304
|
|
|
@@ -1309,7 +1314,7 @@ export function QuestionnaireChoice(props: Incoming<QuestionnaireChoiceProps>) {
|
|
|
1309
1314
|
createEffect(
|
|
1310
1315
|
() => ({
|
|
1311
1316
|
checked: checked(),
|
|
1312
|
-
fallback: controlledChecked() ?? props.defaultChecked
|
|
1317
|
+
fallback: controlledChecked() ?? props.defaultChecked ?? false,
|
|
1313
1318
|
version: item.resetVersion(),
|
|
1314
1319
|
}),
|
|
1315
1320
|
(now) => {
|
|
@@ -1375,11 +1380,11 @@ export function QuestionnaireChoice(props: Incoming<QuestionnaireChoiceProps>) {
|
|
|
1375
1380
|
const labelProps = mergeProps(
|
|
1376
1381
|
// NOT `id`: it belongs on the input, which is the labelable element.
|
|
1377
1382
|
filterDOMProps(options, { global: true, id: false }),
|
|
1378
|
-
styleProps(props),
|
|
1383
|
+
styleProps(cells(props)),
|
|
1379
1384
|
stateProps,
|
|
1380
1385
|
);
|
|
1381
1386
|
|
|
1382
|
-
const render = props.render
|
|
1387
|
+
const render = props.render;
|
|
1383
1388
|
if (render !== undefined) return render(partRender(labelProps), state) as JSXElement;
|
|
1384
1389
|
return <label {...labelProps}>{props.children}</label>;
|
|
1385
1390
|
}
|
|
@@ -1393,30 +1398,30 @@ export interface QuestionnaireChoiceInputProps extends StyleProps {
|
|
|
1393
1398
|
}
|
|
1394
1399
|
|
|
1395
1400
|
/** The radio or checkbox itself, which is what holds focus and is submitted. */
|
|
1396
|
-
export function QuestionnaireChoiceInput(props:
|
|
1401
|
+
export function QuestionnaireChoiceInput(props: QuestionnaireChoiceInputProps) {
|
|
1397
1402
|
const choice = useChoice();
|
|
1398
1403
|
const { ref: attach, ...inputProps } = choice.inputProps;
|
|
1399
1404
|
const elementProps = mergeProps(
|
|
1400
|
-
filterDOMProps(fromProps(props), { global: true, labelable: true, id: false }),
|
|
1401
|
-
styleProps(props),
|
|
1405
|
+
filterDOMProps(fromProps(cells(props)), { global: true, labelable: true, id: false }),
|
|
1406
|
+
styleProps(cells(props)),
|
|
1402
1407
|
choice.stateProps,
|
|
1403
1408
|
inputProps,
|
|
1404
1409
|
);
|
|
1405
|
-
const ref = mergeRefs(attach as RefTarget<HTMLInputElement>, props.ref
|
|
1406
|
-
const render = props.render
|
|
1410
|
+
const ref = mergeRefs(attach as RefTarget<HTMLInputElement>, props.ref);
|
|
1411
|
+
const render = props.render;
|
|
1407
1412
|
if (render !== undefined) {
|
|
1408
1413
|
return render(partRender({ ...elementProps, ref }), choice.state) as JSXElement;
|
|
1409
1414
|
}
|
|
1410
1415
|
return <input {...elementProps} ref={ref} />;
|
|
1411
1416
|
}
|
|
1412
1417
|
|
|
1413
|
-
export function QuestionnaireChoiceLabel(props:
|
|
1418
|
+
export function QuestionnaireChoiceLabel(props: QuestionnairePartProps) {
|
|
1414
1419
|
useChoice();
|
|
1415
1420
|
const elementProps = mergeProps(
|
|
1416
|
-
filterDOMProps(fromProps(props), { global: true }),
|
|
1417
|
-
styleProps(props),
|
|
1421
|
+
filterDOMProps(fromProps(cells(props)), { global: true }),
|
|
1422
|
+
styleProps(cells(props)),
|
|
1418
1423
|
);
|
|
1419
|
-
const render = props.render
|
|
1424
|
+
const render = props.render;
|
|
1420
1425
|
if (render !== undefined) return render(partRender(elementProps)) as JSXElement;
|
|
1421
1426
|
return <span {...elementProps}>{props.children}</span>;
|
|
1422
1427
|
}
|
|
@@ -1433,18 +1438,18 @@ export interface QuestionnaireChoiceShortcutProps extends StyleProps {
|
|
|
1433
1438
|
* `aria-hidden`, because the input already carries it in `aria-keyshortcuts`
|
|
1434
1439
|
* and reading it twice is noise.
|
|
1435
1440
|
*/
|
|
1436
|
-
export function QuestionnaireChoiceShortcut(props:
|
|
1441
|
+
export function QuestionnaireChoiceShortcut(props: QuestionnaireChoiceShortcutProps) {
|
|
1437
1442
|
const choice = useChoice();
|
|
1438
1443
|
const elementProps = mergeProps(
|
|
1439
|
-
filterDOMProps(fromProps(props), { global: true }),
|
|
1440
|
-
styleProps(props),
|
|
1444
|
+
filterDOMProps(fromProps(cells(props)), { global: true }),
|
|
1445
|
+
styleProps(cells(props)),
|
|
1441
1446
|
{
|
|
1442
1447
|
"aria-hidden": true,
|
|
1443
1448
|
hidden: () => choice.state.shortcut() === null,
|
|
1444
1449
|
"data-shortcut": () => choice.state.shortcut() ?? undefined,
|
|
1445
1450
|
},
|
|
1446
1451
|
);
|
|
1447
|
-
const render = props.render
|
|
1452
|
+
const render = props.render;
|
|
1448
1453
|
if (render !== undefined) {
|
|
1449
1454
|
return render(partRender(elementProps), { shortcut: choice.state.shortcut }) as JSXElement;
|
|
1450
1455
|
}
|
|
@@ -1486,15 +1491,15 @@ export interface QuestionnaireInputProps extends StyleProps {
|
|
|
1486
1491
|
}
|
|
1487
1492
|
|
|
1488
1493
|
/** A typed answer, on its own or beside the choices. */
|
|
1489
|
-
export function QuestionnaireInput(props:
|
|
1494
|
+
export function QuestionnaireInput(props: QuestionnaireInputProps) {
|
|
1490
1495
|
const item = useItem();
|
|
1491
|
-
const options = fromProps(props);
|
|
1496
|
+
const options = fromProps(cells(props));
|
|
1492
1497
|
const answerId = createUniqueId();
|
|
1493
1498
|
|
|
1494
|
-
const controlledValue = (): string | number | undefined => props.value
|
|
1495
|
-
const defaultFilled = (): boolean => hasInputValue(props.defaultValue
|
|
1499
|
+
const controlledValue = (): string | number | undefined => props.value;
|
|
1500
|
+
const defaultFilled = (): boolean => hasInputValue(props.defaultValue);
|
|
1496
1501
|
const [typed, setTyped] = createSignal(untrack(defaultFilled));
|
|
1497
|
-
const disabled = (): boolean => item.disabled() || (props.disabled
|
|
1502
|
+
const disabled = (): boolean => item.disabled() || (props.disabled ?? false);
|
|
1498
1503
|
const filled = (): boolean => {
|
|
1499
1504
|
const controlled = controlledValue();
|
|
1500
1505
|
return controlled === undefined ? typed() : hasInputValue(controlled);
|
|
@@ -1512,7 +1517,7 @@ export function QuestionnaireInput(props: Incoming<QuestionnaireInputProps>) {
|
|
|
1512
1517
|
unregister = undefined;
|
|
1513
1518
|
input = node;
|
|
1514
1519
|
if (node === null) return;
|
|
1515
|
-
const start = untrack(() => props.defaultValue
|
|
1520
|
+
const start = untrack(() => props.defaultValue);
|
|
1516
1521
|
// The content attribute, so a native reset has something to restore.
|
|
1517
1522
|
if (untrack(controlledValue) === undefined && start !== undefined) {
|
|
1518
1523
|
node.defaultValue = String(start);
|
|
@@ -1558,10 +1563,10 @@ export function QuestionnaireInput(props: Incoming<QuestionnaireInputProps>) {
|
|
|
1558
1563
|
id: false,
|
|
1559
1564
|
propNames: INPUT_PROPS,
|
|
1560
1565
|
}),
|
|
1561
|
-
styleProps(props),
|
|
1566
|
+
styleProps(cells(props)),
|
|
1562
1567
|
{
|
|
1563
1568
|
id: answerId,
|
|
1564
|
-
type: () => props.type
|
|
1569
|
+
type: () => props.type ?? "text",
|
|
1565
1570
|
disabled,
|
|
1566
1571
|
// Outside the form until it is the answer, so an abandoned draft is
|
|
1567
1572
|
// neither submitted nor validated.
|
|
@@ -1578,8 +1583,8 @@ export function QuestionnaireInput(props: Incoming<QuestionnaireInputProps>) {
|
|
|
1578
1583
|
props.value === undefined ? null : { value: () => String(controlledValue() ?? "") },
|
|
1579
1584
|
);
|
|
1580
1585
|
|
|
1581
|
-
const ref = mergeRefs(attach, props.ref
|
|
1582
|
-
const render = props.render
|
|
1586
|
+
const ref = mergeRefs(attach, props.ref);
|
|
1587
|
+
const render = props.render;
|
|
1583
1588
|
if (render !== undefined) {
|
|
1584
1589
|
const state: QuestionnaireInputState = { disabled, filled, invalid: item.invalid };
|
|
1585
1590
|
return render(partRender({ ...inputProps, ref }), state) as JSXElement;
|
|
@@ -1617,7 +1622,7 @@ interface NavigationOptions {
|
|
|
1617
1622
|
* Hidden rather than removed, so the row of actions keeps its columns and a
|
|
1618
1623
|
* layout does not jump when the last question swaps Next for Submit.
|
|
1619
1624
|
*/
|
|
1620
|
-
function
|
|
1625
|
+
function navigationButton(
|
|
1621
1626
|
props: Incoming<QuestionnaireButtonProps>,
|
|
1622
1627
|
navigation: NavigationOptions,
|
|
1623
1628
|
) {
|
|
@@ -1670,7 +1675,7 @@ function NavigationButton(
|
|
|
1670
1675
|
|
|
1671
1676
|
export function QuestionnairePrevious(props: Incoming<QuestionnaireButtonProps>) {
|
|
1672
1677
|
const root = useRoot();
|
|
1673
|
-
return
|
|
1678
|
+
return navigationButton(props, {
|
|
1674
1679
|
visible: () => root.total() > 1 && !root.first(),
|
|
1675
1680
|
label: "Previous",
|
|
1676
1681
|
type: "button",
|
|
@@ -1681,7 +1686,7 @@ export function QuestionnairePrevious(props: Incoming<QuestionnaireButtonProps>)
|
|
|
1681
1686
|
|
|
1682
1687
|
export function QuestionnaireSkip(props: Incoming<QuestionnaireButtonProps>) {
|
|
1683
1688
|
const root = useRoot();
|
|
1684
|
-
return
|
|
1689
|
+
return navigationButton(props, {
|
|
1685
1690
|
visible: () => root.activeRequired() === false,
|
|
1686
1691
|
label: "Skip",
|
|
1687
1692
|
type: "button",
|
|
@@ -1692,7 +1697,7 @@ export function QuestionnaireSkip(props: Incoming<QuestionnaireButtonProps>) {
|
|
|
1692
1697
|
|
|
1693
1698
|
export function QuestionnaireNext(props: Incoming<QuestionnaireButtonProps>) {
|
|
1694
1699
|
const root = useRoot();
|
|
1695
|
-
return
|
|
1700
|
+
return navigationButton(props, {
|
|
1696
1701
|
visible: () => root.total() > 1 && !root.last(),
|
|
1697
1702
|
label: "Next",
|
|
1698
1703
|
type: "button",
|
|
@@ -1703,7 +1708,7 @@ export function QuestionnaireNext(props: Incoming<QuestionnaireButtonProps>) {
|
|
|
1703
1708
|
|
|
1704
1709
|
export function QuestionnaireSubmit(props: Incoming<QuestionnaireButtonProps>) {
|
|
1705
1710
|
const root = useRoot();
|
|
1706
|
-
return
|
|
1711
|
+
return navigationButton(props, {
|
|
1707
1712
|
visible: () => root.total() > 0 && root.last(),
|
|
1708
1713
|
label: "Submit",
|
|
1709
1714
|
type: "submit",
|