@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/dialog.tsx
CHANGED
|
@@ -18,10 +18,14 @@
|
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
20
|
import {
|
|
21
|
+
cells,
|
|
21
22
|
type Accessor,
|
|
22
23
|
type Child,
|
|
24
|
+
createEffect,
|
|
23
25
|
type Incoming,
|
|
26
|
+
isDev,
|
|
24
27
|
onCleanup,
|
|
28
|
+
onSettled,
|
|
25
29
|
Show,
|
|
26
30
|
createSignal,
|
|
27
31
|
untrack,
|
|
@@ -35,7 +39,9 @@ import type { ElementRef } from "./interactions/press.ts";
|
|
|
35
39
|
import {
|
|
36
40
|
alignOf,
|
|
37
41
|
ariaHideOutside,
|
|
42
|
+
dismissButtonProps,
|
|
38
43
|
followOpen,
|
|
44
|
+
keepVisible,
|
|
39
45
|
modalOverlay,
|
|
40
46
|
overlay,
|
|
41
47
|
portalContainer,
|
|
@@ -52,6 +58,7 @@ import {
|
|
|
52
58
|
type OverlayTriggerState,
|
|
53
59
|
type Placement,
|
|
54
60
|
} from "./overlays.ts";
|
|
61
|
+
import { OverlayArrowProvider } from "./overlay-arrow.tsx";
|
|
55
62
|
import { presence } from "./presence.ts";
|
|
56
63
|
import {
|
|
57
64
|
access,
|
|
@@ -60,6 +67,7 @@ import {
|
|
|
60
67
|
fromProps,
|
|
61
68
|
id,
|
|
62
69
|
type MaybeAccessor,
|
|
70
|
+
clearTriggerSlot,
|
|
63
71
|
mergeProps,
|
|
64
72
|
type StyleProps,
|
|
65
73
|
styleProps,
|
|
@@ -90,6 +98,8 @@ export interface DialogResult {
|
|
|
90
98
|
* only once something has registered and goes again when it leaves.
|
|
91
99
|
*/
|
|
92
100
|
readonly describe: (has: boolean) => void;
|
|
101
|
+
/** The same for the title, which is what makes the dialog point at it. */
|
|
102
|
+
readonly title: (has: boolean) => void;
|
|
93
103
|
}
|
|
94
104
|
|
|
95
105
|
/**
|
|
@@ -107,13 +117,24 @@ export function dialog(options: DialogOptions = {}): DialogResult {
|
|
|
107
117
|
// A description registers from its own component body, so the write is one
|
|
108
118
|
// the body makes on purpose.
|
|
109
119
|
const [described, setDescribed] = createSignal(0, { ownedWrite: true });
|
|
110
|
-
const
|
|
120
|
+
const [titled, setTitled] = createSignal(0, { ownedWrite: true });
|
|
121
|
+
// The title's id is written until the dialog has settled, which is all the
|
|
122
|
+
// server ever renders: a title registers from an effect, and there are no
|
|
123
|
+
// effects there. Once settled, it is written only while a title is present,
|
|
124
|
+
// so a dialog without one points at nothing.
|
|
125
|
+
const [settled, setSettled] = createSignal(false);
|
|
126
|
+
onSettled(() => {
|
|
127
|
+
setSettled(true);
|
|
128
|
+
});
|
|
129
|
+
const labelled = (): string | undefined =>
|
|
130
|
+
access(options["aria-labelledby"]) ?? (titled() > 0 || !settled() ? titleId() : undefined);
|
|
111
131
|
|
|
112
132
|
return {
|
|
113
133
|
titleProps: { id: titleId },
|
|
114
134
|
descriptionProps: { id: descriptionId },
|
|
115
135
|
descriptionId,
|
|
116
136
|
describe: (has) => setDescribed((n) => n + (has ? 1 : -1)),
|
|
137
|
+
title: (has) => setTitled((n) => n + (has ? 1 : -1)),
|
|
117
138
|
dialogProps: mergeProps(filterDOMProps(options, { labelable: true }), {
|
|
118
139
|
role: () => access(options.role) ?? "dialog",
|
|
119
140
|
tabIndex: -1,
|
|
@@ -159,24 +180,39 @@ export interface DialogComponentProps extends StyleProps {
|
|
|
159
180
|
* </Dialog>
|
|
160
181
|
* ```
|
|
161
182
|
*/
|
|
162
|
-
export function Dialog(props:
|
|
183
|
+
export function Dialog(props: DialogComponentProps) {
|
|
163
184
|
const domRef = makeRef<HTMLElement>();
|
|
164
|
-
const options = fromProps(props);
|
|
165
|
-
const { dialogProps, titleProps, descriptionId, describe } = dialog(options);
|
|
166
|
-
|
|
167
|
-
provideDialog({ titleProps, descriptionId, describe });
|
|
185
|
+
const options = fromProps(cells(props));
|
|
186
|
+
const { dialogProps, titleProps, descriptionId, describe, title } = dialog(options);
|
|
187
|
+
|
|
188
|
+
provideDialog({ titleProps, descriptionId, describe, title });
|
|
189
|
+
|
|
190
|
+
if (isDev) {
|
|
191
|
+
onSettled(() => {
|
|
192
|
+
// After the title has had its chance to register, which happens as the
|
|
193
|
+
// content settles.
|
|
194
|
+
queueMicrotask(() => {
|
|
195
|
+
const element = domRef();
|
|
196
|
+
if (element === null || !element.isConnected) return;
|
|
197
|
+
if (element.hasAttribute("aria-label") || element.hasAttribute("aria-labelledby")) return;
|
|
198
|
+
console.warn(
|
|
199
|
+
'A Dialog with no <Heading slot="title"> needs an aria-label or an aria-labelledby, or a screen reader announces it with no name.',
|
|
200
|
+
);
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
}
|
|
168
204
|
|
|
169
205
|
const elementProps = mergeProps(
|
|
170
206
|
dialogProps,
|
|
171
207
|
filterDOMProps(options, { global: true }),
|
|
172
|
-
styleProps(props),
|
|
208
|
+
styleProps(cells(props)),
|
|
173
209
|
{
|
|
174
|
-
"data-testid": () => props["data-testid"]
|
|
210
|
+
"data-testid": () => props["data-testid"],
|
|
175
211
|
},
|
|
176
212
|
);
|
|
177
213
|
|
|
178
214
|
return (
|
|
179
|
-
<section {...elementProps} ref={mergeRefs(domRef.set, props.ref
|
|
215
|
+
<section {...elementProps} ref={mergeRefs(domRef.set, props.ref)}>
|
|
180
216
|
{props.children}
|
|
181
217
|
</section>
|
|
182
218
|
);
|
|
@@ -197,20 +233,30 @@ export interface HeadingComponentProps extends StyleProps {
|
|
|
197
233
|
* the platform's own headings are what a screen reader's heading list is built
|
|
198
234
|
* from.
|
|
199
235
|
*/
|
|
200
|
-
export function Heading(props:
|
|
201
|
-
const
|
|
236
|
+
export function Heading(props: HeadingComponentProps) {
|
|
237
|
+
const slots = getContext(DialogSlotsContext) ?? null;
|
|
238
|
+
const title = slots?.titleProps ?? null;
|
|
239
|
+
|
|
240
|
+
// Only a heading that says it is the title names the dialog, and only for
|
|
241
|
+
// as long as it is there.
|
|
242
|
+
createEffect(
|
|
243
|
+
() => props.slot === "title",
|
|
244
|
+
(isTitle) => {
|
|
245
|
+
if (!isTitle || slots === null) return undefined;
|
|
246
|
+
slots.title(true);
|
|
247
|
+
return () => slots.title(false);
|
|
248
|
+
},
|
|
249
|
+
);
|
|
202
250
|
|
|
203
251
|
const elementProps = mergeProps(
|
|
204
|
-
filterDOMProps(fromProps(props), { global: true }),
|
|
205
|
-
styleProps(props),
|
|
252
|
+
filterDOMProps(fromProps(cells(props)), { global: true }),
|
|
253
|
+
styleProps(cells(props)),
|
|
206
254
|
{
|
|
207
255
|
// The title names the dialog only when it says it is the title.
|
|
208
256
|
id: () =>
|
|
209
|
-
props.slot
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
"aria-level": () => props.level?.() ?? 3,
|
|
213
|
-
"data-testid": () => props["data-testid"]?.(),
|
|
257
|
+
props.slot === "title" ? access(title?.id as MaybeAccessor<string | undefined>) : props.id,
|
|
258
|
+
"aria-level": () => props.level ?? 3,
|
|
259
|
+
"data-testid": () => props["data-testid"],
|
|
214
260
|
},
|
|
215
261
|
);
|
|
216
262
|
|
|
@@ -266,8 +312,9 @@ function callerDirection(options: object): string | undefined {
|
|
|
266
312
|
return access((options as { dir?: MaybeAccessor<string | undefined> }).dir);
|
|
267
313
|
}
|
|
268
314
|
|
|
269
|
-
export function Modal(props:
|
|
270
|
-
|
|
315
|
+
export function Modal(props: ModalComponentProps) {
|
|
316
|
+
clearTriggerSlot();
|
|
317
|
+
const options = fromProps(cells(props));
|
|
271
318
|
const state = overlayTriggerState(options);
|
|
272
319
|
// Read here, where the modal is written. What it draws is portalled out from
|
|
273
320
|
// under the element that carries `dir`.
|
|
@@ -277,15 +324,15 @@ export function Modal(props: Incoming<ModalComponentProps>) {
|
|
|
277
324
|
<ModalContents
|
|
278
325
|
isOpen={state.isOpen()}
|
|
279
326
|
onClose={state.close}
|
|
280
|
-
isDismissable={props.isDismissable
|
|
281
|
-
isKeyboardDismissDisabled={props.isKeyboardDismissDisabled
|
|
282
|
-
isNonModal={props.isNonModal
|
|
283
|
-
autoFocus={props.autoFocus
|
|
284
|
-
underlayClass={props.underlayClass
|
|
285
|
-
underlaySlot={props.underlaySlot
|
|
286
|
-
underlayProps={props.underlayProps
|
|
287
|
-
class={props.class
|
|
288
|
-
style={props.style
|
|
327
|
+
isDismissable={props.isDismissable !== false}
|
|
328
|
+
isKeyboardDismissDisabled={props.isKeyboardDismissDisabled === true}
|
|
329
|
+
isNonModal={props.isNonModal === true}
|
|
330
|
+
autoFocus={props.autoFocus !== false}
|
|
331
|
+
underlayClass={props.underlayClass}
|
|
332
|
+
underlaySlot={props.underlaySlot}
|
|
333
|
+
underlayProps={props.underlayProps}
|
|
334
|
+
class={props.class ?? props.className}
|
|
335
|
+
style={props.style}
|
|
289
336
|
// The global attributes, the global events and every `data-*` the caller
|
|
290
337
|
// gave THIS component, forwarded to the element the caller can see. They
|
|
291
338
|
// cannot be spread on `<ModalContents>` itself: it is a private component
|
|
@@ -294,7 +341,7 @@ export function Modal(props: Incoming<ModalComponentProps>) {
|
|
|
294
341
|
domProps={mergeProps(filterDOMProps(options, { global: true }), {
|
|
295
342
|
dir: () => callerDirection(options) ?? direction(),
|
|
296
343
|
})}
|
|
297
|
-
contentRef={props.ref
|
|
344
|
+
contentRef={props.ref}
|
|
298
345
|
>
|
|
299
346
|
{props.children}
|
|
300
347
|
</ModalContents>
|
|
@@ -326,7 +373,7 @@ interface ContentsProps extends StyleProps {
|
|
|
326
373
|
* holds it only while the stylesheet is still drawing it, marked `data-closed`
|
|
327
374
|
* — and when nothing is animating, that is no time at all.
|
|
328
375
|
*/
|
|
329
|
-
function ModalContents(props:
|
|
376
|
+
function ModalContents(props: ContentsProps) {
|
|
330
377
|
// `<Show>`, not a bare `{() => …}`: a Cell at a component's root travels in
|
|
331
378
|
// the array its caller places, and an array hole is ONE effect — so the
|
|
332
379
|
// condition would become a dependency of whatever hole holds this component,
|
|
@@ -336,7 +383,7 @@ function ModalContents(props: Incoming<ContentsProps>) {
|
|
|
336
383
|
// created with the content it contains, because its disposal is what restores
|
|
337
384
|
// focus; the ref only has to outlive the content so the exit can be measured.
|
|
338
385
|
const domRef = makeRef<HTMLDivElement>();
|
|
339
|
-
const gate = presence({ isOpen: props.isOpen, ref: domRef });
|
|
386
|
+
const gate = presence({ isOpen: cells(props).isOpen, ref: domRef });
|
|
340
387
|
|
|
341
388
|
return (
|
|
342
389
|
<Show when={gate.isPresent()}>
|
|
@@ -344,18 +391,18 @@ function ModalContents(props: Incoming<ContentsProps>) {
|
|
|
344
391
|
<ModalBody
|
|
345
392
|
domRef={domRef}
|
|
346
393
|
isExiting={gate.isExiting()}
|
|
347
|
-
onClose={props.onClose
|
|
348
|
-
isDismissable={props.isDismissable
|
|
349
|
-
isKeyboardDismissDisabled={props.isKeyboardDismissDisabled
|
|
350
|
-
isNonModal={props.isNonModal
|
|
351
|
-
autoFocus={props.autoFocus
|
|
352
|
-
underlayClass={props.underlayClass
|
|
353
|
-
underlaySlot={props.underlaySlot
|
|
354
|
-
underlayProps={props.underlayProps
|
|
355
|
-
domProps={props.domProps
|
|
356
|
-
contentRef={props.contentRef
|
|
357
|
-
class={props.class
|
|
358
|
-
style={props.style
|
|
394
|
+
onClose={props.onClose}
|
|
395
|
+
isDismissable={props.isDismissable}
|
|
396
|
+
isKeyboardDismissDisabled={props.isKeyboardDismissDisabled}
|
|
397
|
+
isNonModal={props.isNonModal}
|
|
398
|
+
autoFocus={props.autoFocus}
|
|
399
|
+
underlayClass={props.underlayClass}
|
|
400
|
+
underlaySlot={props.underlaySlot}
|
|
401
|
+
underlayProps={props.underlayProps}
|
|
402
|
+
domProps={props.domProps}
|
|
403
|
+
contentRef={props.contentRef}
|
|
404
|
+
class={props.class}
|
|
405
|
+
style={props.style}
|
|
359
406
|
>
|
|
360
407
|
{props.children}
|
|
361
408
|
</ModalBody>
|
|
@@ -391,33 +438,33 @@ interface BodyProps extends StyleProps {
|
|
|
391
438
|
* on an element after it is removed, so the assertion passed for the wrong
|
|
392
439
|
* reason.
|
|
393
440
|
*/
|
|
394
|
-
function ModalBody(props:
|
|
395
|
-
const domRef = props.domRef
|
|
441
|
+
function ModalBody(props: BodyProps) {
|
|
442
|
+
const domRef = props.domRef;
|
|
396
443
|
const scope = focusScope({
|
|
397
|
-
contain: () => !props.isNonModal
|
|
444
|
+
contain: () => !props.isNonModal,
|
|
398
445
|
restoreFocus: true,
|
|
399
|
-
autoFocus: () => props.autoFocus
|
|
446
|
+
autoFocus: () => props.autoFocus,
|
|
400
447
|
});
|
|
401
448
|
|
|
402
449
|
const state: OverlayTriggerState = {
|
|
403
450
|
isOpen: () => true,
|
|
404
451
|
setOpen: (open) => {
|
|
405
|
-
if (!open) props.onClose()
|
|
452
|
+
if (!open) props.onClose();
|
|
406
453
|
},
|
|
407
454
|
open: () => {},
|
|
408
|
-
close: () => props.onClose()
|
|
409
|
-
toggle: () => props.onClose()
|
|
455
|
+
close: () => props.onClose(),
|
|
456
|
+
toggle: () => props.onClose(),
|
|
410
457
|
};
|
|
411
458
|
|
|
412
459
|
const { overlayProps, underlayProps, modalProps } = modalOverlay(
|
|
413
460
|
{
|
|
414
|
-
isDismissable: () => props.isDismissable
|
|
415
|
-
isKeyboardDismissDisabled: () => props.isKeyboardDismissDisabled
|
|
416
|
-
isScrollDisabled: () => props.isNonModal
|
|
417
|
-
isNonModal: () => props.isNonModal
|
|
461
|
+
isDismissable: () => props.isDismissable && !props.isNonModal,
|
|
462
|
+
isKeyboardDismissDisabled: () => props.isKeyboardDismissDisabled,
|
|
463
|
+
isScrollDisabled: () => props.isNonModal,
|
|
464
|
+
isNonModal: () => props.isNonModal,
|
|
418
465
|
// Focus is free to leave a dialog that is not modal, and Escape still
|
|
419
466
|
// belongs to it wherever focus went.
|
|
420
|
-
shouldCloseOnEscapeAnywhere: () => props.isNonModal
|
|
467
|
+
shouldCloseOnEscapeAnywhere: () => props.isNonModal,
|
|
421
468
|
},
|
|
422
469
|
state,
|
|
423
470
|
domRef,
|
|
@@ -426,8 +473,8 @@ function ModalBody(props: Incoming<BodyProps>) {
|
|
|
426
473
|
const elementProps = mergeProps(
|
|
427
474
|
overlayProps,
|
|
428
475
|
modalProps,
|
|
429
|
-
props.domProps
|
|
430
|
-
styleProps(props),
|
|
476
|
+
props.domProps ?? null,
|
|
477
|
+
styleProps(cells(props)),
|
|
431
478
|
);
|
|
432
479
|
|
|
433
480
|
// The caller's class joins the component's own rather than replacing it,
|
|
@@ -435,34 +482,37 @@ function ModalBody(props: Incoming<BodyProps>) {
|
|
|
435
482
|
const underlay = mergeProps(
|
|
436
483
|
underlayProps,
|
|
437
484
|
{
|
|
438
|
-
class: () => props.underlayClass
|
|
485
|
+
class: () => props.underlayClass,
|
|
439
486
|
// A `data-slot` like every other element in this package, and the reason
|
|
440
487
|
// is a consumer's stylesheet: `[data-barq-underlay]` is one global rule
|
|
441
488
|
// and cannot tell a dialog's backdrop from a sheet's. shadcn names them
|
|
442
489
|
// separately (`cn-dialog-overlay`, `cn-sheet-overlay`) and so can anyone
|
|
443
490
|
// styling these.
|
|
444
|
-
"data-slot": () => props.underlaySlot
|
|
491
|
+
"data-slot": () => props.underlaySlot,
|
|
445
492
|
},
|
|
446
493
|
// Taken once, as the body is built: the underlay's own attributes are
|
|
447
494
|
// accessors already, and the set of them does not change while it is open.
|
|
448
|
-
untrack(() => props.underlayProps
|
|
495
|
+
untrack(() => props.underlayProps) ?? null,
|
|
449
496
|
);
|
|
450
497
|
|
|
451
498
|
return (
|
|
452
499
|
<div
|
|
453
500
|
{...underlay}
|
|
454
501
|
data-barq-underlay
|
|
455
|
-
data-closed={props.isExiting
|
|
456
|
-
data-state={props.isExiting
|
|
502
|
+
data-closed={props.isExiting ? "" : undefined}
|
|
503
|
+
data-state={props.isExiting ? "closed" : "open"}
|
|
457
504
|
>
|
|
458
505
|
<span hidden ref={scope.startRef} />
|
|
459
506
|
<div
|
|
460
507
|
{...elementProps}
|
|
461
|
-
data-non-modal={props.isNonModal
|
|
462
|
-
data-closed={props.isExiting
|
|
463
|
-
data-state={props.isExiting
|
|
464
|
-
ref={mergeRefs(domRef.set, props.contentRef
|
|
508
|
+
data-non-modal={props.isNonModal ? "" : undefined}
|
|
509
|
+
data-closed={props.isExiting ? "" : undefined}
|
|
510
|
+
data-state={props.isExiting ? "closed" : "open"}
|
|
511
|
+
ref={mergeRefs(domRef.set, props.contentRef)}
|
|
465
512
|
>
|
|
513
|
+
<Show when={props.isDismissable && !props.isNonModal}>
|
|
514
|
+
<DismissButton onDismiss={props.onClose} />
|
|
515
|
+
</Show>
|
|
466
516
|
{props.children}
|
|
467
517
|
</div>
|
|
468
518
|
<span hidden ref={scope.endRef} />
|
|
@@ -472,8 +522,11 @@ function ModalBody(props: Incoming<BodyProps>) {
|
|
|
472
522
|
|
|
473
523
|
export interface PopoverComponentProps extends StyleProps {
|
|
474
524
|
children?: Child;
|
|
475
|
-
/**
|
|
476
|
-
|
|
525
|
+
/**
|
|
526
|
+
* The element the popover is anchored to. Without it, the trigger in scope
|
|
527
|
+
* ({@link providePopoverTrigger}) is.
|
|
528
|
+
*/
|
|
529
|
+
triggerRef?: ElementRef;
|
|
477
530
|
/**
|
|
478
531
|
* A box to place against instead of the trigger's own, in client
|
|
479
532
|
* coordinates. A context menu passes the point the pointer was at.
|
|
@@ -526,24 +579,43 @@ export interface PopoverComponentProps extends StyleProps {
|
|
|
526
579
|
* the right default for a menu or a colour picker; a date picker that must not
|
|
527
580
|
* be escaped sets `isModal`.
|
|
528
581
|
*/
|
|
529
|
-
export function Popover(props:
|
|
582
|
+
export function Popover(props: PopoverComponentProps) {
|
|
583
|
+
clearTriggerSlot();
|
|
530
584
|
const direction = declaredDirection();
|
|
531
585
|
const domRef = makeRef<HTMLDivElement>();
|
|
532
|
-
const options = fromProps(props);
|
|
533
|
-
const
|
|
586
|
+
const options = fromProps(cells(props));
|
|
587
|
+
const trigger = usePopoverTrigger();
|
|
588
|
+
const own = overlayTriggerState(options);
|
|
589
|
+
// The trigger in scope owns the state, unless this popover was told its own.
|
|
590
|
+
const fromTrigger = (): boolean =>
|
|
591
|
+
trigger !== null && props.isOpen === undefined && props.defaultOpen === undefined;
|
|
592
|
+
const state: OverlayTriggerState = {
|
|
593
|
+
isOpen: () => (fromTrigger() ? (trigger?.state.isOpen() ?? false) : own.isOpen()),
|
|
594
|
+
setOpen: (open) => {
|
|
595
|
+
if (fromTrigger()) trigger?.state.setOpen(open);
|
|
596
|
+
else own.setOpen(open);
|
|
597
|
+
},
|
|
598
|
+
open: () => state.setOpen(true),
|
|
599
|
+
close: () => state.setOpen(false),
|
|
600
|
+
toggle: () => state.setOpen(!state.isOpen()),
|
|
601
|
+
};
|
|
602
|
+
const containsFocus = (): boolean =>
|
|
603
|
+
(props.shouldContainFocus ?? access(trigger?.shouldContainFocus)) !== false;
|
|
534
604
|
const locale = useLocale();
|
|
535
|
-
const placement = (): Placement => props.placement
|
|
605
|
+
const placement = (): Placement => props.placement ?? "bottom";
|
|
536
606
|
|
|
607
|
+
const arrowRef = makeRef<Element>();
|
|
537
608
|
const position = overlayPosition({
|
|
538
|
-
targetRef: () => access(props.triggerRef
|
|
539
|
-
targetRect: () => props.triggerRect
|
|
609
|
+
targetRef: () => access(props.triggerRef ?? trigger?.triggerRef),
|
|
610
|
+
targetRect: () => props.triggerRect ?? null,
|
|
540
611
|
overlayRef: domRef,
|
|
612
|
+
arrowRef,
|
|
541
613
|
placement,
|
|
542
614
|
direction: () => locale().direction,
|
|
543
|
-
offset: () => props.offset
|
|
544
|
-
crossOffset: () => props.crossOffset
|
|
545
|
-
shouldFlip: () => props.shouldFlip
|
|
546
|
-
containerPadding: () => props.containerPadding
|
|
615
|
+
offset: () => props.offset ?? 8,
|
|
616
|
+
crossOffset: () => props.crossOffset,
|
|
617
|
+
shouldFlip: () => props.shouldFlip,
|
|
618
|
+
containerPadding: () => props.containerPadding,
|
|
547
619
|
isOpen: state.isOpen,
|
|
548
620
|
onClose: state.close,
|
|
549
621
|
});
|
|
@@ -553,44 +625,57 @@ export function Popover(props: Incoming<PopoverComponentProps>) {
|
|
|
553
625
|
// two are one overlay as far as an outside press and `aria-hidden` are
|
|
554
626
|
// concerned. Pressing a submenu item is not a press outside its menu.
|
|
555
627
|
const group = usePopoverGroup();
|
|
556
|
-
const nested = group !== null && props.isNested
|
|
628
|
+
const nested = group !== null && props.isNested === true;
|
|
557
629
|
const groupRef = makeRef<HTMLDivElement>();
|
|
558
630
|
|
|
559
631
|
const { overlayProps } = overlay(
|
|
560
632
|
{
|
|
561
633
|
isOpen: state.isOpen,
|
|
562
634
|
onClose: state.close,
|
|
563
|
-
isDismissable: () => props.isDismissable
|
|
564
|
-
isKeyboardDismissDisabled: () => props.isKeyboardDismissDisabled
|
|
635
|
+
isDismissable: () => props.isDismissable !== false,
|
|
636
|
+
isKeyboardDismissDisabled: () => props.isKeyboardDismissDisabled === true,
|
|
565
637
|
// Focus was never moved in, so Escape arrives wherever it already was.
|
|
566
|
-
shouldCloseOnEscapeAnywhere: () =>
|
|
638
|
+
shouldCloseOnEscapeAnywhere: () => !containsFocus(),
|
|
639
|
+
shouldCloseOnBlur: true,
|
|
567
640
|
groupRef: nested ? group : groupRef,
|
|
568
641
|
},
|
|
569
642
|
domRef,
|
|
570
643
|
);
|
|
571
644
|
|
|
572
|
-
preventScroll({ isDisabled: () => !state.isOpen() || props.isModal
|
|
645
|
+
preventScroll({ isDisabled: () => !state.isOpen() || props.isModal !== true });
|
|
573
646
|
|
|
647
|
+
// A modal popover hides the rest of the page. One that is not still has to
|
|
648
|
+
// be exempt from whatever is hiding the page around it: a list opened from
|
|
649
|
+
// inside a modal dialog is portalled out of the dialog, and the dialog's own
|
|
650
|
+
// hiding would otherwise take it for more of the page behind.
|
|
574
651
|
followOpen(
|
|
575
652
|
() =>
|
|
576
|
-
state.isOpen()
|
|
577
|
-
? (
|
|
653
|
+
state.isOpen()
|
|
654
|
+
? ([
|
|
655
|
+
((nested ? access(group) : groupRef()) as Element | null) ?? null,
|
|
656
|
+
props.isModal === true,
|
|
657
|
+
] as const)
|
|
578
658
|
: null,
|
|
579
|
-
(
|
|
659
|
+
(open) => {
|
|
660
|
+
if (open === null || open[0] === null) return undefined;
|
|
661
|
+
const [element, isModal] = open;
|
|
662
|
+
return isModal ? ariaHideOutside([element], { shouldUseInert: true }) : keepVisible(element);
|
|
663
|
+
},
|
|
580
664
|
);
|
|
581
665
|
|
|
582
666
|
const elementProps = mergeProps(
|
|
583
667
|
overlayProps,
|
|
584
668
|
position.overlayProps,
|
|
669
|
+
trigger?.overlayProps ?? null,
|
|
585
670
|
filterDOMProps(options, { global: true, labelable: true }),
|
|
586
671
|
// Portalled out from under the element that carries `dir`.
|
|
587
672
|
{ dir: () => callerDirection(options) ?? direction() },
|
|
588
|
-
styleProps(props),
|
|
673
|
+
styleProps(cells(props)),
|
|
589
674
|
{
|
|
590
675
|
"data-placement": position.placement,
|
|
591
676
|
"data-side": position.placement,
|
|
592
677
|
"data-align": () => alignOf(placement()),
|
|
593
|
-
"data-testid": () => props["data-testid"]
|
|
678
|
+
"data-testid": () => props["data-testid"],
|
|
594
679
|
},
|
|
595
680
|
);
|
|
596
681
|
|
|
@@ -617,15 +702,25 @@ export function Popover(props: Incoming<PopoverComponentProps>) {
|
|
|
617
702
|
than its own, so a submenu three deep is still one group. */}
|
|
618
703
|
<div ref={groupRef.set} style={{ display: "contents" }}>
|
|
619
704
|
<PopoverGroupProvider value={nested && group !== null ? group : groupRef} placed={placed}>
|
|
620
|
-
<
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
705
|
+
<OverlayArrowProvider
|
|
706
|
+
value={{
|
|
707
|
+
placement: position.placement,
|
|
708
|
+
arrowProps: position.arrowProps,
|
|
709
|
+
ref: arrowRef.set,
|
|
710
|
+
}}
|
|
626
711
|
>
|
|
627
|
-
|
|
628
|
-
|
|
712
|
+
<PopoverBody
|
|
713
|
+
elementProps={elementProps}
|
|
714
|
+
domRef={domRef}
|
|
715
|
+
forwardedRef={props.ref}
|
|
716
|
+
isExiting={gate.isExiting()}
|
|
717
|
+
containsFocus={containsFocus()}
|
|
718
|
+
isModal={props.isModal === true}
|
|
719
|
+
onDismiss={state.close}
|
|
720
|
+
>
|
|
721
|
+
{props.children}
|
|
722
|
+
</PopoverBody>
|
|
723
|
+
</OverlayArrowProvider>
|
|
629
724
|
</PopoverGroupProvider>
|
|
630
725
|
</div>
|
|
631
726
|
</Portal>
|
|
@@ -639,6 +734,8 @@ interface PopoverBodyProps {
|
|
|
639
734
|
forwardedRef?: RefTarget<HTMLDivElement>;
|
|
640
735
|
isExiting: boolean;
|
|
641
736
|
containsFocus: boolean;
|
|
737
|
+
isModal: boolean;
|
|
738
|
+
onDismiss: () => void;
|
|
642
739
|
children?: Child;
|
|
643
740
|
}
|
|
644
741
|
|
|
@@ -650,21 +747,27 @@ interface PopoverBodyProps {
|
|
|
650
747
|
* trigger. Called in `Popover`'s own body the scope outlives every open and
|
|
651
748
|
* close, so nothing is ever disposed and focus is left on `<body>`.
|
|
652
749
|
*/
|
|
653
|
-
function PopoverBody(props:
|
|
654
|
-
const domRef = props.domRef
|
|
655
|
-
const setElement = mergeRefs(domRef.set, props.forwardedRef
|
|
750
|
+
function PopoverBody(props: PopoverBodyProps) {
|
|
751
|
+
const domRef = props.domRef;
|
|
752
|
+
const setElement = mergeRefs(domRef.set, props.forwardedRef);
|
|
656
753
|
|
|
657
754
|
// Read once: a popover does not change its mind about focus while it is open,
|
|
658
755
|
// and a scope that came and went with a prop would restore focus mid-flight.
|
|
659
|
-
if (!props.containsFocus
|
|
756
|
+
if (!props.containsFocus) {
|
|
660
757
|
return (
|
|
661
758
|
<div
|
|
662
|
-
{...props.elementProps
|
|
663
|
-
data-closed={props.isExiting
|
|
664
|
-
data-state={props.isExiting
|
|
759
|
+
{...props.elementProps}
|
|
760
|
+
data-closed={props.isExiting ? "" : undefined}
|
|
761
|
+
data-state={props.isExiting ? "closed" : "open"}
|
|
665
762
|
ref={setElement}
|
|
666
763
|
>
|
|
764
|
+
<Show when={props.isModal}>
|
|
765
|
+
<DismissButton onDismiss={props.onDismiss} />
|
|
766
|
+
</Show>
|
|
667
767
|
{props.children}
|
|
768
|
+
<Show when={props.isModal}>
|
|
769
|
+
<DismissButton onDismiss={props.onDismiss} />
|
|
770
|
+
</Show>
|
|
668
771
|
</div>
|
|
669
772
|
);
|
|
670
773
|
}
|
|
@@ -675,18 +778,48 @@ function PopoverBody(props: Incoming<PopoverBodyProps>) {
|
|
|
675
778
|
<>
|
|
676
779
|
<span hidden ref={scope.startRef} />
|
|
677
780
|
<div
|
|
678
|
-
{...props.elementProps
|
|
679
|
-
data-closed={props.isExiting
|
|
680
|
-
data-state={props.isExiting
|
|
781
|
+
{...props.elementProps}
|
|
782
|
+
data-closed={props.isExiting ? "" : undefined}
|
|
783
|
+
data-state={props.isExiting ? "closed" : "open"}
|
|
681
784
|
ref={setElement}
|
|
682
785
|
>
|
|
786
|
+
<Show when={props.isModal}>
|
|
787
|
+
<DismissButton onDismiss={props.onDismiss} />
|
|
788
|
+
</Show>
|
|
683
789
|
{props.children}
|
|
790
|
+
<Show when={props.isModal}>
|
|
791
|
+
<DismissButton onDismiss={props.onDismiss} />
|
|
792
|
+
</Show>
|
|
684
793
|
</div>
|
|
685
794
|
<span hidden ref={scope.endRef} />
|
|
686
795
|
</>
|
|
687
796
|
);
|
|
688
797
|
}
|
|
689
798
|
|
|
799
|
+
export interface DismissButtonComponentProps {
|
|
800
|
+
/** Called when a screen reader activates it. */
|
|
801
|
+
onDismiss?: () => void;
|
|
802
|
+
/** @default "Dismiss", in the locale in scope */
|
|
803
|
+
"aria-label"?: string;
|
|
804
|
+
"aria-labelledby"?: string;
|
|
805
|
+
id?: string;
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
/**
|
|
809
|
+
* A button only a screen reader can find, that closes the overlay it is in.
|
|
810
|
+
*
|
|
811
|
+
* iOS VoiceOver has no Escape key: without one of these at the end of a
|
|
812
|
+
* popover, swiping past its last element leaves the popover open behind the
|
|
813
|
+
* user with no way back to close it.
|
|
814
|
+
*/
|
|
815
|
+
export function DismissButton(props: DismissButtonComponentProps) {
|
|
816
|
+
const elementProps = mergeProps(
|
|
817
|
+
dismissButtonProps(() => props.onDismiss?.()),
|
|
818
|
+
filterDOMProps(fromProps(cells(props)), { labelable: true }),
|
|
819
|
+
);
|
|
820
|
+
return <button {...elementProps} />;
|
|
821
|
+
}
|
|
822
|
+
|
|
690
823
|
export interface DialogTriggerComponentProps {
|
|
691
824
|
children?: Child;
|
|
692
825
|
isOpen?: boolean;
|
|
@@ -727,6 +860,43 @@ import { createContext, getContext, getOwner, install, provide } from "@barqjs/c
|
|
|
727
860
|
*/
|
|
728
861
|
const PopoverGroupContext = createContext<ElementRef | null>(null);
|
|
729
862
|
|
|
863
|
+
/**
|
|
864
|
+
* What opens a popover, for a {@link Popover} written inside it with no
|
|
865
|
+
* `triggerRef` and no `isOpen` of its own.
|
|
866
|
+
*/
|
|
867
|
+
export interface PopoverTriggerValue {
|
|
868
|
+
/** The element the popover is anchored to. */
|
|
869
|
+
triggerRef: ElementRef;
|
|
870
|
+
/** Whether it is open, and how the popover closes it. */
|
|
871
|
+
state: OverlayTriggerState;
|
|
872
|
+
/** Props for the popover's own element: the id the trigger points at, handlers. */
|
|
873
|
+
overlayProps?: DOMProps;
|
|
874
|
+
/** @default true */
|
|
875
|
+
shouldContainFocus?: MaybeAccessor<boolean | undefined>;
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
const PopoverTriggerContext = createContext<PopoverTriggerValue | null>(null);
|
|
879
|
+
|
|
880
|
+
/**
|
|
881
|
+
* Offer a trigger to the popovers written inside `children`.
|
|
882
|
+
*
|
|
883
|
+
* A trigger of a new kind (a hover preview, a toolbar's overflow) provides
|
|
884
|
+
* this and renders the ordinary `<Popover>`, rather than a popover component
|
|
885
|
+
* of its own that passes the same four props through.
|
|
886
|
+
*/
|
|
887
|
+
export function providePopoverTrigger(value: PopoverTriggerValue, children: () => Child): Child {
|
|
888
|
+
return provide(
|
|
889
|
+
PopoverTriggerContext,
|
|
890
|
+
() => value,
|
|
891
|
+
() => children() as unknown,
|
|
892
|
+
) as Child;
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
/** The trigger in scope, if one was provided. */
|
|
896
|
+
export function usePopoverTrigger(): PopoverTriggerValue | null {
|
|
897
|
+
return getContext(PopoverTriggerContext) ?? null;
|
|
898
|
+
}
|
|
899
|
+
|
|
730
900
|
/** The enclosing popover's container, if this is inside one. */
|
|
731
901
|
export function usePopoverGroup(): ElementRef | null {
|
|
732
902
|
return getContext(PopoverGroupContext) ?? null;
|
|
@@ -768,17 +938,25 @@ export function popoverStateProps(): DOMProps {
|
|
|
768
938
|
};
|
|
769
939
|
}
|
|
770
940
|
|
|
771
|
-
function PopoverGroupProvider(
|
|
772
|
-
|
|
773
|
-
|
|
941
|
+
function PopoverGroupProvider(props: {
|
|
942
|
+
value: ElementRef;
|
|
943
|
+
placed: PopoverPlacement;
|
|
944
|
+
children?: Child;
|
|
945
|
+
}) {
|
|
774
946
|
return provide(
|
|
775
947
|
PopoverGroupContext,
|
|
776
|
-
() => props.value
|
|
948
|
+
() => props.value,
|
|
777
949
|
() =>
|
|
778
950
|
provide(
|
|
779
951
|
PopoverPlacementContext,
|
|
780
|
-
() => props.placed
|
|
781
|
-
|
|
952
|
+
() => props.placed,
|
|
953
|
+
// A popover opened from inside this one has a trigger of its own.
|
|
954
|
+
() =>
|
|
955
|
+
provide(
|
|
956
|
+
PopoverTriggerContext,
|
|
957
|
+
() => null,
|
|
958
|
+
() => props.children as unknown,
|
|
959
|
+
),
|
|
782
960
|
),
|
|
783
961
|
);
|
|
784
962
|
}
|
|
@@ -820,6 +998,7 @@ interface DialogSlots {
|
|
|
820
998
|
titleProps: DOMProps;
|
|
821
999
|
descriptionId: Accessor<string>;
|
|
822
1000
|
readonly describe: (has: boolean) => void;
|
|
1001
|
+
readonly title: (has: boolean) => void;
|
|
823
1002
|
}
|
|
824
1003
|
|
|
825
1004
|
export interface DialogDescription {
|
|
@@ -833,9 +1012,17 @@ function provideDialog(slots: DialogSlots): void {
|
|
|
833
1012
|
if (owner !== null) install(owner, DialogSlotsContext, () => slots);
|
|
834
1013
|
}
|
|
835
1014
|
|
|
836
|
-
/**
|
|
1015
|
+
/**
|
|
1016
|
+
* The props the enclosing dialog's title element must carry, and the
|
|
1017
|
+
* registration that makes the dialog point at it, for as long as the caller
|
|
1018
|
+
* is rendered: a design system's own heading names the dialog this way.
|
|
1019
|
+
*/
|
|
837
1020
|
export function useDialogTitle(): DOMProps | null {
|
|
838
|
-
|
|
1021
|
+
const slots = getContext(DialogSlotsContext);
|
|
1022
|
+
if (slots === null || slots === undefined) return null;
|
|
1023
|
+
slots.title(true);
|
|
1024
|
+
onCleanup(() => slots.title(false));
|
|
1025
|
+
return slots.titleProps;
|
|
839
1026
|
}
|
|
840
1027
|
|
|
841
1028
|
/**
|