@lostgradient/cinder 0.24.2 → 0.24.3
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/CHANGELOG.md +18 -0
- package/components.json +1 -1
- package/dist/components/alert-dialog/index.js +31 -4
- package/dist/components/confirm-dialog/index.js +31 -4
- package/dist/components/drawer/index.js +31 -4
- package/dist/components/focus-trap/focus-trap.schema.js +16 -1
- package/dist/components/focus-trap/focus-trap.types.d.ts +6 -0
- package/dist/components/focus-trap/focus-trap.utilities.svelte.d.ts +37 -0
- package/dist/components/focus-trap/index.js +31 -4
- package/dist/components/modal/index.js +31 -4
- package/dist/components/sidebar/index.js +31 -4
- package/dist/index.js +31 -4
- package/dist/server/components/alert-dialog/index.js +1 -1
- package/dist/server/components/confirm-dialog/index.js +1 -1
- package/dist/server/components/drawer/index.js +1 -1
- package/dist/server/components/focus-trap/index.js +1 -1
- package/dist/server/components/modal/index.js +1 -1
- package/dist/server/components/sidebar/index.js +1 -1
- package/dist/server/index.js +1 -1
- package/dist/server/{index.server-r5emexd4.js → index.server-es919z55.js} +27 -2
- package/package.json +1 -1
- package/src/components/focus-trap/focus-trap.schema.json +15 -0
- package/src/components/focus-trap/focus-trap.schema.ts +17 -0
- package/src/components/focus-trap/focus-trap.svelte +3 -1
- package/src/components/focus-trap/focus-trap.types.ts +6 -0
- package/src/components/focus-trap/focus-trap.utilities.svelte.ts +41 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @lostgradient/cinder
|
|
2
2
|
|
|
3
|
+
## 0.24.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#1293](https://github.com/stevekinney/cinder/pull/1293) [`5bd476a`](https://github.com/stevekinney/cinder/commit/5bd476a74c1f04bf76e4689268d2256ee490dc58) Thanks [@stevekinney](https://github.com/stevekinney)! - Give `createFocusTrap` a `restoreFallback`, so closing an overlay whose opener has been removed no longer drops focus on `<body>`.
|
|
8
|
+
|
|
9
|
+
The trap captured the focused element on activation and handed it to `restoreFocusTo` on deactivation. That helper correctly refuses to focus a disconnected node — and its return value was discarded, so when the control that opened the overlay had been removed in the meantime, nothing else happened and focus landed nowhere. A screen reader says nothing; a keyboard user's next Tab restarts at the top of the document.
|
|
10
|
+
|
|
11
|
+
The reachable instance is `ReviewEditor`'s thread popover: deleting a thread from inside its own popover removes the sidebar item the popover was opened from, so the restore target is gone by the time the trap runs. It only bites a consumer that actually applies `onthreaddelete`, which is why notification-only demos never showed it — their sidebar item survives the delete.
|
|
12
|
+
|
|
13
|
+
`restoreFallback` is consulted only when restoring to the captured element fails, so supplying it can never override a restore that would have worked, and it is resolved against the document rather than the trap root because a restore target lives outside the trap by definition and the trap's own node is usually already detached by then. A restore now also counts as successful only when focus actually lands: `restoreFocusTo` reports success whenever `.focus()` did not throw, which is equally true of a still-connected element that has since become `disabled` or `inert`.
|
|
14
|
+
|
|
15
|
+
A companion `preferRestoreFallback` covers the asynchronous case. A consumer whose delete handler waits on a server keeps the opener mounted while the request is in flight, so restoration finds it perfectly focusable, hands focus back, and then watches it unmount — landing on `<body>` after all. `ThreadPopover` sets it once a delete has been requested. It reorders the candidates rather than discarding one, so a missing fallback still falls through to the captured element.
|
|
16
|
+
|
|
17
|
+
`ReviewEditor` points the popover at that editor instance's comments-sidebar toggle — always mounted, always focusable, adjacent to the work, and its label announces the changed comment count. The toggle gained an `id` so the target can be resolved with `getElementById` rather than an attribute selector: the editor `id` is consumer-supplied and only has to be a valid HTML id, so it may contain `"` or `\`, which would make an interpolated selector invalid and fail silently — back to `<body>`.
|
|
18
|
+
|
|
19
|
+
Fixes [#1291](https://github.com/stevekinney/cinder/issues/1291).
|
|
20
|
+
|
|
3
21
|
## 0.24.2
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
package/components.json
CHANGED
|
@@ -439,6 +439,23 @@ function getFallbackTarget(root, fallbackFocus) {
|
|
|
439
439
|
const resolved = resolveScopedTarget(root, fallbackFocus);
|
|
440
440
|
return resolved && isProgrammaticallyFocusable(resolved) ? resolved : null;
|
|
441
441
|
}
|
|
442
|
+
function getRestoreFallbackTarget(restoreFallback) {
|
|
443
|
+
const resolved = readOption(restoreFallback);
|
|
444
|
+
if (!resolved)
|
|
445
|
+
return null;
|
|
446
|
+
if (typeof resolved === "string") {
|
|
447
|
+
if (typeof document === "undefined")
|
|
448
|
+
return null;
|
|
449
|
+
let match;
|
|
450
|
+
try {
|
|
451
|
+
match = document.querySelector(resolved);
|
|
452
|
+
} catch {
|
|
453
|
+
return null;
|
|
454
|
+
}
|
|
455
|
+
return match && isProgrammaticallyFocusable(match) ? match : null;
|
|
456
|
+
}
|
|
457
|
+
return resolved instanceof HTMLElement && isProgrammaticallyFocusable(resolved) ? resolved : null;
|
|
458
|
+
}
|
|
442
459
|
function tryFocus(element) {
|
|
443
460
|
element.focus();
|
|
444
461
|
return document.activeElement === element;
|
|
@@ -475,6 +492,8 @@ function createFocusTrap(options = {}) {
|
|
|
475
492
|
const restoreFocus = options.restoreFocus ?? true;
|
|
476
493
|
const initialFocus = options.initialFocus ?? null;
|
|
477
494
|
const fallbackFocus = options.fallbackFocus ?? null;
|
|
495
|
+
const restoreFallback = options.restoreFallback ?? null;
|
|
496
|
+
const preferRestoreFallback = options.preferRestoreFallback ?? false;
|
|
478
497
|
const manageInitialFocus = options.manageInitialFocus ?? true;
|
|
479
498
|
let activated = false;
|
|
480
499
|
let activationGeneration = 0;
|
|
@@ -519,7 +538,11 @@ function createFocusTrap(options = {}) {
|
|
|
519
538
|
restoreRootFocusability = noop;
|
|
520
539
|
removeTrap(trapId);
|
|
521
540
|
if (restoreFocus) {
|
|
522
|
-
|
|
541
|
+
const candidates = readOption(preferRestoreFallback ?? false) ? [getRestoreFallbackTarget(restoreFallback), capturedFocus] : [capturedFocus, getRestoreFallbackTarget(restoreFallback)];
|
|
542
|
+
for (const candidate of candidates) {
|
|
543
|
+
if (restoreFocusTo(candidate) && document.activeElement === candidate)
|
|
544
|
+
break;
|
|
545
|
+
}
|
|
523
546
|
}
|
|
524
547
|
capturedFocus = null;
|
|
525
548
|
}
|
|
@@ -572,13 +595,15 @@ var rest_excludes = new Set([
|
|
|
572
595
|
"restoreFocus",
|
|
573
596
|
"initialFocus",
|
|
574
597
|
"fallbackFocus",
|
|
598
|
+
"restoreFallback",
|
|
599
|
+
"preferRestoreFallback",
|
|
575
600
|
"class",
|
|
576
601
|
"children"
|
|
577
602
|
]);
|
|
578
603
|
var root = $2.from_html(`<div><!></div>`);
|
|
579
604
|
function Focus_trap($$anchor, $$props) {
|
|
580
605
|
$2.push($$props, true);
|
|
581
|
-
let active = $2.prop($$props, "active", 3, true), restoreFocus = $2.prop($$props, "restoreFocus", 3, true), initialFocus = $2.prop($$props, "initialFocus", 3, null), fallbackFocus = $2.prop($$props, "fallbackFocus", 3, null), rest = $2.rest_props($$props, rest_excludes);
|
|
606
|
+
let active = $2.prop($$props, "active", 3, true), restoreFocus = $2.prop($$props, "restoreFocus", 3, true), initialFocus = $2.prop($$props, "initialFocus", 3, null), fallbackFocus = $2.prop($$props, "fallbackFocus", 3, null), restoreFallback = $2.prop($$props, "restoreFallback", 3, null), preferRestoreFallback = $2.prop($$props, "preferRestoreFallback", 3, false), rest = $2.rest_props($$props, rest_excludes);
|
|
582
607
|
var div = root();
|
|
583
608
|
$2.attribute_effect(div, ($0) => ({ class: $0, ...rest }), [() => classNames($$props.class)]);
|
|
584
609
|
var node = $2.child(div);
|
|
@@ -588,7 +613,9 @@ function Focus_trap($$anchor, $$props) {
|
|
|
588
613
|
active: () => active(),
|
|
589
614
|
restoreFocus: restoreFocus(),
|
|
590
615
|
initialFocus: () => initialFocus(),
|
|
591
|
-
fallbackFocus: () => fallbackFocus()
|
|
616
|
+
fallbackFocus: () => fallbackFocus(),
|
|
617
|
+
restoreFallback: () => restoreFallback(),
|
|
618
|
+
preferRestoreFallback: () => preferRestoreFallback()
|
|
592
619
|
}));
|
|
593
620
|
$2.append($$anchor, div);
|
|
594
621
|
$2.pop();
|
|
@@ -1641,4 +1668,4 @@ export {
|
|
|
1641
1668
|
Alert_dialog as AlertDialog
|
|
1642
1669
|
};
|
|
1643
1670
|
|
|
1644
|
-
//# debugId=
|
|
1671
|
+
//# debugId=465BE598F4728E6264756E2164756E21
|
|
@@ -439,6 +439,23 @@ function getFallbackTarget(root, fallbackFocus) {
|
|
|
439
439
|
const resolved = resolveScopedTarget(root, fallbackFocus);
|
|
440
440
|
return resolved && isProgrammaticallyFocusable(resolved) ? resolved : null;
|
|
441
441
|
}
|
|
442
|
+
function getRestoreFallbackTarget(restoreFallback) {
|
|
443
|
+
const resolved = readOption(restoreFallback);
|
|
444
|
+
if (!resolved)
|
|
445
|
+
return null;
|
|
446
|
+
if (typeof resolved === "string") {
|
|
447
|
+
if (typeof document === "undefined")
|
|
448
|
+
return null;
|
|
449
|
+
let match;
|
|
450
|
+
try {
|
|
451
|
+
match = document.querySelector(resolved);
|
|
452
|
+
} catch {
|
|
453
|
+
return null;
|
|
454
|
+
}
|
|
455
|
+
return match && isProgrammaticallyFocusable(match) ? match : null;
|
|
456
|
+
}
|
|
457
|
+
return resolved instanceof HTMLElement && isProgrammaticallyFocusable(resolved) ? resolved : null;
|
|
458
|
+
}
|
|
442
459
|
function tryFocus(element) {
|
|
443
460
|
element.focus();
|
|
444
461
|
return document.activeElement === element;
|
|
@@ -475,6 +492,8 @@ function createFocusTrap(options = {}) {
|
|
|
475
492
|
const restoreFocus = options.restoreFocus ?? true;
|
|
476
493
|
const initialFocus = options.initialFocus ?? null;
|
|
477
494
|
const fallbackFocus = options.fallbackFocus ?? null;
|
|
495
|
+
const restoreFallback = options.restoreFallback ?? null;
|
|
496
|
+
const preferRestoreFallback = options.preferRestoreFallback ?? false;
|
|
478
497
|
const manageInitialFocus = options.manageInitialFocus ?? true;
|
|
479
498
|
let activated = false;
|
|
480
499
|
let activationGeneration = 0;
|
|
@@ -519,7 +538,11 @@ function createFocusTrap(options = {}) {
|
|
|
519
538
|
restoreRootFocusability = noop;
|
|
520
539
|
removeTrap(trapId);
|
|
521
540
|
if (restoreFocus) {
|
|
522
|
-
|
|
541
|
+
const candidates = readOption(preferRestoreFallback ?? false) ? [getRestoreFallbackTarget(restoreFallback), capturedFocus] : [capturedFocus, getRestoreFallbackTarget(restoreFallback)];
|
|
542
|
+
for (const candidate of candidates) {
|
|
543
|
+
if (restoreFocusTo(candidate) && document.activeElement === candidate)
|
|
544
|
+
break;
|
|
545
|
+
}
|
|
523
546
|
}
|
|
524
547
|
capturedFocus = null;
|
|
525
548
|
}
|
|
@@ -572,13 +595,15 @@ var rest_excludes = new Set([
|
|
|
572
595
|
"restoreFocus",
|
|
573
596
|
"initialFocus",
|
|
574
597
|
"fallbackFocus",
|
|
598
|
+
"restoreFallback",
|
|
599
|
+
"preferRestoreFallback",
|
|
575
600
|
"class",
|
|
576
601
|
"children"
|
|
577
602
|
]);
|
|
578
603
|
var root = $2.from_html(`<div><!></div>`);
|
|
579
604
|
function Focus_trap($$anchor, $$props) {
|
|
580
605
|
$2.push($$props, true);
|
|
581
|
-
let active = $2.prop($$props, "active", 3, true), restoreFocus = $2.prop($$props, "restoreFocus", 3, true), initialFocus = $2.prop($$props, "initialFocus", 3, null), fallbackFocus = $2.prop($$props, "fallbackFocus", 3, null), rest = $2.rest_props($$props, rest_excludes);
|
|
606
|
+
let active = $2.prop($$props, "active", 3, true), restoreFocus = $2.prop($$props, "restoreFocus", 3, true), initialFocus = $2.prop($$props, "initialFocus", 3, null), fallbackFocus = $2.prop($$props, "fallbackFocus", 3, null), restoreFallback = $2.prop($$props, "restoreFallback", 3, null), preferRestoreFallback = $2.prop($$props, "preferRestoreFallback", 3, false), rest = $2.rest_props($$props, rest_excludes);
|
|
582
607
|
var div = root();
|
|
583
608
|
$2.attribute_effect(div, ($0) => ({ class: $0, ...rest }), [() => classNames($$props.class)]);
|
|
584
609
|
var node = $2.child(div);
|
|
@@ -588,7 +613,9 @@ function Focus_trap($$anchor, $$props) {
|
|
|
588
613
|
active: () => active(),
|
|
589
614
|
restoreFocus: restoreFocus(),
|
|
590
615
|
initialFocus: () => initialFocus(),
|
|
591
|
-
fallbackFocus: () => fallbackFocus()
|
|
616
|
+
fallbackFocus: () => fallbackFocus(),
|
|
617
|
+
restoreFallback: () => restoreFallback(),
|
|
618
|
+
preferRestoreFallback: () => preferRestoreFallback()
|
|
592
619
|
}));
|
|
593
620
|
$2.append($$anchor, div);
|
|
594
621
|
$2.pop();
|
|
@@ -2459,4 +2486,4 @@ export {
|
|
|
2459
2486
|
Confirm_dialog as ConfirmDialog
|
|
2460
2487
|
};
|
|
2461
2488
|
|
|
2462
|
-
//# debugId=
|
|
2489
|
+
//# debugId=EDDA979B9903E24464756E2164756E21
|
|
@@ -439,6 +439,23 @@ function getFallbackTarget(root, fallbackFocus) {
|
|
|
439
439
|
const resolved = resolveScopedTarget(root, fallbackFocus);
|
|
440
440
|
return resolved && isProgrammaticallyFocusable(resolved) ? resolved : null;
|
|
441
441
|
}
|
|
442
|
+
function getRestoreFallbackTarget(restoreFallback) {
|
|
443
|
+
const resolved = readOption(restoreFallback);
|
|
444
|
+
if (!resolved)
|
|
445
|
+
return null;
|
|
446
|
+
if (typeof resolved === "string") {
|
|
447
|
+
if (typeof document === "undefined")
|
|
448
|
+
return null;
|
|
449
|
+
let match;
|
|
450
|
+
try {
|
|
451
|
+
match = document.querySelector(resolved);
|
|
452
|
+
} catch {
|
|
453
|
+
return null;
|
|
454
|
+
}
|
|
455
|
+
return match && isProgrammaticallyFocusable(match) ? match : null;
|
|
456
|
+
}
|
|
457
|
+
return resolved instanceof HTMLElement && isProgrammaticallyFocusable(resolved) ? resolved : null;
|
|
458
|
+
}
|
|
442
459
|
function tryFocus(element) {
|
|
443
460
|
element.focus();
|
|
444
461
|
return document.activeElement === element;
|
|
@@ -475,6 +492,8 @@ function createFocusTrap(options = {}) {
|
|
|
475
492
|
const restoreFocus = options.restoreFocus ?? true;
|
|
476
493
|
const initialFocus = options.initialFocus ?? null;
|
|
477
494
|
const fallbackFocus = options.fallbackFocus ?? null;
|
|
495
|
+
const restoreFallback = options.restoreFallback ?? null;
|
|
496
|
+
const preferRestoreFallback = options.preferRestoreFallback ?? false;
|
|
478
497
|
const manageInitialFocus = options.manageInitialFocus ?? true;
|
|
479
498
|
let activated = false;
|
|
480
499
|
let activationGeneration = 0;
|
|
@@ -519,7 +538,11 @@ function createFocusTrap(options = {}) {
|
|
|
519
538
|
restoreRootFocusability = noop;
|
|
520
539
|
removeTrap(trapId);
|
|
521
540
|
if (restoreFocus) {
|
|
522
|
-
|
|
541
|
+
const candidates = readOption(preferRestoreFallback ?? false) ? [getRestoreFallbackTarget(restoreFallback), capturedFocus] : [capturedFocus, getRestoreFallbackTarget(restoreFallback)];
|
|
542
|
+
for (const candidate of candidates) {
|
|
543
|
+
if (restoreFocusTo(candidate) && document.activeElement === candidate)
|
|
544
|
+
break;
|
|
545
|
+
}
|
|
523
546
|
}
|
|
524
547
|
capturedFocus = null;
|
|
525
548
|
}
|
|
@@ -572,13 +595,15 @@ var rest_excludes = new Set([
|
|
|
572
595
|
"restoreFocus",
|
|
573
596
|
"initialFocus",
|
|
574
597
|
"fallbackFocus",
|
|
598
|
+
"restoreFallback",
|
|
599
|
+
"preferRestoreFallback",
|
|
575
600
|
"class",
|
|
576
601
|
"children"
|
|
577
602
|
]);
|
|
578
603
|
var root = $2.from_html(`<div><!></div>`);
|
|
579
604
|
function Focus_trap($$anchor, $$props) {
|
|
580
605
|
$2.push($$props, true);
|
|
581
|
-
let active = $2.prop($$props, "active", 3, true), restoreFocus = $2.prop($$props, "restoreFocus", 3, true), initialFocus = $2.prop($$props, "initialFocus", 3, null), fallbackFocus = $2.prop($$props, "fallbackFocus", 3, null), rest = $2.rest_props($$props, rest_excludes);
|
|
606
|
+
let active = $2.prop($$props, "active", 3, true), restoreFocus = $2.prop($$props, "restoreFocus", 3, true), initialFocus = $2.prop($$props, "initialFocus", 3, null), fallbackFocus = $2.prop($$props, "fallbackFocus", 3, null), restoreFallback = $2.prop($$props, "restoreFallback", 3, null), preferRestoreFallback = $2.prop($$props, "preferRestoreFallback", 3, false), rest = $2.rest_props($$props, rest_excludes);
|
|
582
607
|
var div = root();
|
|
583
608
|
$2.attribute_effect(div, ($0) => ({ class: $0, ...rest }), [() => classNames($$props.class)]);
|
|
584
609
|
var node = $2.child(div);
|
|
@@ -588,7 +613,9 @@ function Focus_trap($$anchor, $$props) {
|
|
|
588
613
|
active: () => active(),
|
|
589
614
|
restoreFocus: restoreFocus(),
|
|
590
615
|
initialFocus: () => initialFocus(),
|
|
591
|
-
fallbackFocus: () => fallbackFocus()
|
|
616
|
+
fallbackFocus: () => fallbackFocus(),
|
|
617
|
+
restoreFallback: () => restoreFallback(),
|
|
618
|
+
preferRestoreFallback: () => preferRestoreFallback()
|
|
592
619
|
}));
|
|
593
620
|
$2.append($$anchor, div);
|
|
594
621
|
$2.pop();
|
|
@@ -1355,4 +1382,4 @@ export {
|
|
|
1355
1382
|
Drawer
|
|
1356
1383
|
};
|
|
1357
1384
|
|
|
1358
|
-
//# debugId=
|
|
1385
|
+
//# debugId=04305779D28BD7B664756E2164756E21
|
|
@@ -86,6 +86,21 @@ var schema = {
|
|
|
86
86
|
],
|
|
87
87
|
description: "CSS selector for the element that receives focus when `initialFocus` is unset or unresolvable. Defaults to the trap container itself."
|
|
88
88
|
},
|
|
89
|
+
restoreFallback: {
|
|
90
|
+
anyOf: [
|
|
91
|
+
{
|
|
92
|
+
type: "string"
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
type: "null"
|
|
96
|
+
}
|
|
97
|
+
],
|
|
98
|
+
description: "CSS selector, resolved against the document, for the element that receives focus when the previously focused element cannot take it back — typically because it was removed from the DOM while the trap was open. Without it, focus falls to `<body>`."
|
|
99
|
+
},
|
|
100
|
+
preferRestoreFallback: {
|
|
101
|
+
type: "boolean",
|
|
102
|
+
description: "When true, `restoreFallback` is tried before the previously focused element rather than only after it. For hosts that know the captured element is about to be removed but cannot prove it yet, such as a delete that awaits a server round trip."
|
|
103
|
+
},
|
|
89
104
|
class: {
|
|
90
105
|
type: "string",
|
|
91
106
|
description: "Additional class applied to the focus-trap wrapper element."
|
|
@@ -107,4 +122,4 @@ export {
|
|
|
107
122
|
focus_trap_schema_default as default
|
|
108
123
|
};
|
|
109
124
|
|
|
110
|
-
//# debugId=
|
|
125
|
+
//# debugId=A5E192B047DA2F2964756E2164756E21
|
|
@@ -7,6 +7,8 @@ export type FocusTrapProps = Omit<HTMLAttributes<HTMLDivElement>, 'children' | '
|
|
|
7
7
|
restoreFocus?: boolean;
|
|
8
8
|
initialFocus?: Exclude<FocusTargetInput, Function>;
|
|
9
9
|
fallbackFocus?: Exclude<FocusTargetInput, Function>;
|
|
10
|
+
restoreFallback?: Exclude<FocusTargetInput, Function>;
|
|
11
|
+
preferRestoreFallback?: boolean;
|
|
10
12
|
class?: string;
|
|
11
13
|
};
|
|
12
14
|
export interface FocusTrapSchemaProps {
|
|
@@ -18,6 +20,10 @@ export interface FocusTrapSchemaProps {
|
|
|
18
20
|
initialFocus?: string | null;
|
|
19
21
|
/** CSS selector for the element that receives focus when `initialFocus` is unset or unresolvable. Defaults to the trap container itself. */
|
|
20
22
|
fallbackFocus?: string | null;
|
|
23
|
+
/** CSS selector, resolved against the document, for the element that receives focus when the previously focused element cannot take it back — typically because it was removed from the DOM while the trap was open. Without it, focus falls to `<body>`. */
|
|
24
|
+
restoreFallback?: string | null;
|
|
25
|
+
/** When true, `restoreFallback` is tried before the previously focused element rather than only after it. For hosts that know the captured element is about to be removed but cannot prove it yet, such as a delete that awaits a server round trip. */
|
|
26
|
+
preferRestoreFallback?: boolean;
|
|
21
27
|
/** Additional class applied to the focus-trap wrapper element. */
|
|
22
28
|
class?: string;
|
|
23
29
|
}
|
|
@@ -19,5 +19,42 @@ export type FocusTrapOptions = {
|
|
|
19
19
|
* `restoreFocus: false`.
|
|
20
20
|
*/
|
|
21
21
|
manageInitialFocus?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Where focus goes when the element captured at activation cannot take it
|
|
24
|
+
* back — most often because the control that opened the overlay was removed
|
|
25
|
+
* from the DOM while the overlay was open. Deleting the item whose popover
|
|
26
|
+
* you are standing in is the canonical case: the popover closes, its opener
|
|
27
|
+
* no longer exists, and without this focus lands on `<body>`, which reads as
|
|
28
|
+
* "nowhere" to a screen reader and restarts a keyboard user at the top of the
|
|
29
|
+
* document.
|
|
30
|
+
*
|
|
31
|
+
* Resolved against the DOCUMENT, unlike {@link initialFocus} and
|
|
32
|
+
* {@link fallbackFocus}, which are scoped to the trap root. That difference is
|
|
33
|
+
* deliberate and not an inconsistency: a restore target lives outside the trap
|
|
34
|
+
* by definition, and by the time restoration runs on unmount the trap's own
|
|
35
|
+
* node is usually already detached, so a root-scoped lookup would find
|
|
36
|
+
* nothing.
|
|
37
|
+
*
|
|
38
|
+
* Consulted only when restoring to the captured element fails, so supplying it
|
|
39
|
+
* can never override a restore that would have worked. Ignored entirely when
|
|
40
|
+
* `restoreFocus` is `false`.
|
|
41
|
+
*/
|
|
42
|
+
restoreFallback?: FocusTargetInput;
|
|
43
|
+
/**
|
|
44
|
+
* Go to {@link restoreFallback} FIRST on the next deactivation, rather than
|
|
45
|
+
* only when the captured element fails.
|
|
46
|
+
*
|
|
47
|
+
* For hosts that know the captured element is on its way out but cannot prove
|
|
48
|
+
* it yet. A popover whose delete action is server-backed is the case: the
|
|
49
|
+
* popover closes as soon as the request is made, while the list item that
|
|
50
|
+
* opened it is still on screen waiting for the response. Restoration would
|
|
51
|
+
* find that item perfectly focusable, hand focus back to it, and then watch it
|
|
52
|
+
* unmount a moment later — landing on `<body>` after all, with the fallback
|
|
53
|
+
* never consulted.
|
|
54
|
+
*
|
|
55
|
+
* Still falls through to the captured element if the fallback cannot take
|
|
56
|
+
* focus, so this changes the order rather than discarding a candidate.
|
|
57
|
+
*/
|
|
58
|
+
preferRestoreFallback?: boolean | (() => boolean);
|
|
22
59
|
};
|
|
23
60
|
export declare function createFocusTrap(options?: FocusTrapOptions): Attachment<HTMLElement>;
|
|
@@ -439,6 +439,23 @@ function getFallbackTarget(root, fallbackFocus) {
|
|
|
439
439
|
const resolved = resolveScopedTarget(root, fallbackFocus);
|
|
440
440
|
return resolved && isProgrammaticallyFocusable(resolved) ? resolved : null;
|
|
441
441
|
}
|
|
442
|
+
function getRestoreFallbackTarget(restoreFallback) {
|
|
443
|
+
const resolved = readOption(restoreFallback);
|
|
444
|
+
if (!resolved)
|
|
445
|
+
return null;
|
|
446
|
+
if (typeof resolved === "string") {
|
|
447
|
+
if (typeof document === "undefined")
|
|
448
|
+
return null;
|
|
449
|
+
let match;
|
|
450
|
+
try {
|
|
451
|
+
match = document.querySelector(resolved);
|
|
452
|
+
} catch {
|
|
453
|
+
return null;
|
|
454
|
+
}
|
|
455
|
+
return match && isProgrammaticallyFocusable(match) ? match : null;
|
|
456
|
+
}
|
|
457
|
+
return resolved instanceof HTMLElement && isProgrammaticallyFocusable(resolved) ? resolved : null;
|
|
458
|
+
}
|
|
442
459
|
function tryFocus(element) {
|
|
443
460
|
element.focus();
|
|
444
461
|
return document.activeElement === element;
|
|
@@ -475,6 +492,8 @@ function createFocusTrap(options = {}) {
|
|
|
475
492
|
const restoreFocus = options.restoreFocus ?? true;
|
|
476
493
|
const initialFocus = options.initialFocus ?? null;
|
|
477
494
|
const fallbackFocus = options.fallbackFocus ?? null;
|
|
495
|
+
const restoreFallback = options.restoreFallback ?? null;
|
|
496
|
+
const preferRestoreFallback = options.preferRestoreFallback ?? false;
|
|
478
497
|
const manageInitialFocus = options.manageInitialFocus ?? true;
|
|
479
498
|
let activated = false;
|
|
480
499
|
let activationGeneration = 0;
|
|
@@ -519,7 +538,11 @@ function createFocusTrap(options = {}) {
|
|
|
519
538
|
restoreRootFocusability = noop;
|
|
520
539
|
removeTrap(trapId);
|
|
521
540
|
if (restoreFocus) {
|
|
522
|
-
|
|
541
|
+
const candidates = readOption(preferRestoreFallback ?? false) ? [getRestoreFallbackTarget(restoreFallback), capturedFocus] : [capturedFocus, getRestoreFallbackTarget(restoreFallback)];
|
|
542
|
+
for (const candidate of candidates) {
|
|
543
|
+
if (restoreFocusTo(candidate) && document.activeElement === candidate)
|
|
544
|
+
break;
|
|
545
|
+
}
|
|
523
546
|
}
|
|
524
547
|
capturedFocus = null;
|
|
525
548
|
}
|
|
@@ -572,13 +595,15 @@ var rest_excludes = new Set([
|
|
|
572
595
|
"restoreFocus",
|
|
573
596
|
"initialFocus",
|
|
574
597
|
"fallbackFocus",
|
|
598
|
+
"restoreFallback",
|
|
599
|
+
"preferRestoreFallback",
|
|
575
600
|
"class",
|
|
576
601
|
"children"
|
|
577
602
|
]);
|
|
578
603
|
var root = $2.from_html(`<div><!></div>`);
|
|
579
604
|
function Focus_trap($$anchor, $$props) {
|
|
580
605
|
$2.push($$props, true);
|
|
581
|
-
let active = $2.prop($$props, "active", 3, true), restoreFocus = $2.prop($$props, "restoreFocus", 3, true), initialFocus = $2.prop($$props, "initialFocus", 3, null), fallbackFocus = $2.prop($$props, "fallbackFocus", 3, null), rest = $2.rest_props($$props, rest_excludes);
|
|
606
|
+
let active = $2.prop($$props, "active", 3, true), restoreFocus = $2.prop($$props, "restoreFocus", 3, true), initialFocus = $2.prop($$props, "initialFocus", 3, null), fallbackFocus = $2.prop($$props, "fallbackFocus", 3, null), restoreFallback = $2.prop($$props, "restoreFallback", 3, null), preferRestoreFallback = $2.prop($$props, "preferRestoreFallback", 3, false), rest = $2.rest_props($$props, rest_excludes);
|
|
582
607
|
var div = root();
|
|
583
608
|
$2.attribute_effect(div, ($0) => ({ class: $0, ...rest }), [() => classNames($$props.class)]);
|
|
584
609
|
var node = $2.child(div);
|
|
@@ -588,7 +613,9 @@ function Focus_trap($$anchor, $$props) {
|
|
|
588
613
|
active: () => active(),
|
|
589
614
|
restoreFocus: restoreFocus(),
|
|
590
615
|
initialFocus: () => initialFocus(),
|
|
591
|
-
fallbackFocus: () => fallbackFocus()
|
|
616
|
+
fallbackFocus: () => fallbackFocus(),
|
|
617
|
+
restoreFallback: () => restoreFallback(),
|
|
618
|
+
preferRestoreFallback: () => preferRestoreFallback()
|
|
592
619
|
}));
|
|
593
620
|
$2.append($$anchor, div);
|
|
594
621
|
$2.pop();
|
|
@@ -853,4 +880,4 @@ export {
|
|
|
853
880
|
Focus_trap as FocusTrap
|
|
854
881
|
};
|
|
855
882
|
|
|
856
|
-
//# debugId=
|
|
883
|
+
//# debugId=716097E866FBB7BF64756E2164756E21
|
|
@@ -439,6 +439,23 @@ function getFallbackTarget(root, fallbackFocus) {
|
|
|
439
439
|
const resolved = resolveScopedTarget(root, fallbackFocus);
|
|
440
440
|
return resolved && isProgrammaticallyFocusable(resolved) ? resolved : null;
|
|
441
441
|
}
|
|
442
|
+
function getRestoreFallbackTarget(restoreFallback) {
|
|
443
|
+
const resolved = readOption(restoreFallback);
|
|
444
|
+
if (!resolved)
|
|
445
|
+
return null;
|
|
446
|
+
if (typeof resolved === "string") {
|
|
447
|
+
if (typeof document === "undefined")
|
|
448
|
+
return null;
|
|
449
|
+
let match;
|
|
450
|
+
try {
|
|
451
|
+
match = document.querySelector(resolved);
|
|
452
|
+
} catch {
|
|
453
|
+
return null;
|
|
454
|
+
}
|
|
455
|
+
return match && isProgrammaticallyFocusable(match) ? match : null;
|
|
456
|
+
}
|
|
457
|
+
return resolved instanceof HTMLElement && isProgrammaticallyFocusable(resolved) ? resolved : null;
|
|
458
|
+
}
|
|
442
459
|
function tryFocus(element) {
|
|
443
460
|
element.focus();
|
|
444
461
|
return document.activeElement === element;
|
|
@@ -475,6 +492,8 @@ function createFocusTrap(options = {}) {
|
|
|
475
492
|
const restoreFocus = options.restoreFocus ?? true;
|
|
476
493
|
const initialFocus = options.initialFocus ?? null;
|
|
477
494
|
const fallbackFocus = options.fallbackFocus ?? null;
|
|
495
|
+
const restoreFallback = options.restoreFallback ?? null;
|
|
496
|
+
const preferRestoreFallback = options.preferRestoreFallback ?? false;
|
|
478
497
|
const manageInitialFocus = options.manageInitialFocus ?? true;
|
|
479
498
|
let activated = false;
|
|
480
499
|
let activationGeneration = 0;
|
|
@@ -519,7 +538,11 @@ function createFocusTrap(options = {}) {
|
|
|
519
538
|
restoreRootFocusability = noop;
|
|
520
539
|
removeTrap(trapId);
|
|
521
540
|
if (restoreFocus) {
|
|
522
|
-
|
|
541
|
+
const candidates = readOption(preferRestoreFallback ?? false) ? [getRestoreFallbackTarget(restoreFallback), capturedFocus] : [capturedFocus, getRestoreFallbackTarget(restoreFallback)];
|
|
542
|
+
for (const candidate of candidates) {
|
|
543
|
+
if (restoreFocusTo(candidate) && document.activeElement === candidate)
|
|
544
|
+
break;
|
|
545
|
+
}
|
|
523
546
|
}
|
|
524
547
|
capturedFocus = null;
|
|
525
548
|
}
|
|
@@ -572,13 +595,15 @@ var rest_excludes = new Set([
|
|
|
572
595
|
"restoreFocus",
|
|
573
596
|
"initialFocus",
|
|
574
597
|
"fallbackFocus",
|
|
598
|
+
"restoreFallback",
|
|
599
|
+
"preferRestoreFallback",
|
|
575
600
|
"class",
|
|
576
601
|
"children"
|
|
577
602
|
]);
|
|
578
603
|
var root = $2.from_html(`<div><!></div>`);
|
|
579
604
|
function Focus_trap($$anchor, $$props) {
|
|
580
605
|
$2.push($$props, true);
|
|
581
|
-
let active = $2.prop($$props, "active", 3, true), restoreFocus = $2.prop($$props, "restoreFocus", 3, true), initialFocus = $2.prop($$props, "initialFocus", 3, null), fallbackFocus = $2.prop($$props, "fallbackFocus", 3, null), rest = $2.rest_props($$props, rest_excludes);
|
|
606
|
+
let active = $2.prop($$props, "active", 3, true), restoreFocus = $2.prop($$props, "restoreFocus", 3, true), initialFocus = $2.prop($$props, "initialFocus", 3, null), fallbackFocus = $2.prop($$props, "fallbackFocus", 3, null), restoreFallback = $2.prop($$props, "restoreFallback", 3, null), preferRestoreFallback = $2.prop($$props, "preferRestoreFallback", 3, false), rest = $2.rest_props($$props, rest_excludes);
|
|
582
607
|
var div = root();
|
|
583
608
|
$2.attribute_effect(div, ($0) => ({ class: $0, ...rest }), [() => classNames($$props.class)]);
|
|
584
609
|
var node = $2.child(div);
|
|
@@ -588,7 +613,9 @@ function Focus_trap($$anchor, $$props) {
|
|
|
588
613
|
active: () => active(),
|
|
589
614
|
restoreFocus: restoreFocus(),
|
|
590
615
|
initialFocus: () => initialFocus(),
|
|
591
|
-
fallbackFocus: () => fallbackFocus()
|
|
616
|
+
fallbackFocus: () => fallbackFocus(),
|
|
617
|
+
restoreFallback: () => restoreFallback(),
|
|
618
|
+
preferRestoreFallback: () => preferRestoreFallback()
|
|
592
619
|
}));
|
|
593
620
|
$2.append($$anchor, div);
|
|
594
621
|
$2.pop();
|
|
@@ -1308,4 +1335,4 @@ export {
|
|
|
1308
1335
|
Modal
|
|
1309
1336
|
};
|
|
1310
1337
|
|
|
1311
|
-
//# debugId=
|
|
1338
|
+
//# debugId=C298FBD9899945CA64756E2164756E21
|
|
@@ -439,6 +439,23 @@ function getFallbackTarget(root, fallbackFocus) {
|
|
|
439
439
|
const resolved = resolveScopedTarget(root, fallbackFocus);
|
|
440
440
|
return resolved && isProgrammaticallyFocusable(resolved) ? resolved : null;
|
|
441
441
|
}
|
|
442
|
+
function getRestoreFallbackTarget(restoreFallback) {
|
|
443
|
+
const resolved = readOption(restoreFallback);
|
|
444
|
+
if (!resolved)
|
|
445
|
+
return null;
|
|
446
|
+
if (typeof resolved === "string") {
|
|
447
|
+
if (typeof document === "undefined")
|
|
448
|
+
return null;
|
|
449
|
+
let match;
|
|
450
|
+
try {
|
|
451
|
+
match = document.querySelector(resolved);
|
|
452
|
+
} catch {
|
|
453
|
+
return null;
|
|
454
|
+
}
|
|
455
|
+
return match && isProgrammaticallyFocusable(match) ? match : null;
|
|
456
|
+
}
|
|
457
|
+
return resolved instanceof HTMLElement && isProgrammaticallyFocusable(resolved) ? resolved : null;
|
|
458
|
+
}
|
|
442
459
|
function tryFocus(element) {
|
|
443
460
|
element.focus();
|
|
444
461
|
return document.activeElement === element;
|
|
@@ -475,6 +492,8 @@ function createFocusTrap(options = {}) {
|
|
|
475
492
|
const restoreFocus = options.restoreFocus ?? true;
|
|
476
493
|
const initialFocus = options.initialFocus ?? null;
|
|
477
494
|
const fallbackFocus = options.fallbackFocus ?? null;
|
|
495
|
+
const restoreFallback = options.restoreFallback ?? null;
|
|
496
|
+
const preferRestoreFallback = options.preferRestoreFallback ?? false;
|
|
478
497
|
const manageInitialFocus = options.manageInitialFocus ?? true;
|
|
479
498
|
let activated = false;
|
|
480
499
|
let activationGeneration = 0;
|
|
@@ -519,7 +538,11 @@ function createFocusTrap(options = {}) {
|
|
|
519
538
|
restoreRootFocusability = noop;
|
|
520
539
|
removeTrap(trapId);
|
|
521
540
|
if (restoreFocus) {
|
|
522
|
-
|
|
541
|
+
const candidates = readOption(preferRestoreFallback ?? false) ? [getRestoreFallbackTarget(restoreFallback), capturedFocus] : [capturedFocus, getRestoreFallbackTarget(restoreFallback)];
|
|
542
|
+
for (const candidate of candidates) {
|
|
543
|
+
if (restoreFocusTo(candidate) && document.activeElement === candidate)
|
|
544
|
+
break;
|
|
545
|
+
}
|
|
523
546
|
}
|
|
524
547
|
capturedFocus = null;
|
|
525
548
|
}
|
|
@@ -572,13 +595,15 @@ var rest_excludes = new Set([
|
|
|
572
595
|
"restoreFocus",
|
|
573
596
|
"initialFocus",
|
|
574
597
|
"fallbackFocus",
|
|
598
|
+
"restoreFallback",
|
|
599
|
+
"preferRestoreFallback",
|
|
575
600
|
"class",
|
|
576
601
|
"children"
|
|
577
602
|
]);
|
|
578
603
|
var root = $2.from_html(`<div><!></div>`);
|
|
579
604
|
function Focus_trap($$anchor, $$props) {
|
|
580
605
|
$2.push($$props, true);
|
|
581
|
-
let active = $2.prop($$props, "active", 3, true), restoreFocus = $2.prop($$props, "restoreFocus", 3, true), initialFocus = $2.prop($$props, "initialFocus", 3, null), fallbackFocus = $2.prop($$props, "fallbackFocus", 3, null), rest = $2.rest_props($$props, rest_excludes);
|
|
606
|
+
let active = $2.prop($$props, "active", 3, true), restoreFocus = $2.prop($$props, "restoreFocus", 3, true), initialFocus = $2.prop($$props, "initialFocus", 3, null), fallbackFocus = $2.prop($$props, "fallbackFocus", 3, null), restoreFallback = $2.prop($$props, "restoreFallback", 3, null), preferRestoreFallback = $2.prop($$props, "preferRestoreFallback", 3, false), rest = $2.rest_props($$props, rest_excludes);
|
|
582
607
|
var div = root();
|
|
583
608
|
$2.attribute_effect(div, ($0) => ({ class: $0, ...rest }), [() => classNames($$props.class)]);
|
|
584
609
|
var node = $2.child(div);
|
|
@@ -588,7 +613,9 @@ function Focus_trap($$anchor, $$props) {
|
|
|
588
613
|
active: () => active(),
|
|
589
614
|
restoreFocus: restoreFocus(),
|
|
590
615
|
initialFocus: () => initialFocus(),
|
|
591
|
-
fallbackFocus: () => fallbackFocus()
|
|
616
|
+
fallbackFocus: () => fallbackFocus(),
|
|
617
|
+
restoreFallback: () => restoreFallback(),
|
|
618
|
+
preferRestoreFallback: () => preferRestoreFallback()
|
|
592
619
|
}));
|
|
593
620
|
$2.append($$anchor, div);
|
|
594
621
|
$2.pop();
|
|
@@ -1602,4 +1629,4 @@ export {
|
|
|
1602
1629
|
SIDEBAR_MOBILE_BREAKPOINT
|
|
1603
1630
|
};
|
|
1604
1631
|
|
|
1605
|
-
//# debugId=
|
|
1632
|
+
//# debugId=D68604E5B21F442D64756E2164756E21
|
package/dist/index.js
CHANGED
|
@@ -7289,6 +7289,23 @@ function getFallbackTarget(root8, fallbackFocus) {
|
|
|
7289
7289
|
const resolved = resolveScopedTarget(root8, fallbackFocus);
|
|
7290
7290
|
return resolved && isProgrammaticallyFocusable(resolved) ? resolved : null;
|
|
7291
7291
|
}
|
|
7292
|
+
function getRestoreFallbackTarget(restoreFallback) {
|
|
7293
|
+
const resolved = readOption(restoreFallback);
|
|
7294
|
+
if (!resolved)
|
|
7295
|
+
return null;
|
|
7296
|
+
if (typeof resolved === "string") {
|
|
7297
|
+
if (typeof document === "undefined")
|
|
7298
|
+
return null;
|
|
7299
|
+
let match;
|
|
7300
|
+
try {
|
|
7301
|
+
match = document.querySelector(resolved);
|
|
7302
|
+
} catch {
|
|
7303
|
+
return null;
|
|
7304
|
+
}
|
|
7305
|
+
return match && isProgrammaticallyFocusable(match) ? match : null;
|
|
7306
|
+
}
|
|
7307
|
+
return resolved instanceof HTMLElement && isProgrammaticallyFocusable(resolved) ? resolved : null;
|
|
7308
|
+
}
|
|
7292
7309
|
function tryFocus(element2) {
|
|
7293
7310
|
element2.focus();
|
|
7294
7311
|
return document.activeElement === element2;
|
|
@@ -7325,6 +7342,8 @@ function createFocusTrap(options = {}) {
|
|
|
7325
7342
|
const restoreFocus = options.restoreFocus ?? true;
|
|
7326
7343
|
const initialFocus = options.initialFocus ?? null;
|
|
7327
7344
|
const fallbackFocus = options.fallbackFocus ?? null;
|
|
7345
|
+
const restoreFallback = options.restoreFallback ?? null;
|
|
7346
|
+
const preferRestoreFallback = options.preferRestoreFallback ?? false;
|
|
7328
7347
|
const manageInitialFocus = options.manageInitialFocus ?? true;
|
|
7329
7348
|
let activated = false;
|
|
7330
7349
|
let activationGeneration = 0;
|
|
@@ -7369,7 +7388,11 @@ function createFocusTrap(options = {}) {
|
|
|
7369
7388
|
restoreRootFocusability = noop3;
|
|
7370
7389
|
removeTrap(trapId);
|
|
7371
7390
|
if (restoreFocus) {
|
|
7372
|
-
|
|
7391
|
+
const candidates = readOption(preferRestoreFallback ?? false) ? [getRestoreFallbackTarget(restoreFallback), capturedFocus] : [capturedFocus, getRestoreFallbackTarget(restoreFallback)];
|
|
7392
|
+
for (const candidate of candidates) {
|
|
7393
|
+
if (restoreFocusTo(candidate) && document.activeElement === candidate)
|
|
7394
|
+
break;
|
|
7395
|
+
}
|
|
7373
7396
|
}
|
|
7374
7397
|
capturedFocus = null;
|
|
7375
7398
|
}
|
|
@@ -7422,13 +7445,15 @@ var rest_excludes5 = new Set([
|
|
|
7422
7445
|
"restoreFocus",
|
|
7423
7446
|
"initialFocus",
|
|
7424
7447
|
"fallbackFocus",
|
|
7448
|
+
"restoreFallback",
|
|
7449
|
+
"preferRestoreFallback",
|
|
7425
7450
|
"class",
|
|
7426
7451
|
"children"
|
|
7427
7452
|
]);
|
|
7428
7453
|
var root8 = $73.from_html(`<div><!></div>`);
|
|
7429
7454
|
function Focus_trap($$anchor, $$props) {
|
|
7430
7455
|
$73.push($$props, true);
|
|
7431
|
-
let active = $73.prop($$props, "active", 3, true), restoreFocus = $73.prop($$props, "restoreFocus", 3, true), initialFocus = $73.prop($$props, "initialFocus", 3, null), fallbackFocus = $73.prop($$props, "fallbackFocus", 3, null), rest = $73.rest_props($$props, rest_excludes5);
|
|
7456
|
+
let active = $73.prop($$props, "active", 3, true), restoreFocus = $73.prop($$props, "restoreFocus", 3, true), initialFocus = $73.prop($$props, "initialFocus", 3, null), fallbackFocus = $73.prop($$props, "fallbackFocus", 3, null), restoreFallback = $73.prop($$props, "restoreFallback", 3, null), preferRestoreFallback = $73.prop($$props, "preferRestoreFallback", 3, false), rest = $73.rest_props($$props, rest_excludes5);
|
|
7432
7457
|
var div = root8();
|
|
7433
7458
|
$73.attribute_effect(div, ($0) => ({ class: $0, ...rest }), [() => classNames($$props.class)]);
|
|
7434
7459
|
var node = $73.child(div);
|
|
@@ -7438,7 +7463,9 @@ function Focus_trap($$anchor, $$props) {
|
|
|
7438
7463
|
active: () => active(),
|
|
7439
7464
|
restoreFocus: restoreFocus(),
|
|
7440
7465
|
initialFocus: () => initialFocus(),
|
|
7441
|
-
fallbackFocus: () => fallbackFocus()
|
|
7466
|
+
fallbackFocus: () => fallbackFocus(),
|
|
7467
|
+
restoreFallback: () => restoreFallback(),
|
|
7468
|
+
preferRestoreFallback: () => preferRestoreFallback()
|
|
7442
7469
|
}));
|
|
7443
7470
|
$73.append($$anchor, div);
|
|
7444
7471
|
$73.pop();
|
|
@@ -72877,4 +72904,4 @@ export {
|
|
|
72877
72904
|
AccessGateExport as AccessGate
|
|
72878
72905
|
};
|
|
72879
72906
|
|
|
72880
|
-
//# debugId=
|
|
72907
|
+
//# debugId=80C8E1090D7D97D764756E2164756E21
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
import"../../index.server-tkt7wm9w.js";
|
|
6
6
|
import"../../index.server-x0sbmhn7.js";
|
|
7
7
|
import"../../index.server-78d33trm.js";
|
|
8
|
-
import"../../index.server-
|
|
8
|
+
import"../../index.server-es919z55.js";
|
|
9
9
|
import"../../index.server-gdtg1xg7.js";
|
|
10
10
|
import"../../index.server-fdpe3vky.js";
|
|
11
11
|
import"../../index.server-th1tsad4.js";
|
|
@@ -10,7 +10,7 @@ import"../../index.server-493m9fm5.js";
|
|
|
10
10
|
import"../../index.server-tkt7wm9w.js";
|
|
11
11
|
import"../../index.server-x0sbmhn7.js";
|
|
12
12
|
import"../../index.server-78d33trm.js";
|
|
13
|
-
import"../../index.server-
|
|
13
|
+
import"../../index.server-es919z55.js";
|
|
14
14
|
import"../../index.server-gdtg1xg7.js";
|
|
15
15
|
import"../../index.server-abm21gz1.js";
|
|
16
16
|
import"../../index.server-fdpe3vky.js";
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
} from "../../index.server-9m7bqtev.js";
|
|
7
7
|
import"../../index.server-x0sbmhn7.js";
|
|
8
8
|
import"../../index.server-78d33trm.js";
|
|
9
|
-
import"../../index.server-
|
|
9
|
+
import"../../index.server-es919z55.js";
|
|
10
10
|
import"../../index.server-gdtg1xg7.js";
|
|
11
11
|
import"../../index.server-th1tsad4.js";
|
|
12
12
|
import"../../index.server-6pdmym90.js";
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
} from "../../index.server-tkt7wm9w.js";
|
|
7
7
|
import"../../index.server-x0sbmhn7.js";
|
|
8
8
|
import"../../index.server-78d33trm.js";
|
|
9
|
-
import"../../index.server-
|
|
9
|
+
import"../../index.server-es919z55.js";
|
|
10
10
|
import"../../index.server-gdtg1xg7.js";
|
|
11
11
|
import"../../index.server-th1tsad4.js";
|
|
12
12
|
import"../../index.server-6pdmym90.js";
|
|
@@ -8,7 +8,7 @@ import"../../index.server-9m7bqtev.js";
|
|
|
8
8
|
import"../../index.server-493m9fm5.js";
|
|
9
9
|
import"../../index.server-x0sbmhn7.js";
|
|
10
10
|
import"../../index.server-78d33trm.js";
|
|
11
|
-
import"../../index.server-
|
|
11
|
+
import"../../index.server-es919z55.js";
|
|
12
12
|
import"../../index.server-gdtg1xg7.js";
|
|
13
13
|
import"../../index.server-th1tsad4.js";
|
|
14
14
|
import"../../index.server-6pdmym90.js";
|
package/dist/server/index.js
CHANGED
|
@@ -677,7 +677,7 @@ import"./index.server-78d33trm.js";
|
|
|
677
677
|
import {
|
|
678
678
|
createFocusTrap,
|
|
679
679
|
focus_trap_default
|
|
680
|
-
} from "./index.server-
|
|
680
|
+
} from "./index.server-es919z55.js";
|
|
681
681
|
import"./index.server-gdtg1xg7.js";
|
|
682
682
|
import {
|
|
683
683
|
approval_card_default
|
|
@@ -81,6 +81,23 @@ function getFallbackTarget(root, fallbackFocus) {
|
|
|
81
81
|
const resolved = resolveScopedTarget(root, fallbackFocus);
|
|
82
82
|
return resolved && isProgrammaticallyFocusable(resolved) ? resolved : null;
|
|
83
83
|
}
|
|
84
|
+
function getRestoreFallbackTarget(restoreFallback) {
|
|
85
|
+
const resolved = readOption(restoreFallback);
|
|
86
|
+
if (!resolved)
|
|
87
|
+
return null;
|
|
88
|
+
if (typeof resolved === "string") {
|
|
89
|
+
if (typeof document === "undefined")
|
|
90
|
+
return null;
|
|
91
|
+
let match;
|
|
92
|
+
try {
|
|
93
|
+
match = document.querySelector(resolved);
|
|
94
|
+
} catch {
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
return match && isProgrammaticallyFocusable(match) ? match : null;
|
|
98
|
+
}
|
|
99
|
+
return resolved instanceof HTMLElement && isProgrammaticallyFocusable(resolved) ? resolved : null;
|
|
100
|
+
}
|
|
84
101
|
function tryFocus(element) {
|
|
85
102
|
element.focus();
|
|
86
103
|
return document.activeElement === element;
|
|
@@ -117,6 +134,8 @@ function createFocusTrap(options = {}) {
|
|
|
117
134
|
const restoreFocus = options.restoreFocus ?? true;
|
|
118
135
|
const initialFocus = options.initialFocus ?? null;
|
|
119
136
|
const fallbackFocus = options.fallbackFocus ?? null;
|
|
137
|
+
const restoreFallback = options.restoreFallback ?? null;
|
|
138
|
+
const preferRestoreFallback = options.preferRestoreFallback ?? false;
|
|
120
139
|
const manageInitialFocus = options.manageInitialFocus ?? true;
|
|
121
140
|
let activated = false;
|
|
122
141
|
let activationGeneration = 0;
|
|
@@ -161,7 +180,11 @@ function createFocusTrap(options = {}) {
|
|
|
161
180
|
restoreRootFocusability = noop;
|
|
162
181
|
removeTrap(trapId);
|
|
163
182
|
if (restoreFocus) {
|
|
164
|
-
|
|
183
|
+
const candidates = readOption(preferRestoreFallback ?? false) ? [getRestoreFallbackTarget(restoreFallback), capturedFocus] : [capturedFocus, getRestoreFallbackTarget(restoreFallback)];
|
|
184
|
+
for (const candidate of candidates) {
|
|
185
|
+
if (restoreFocusTo(candidate) && document.activeElement === candidate)
|
|
186
|
+
break;
|
|
187
|
+
}
|
|
165
188
|
}
|
|
166
189
|
capturedFocus = null;
|
|
167
190
|
}
|
|
@@ -205,6 +228,8 @@ function Focus_trap($$renderer, $$props) {
|
|
|
205
228
|
restoreFocus = true,
|
|
206
229
|
initialFocus = null,
|
|
207
230
|
fallbackFocus = null,
|
|
231
|
+
restoreFallback = null,
|
|
232
|
+
preferRestoreFallback = false,
|
|
208
233
|
class: className,
|
|
209
234
|
children,
|
|
210
235
|
$$slots,
|
|
@@ -221,4 +246,4 @@ function Focus_trap($$renderer, $$props) {
|
|
|
221
246
|
var focus_trap_default = Focus_trap;
|
|
222
247
|
export { createFocusTrap, Focus_trap, focus_trap_default };
|
|
223
248
|
|
|
224
|
-
//# debugId=
|
|
249
|
+
//# debugId=2A658975792E379464756E2164756E21
|
package/package.json
CHANGED
|
@@ -32,6 +32,21 @@
|
|
|
32
32
|
],
|
|
33
33
|
"description": "CSS selector for the element that receives focus when `initialFocus` is unset or unresolvable. Defaults to the trap container itself."
|
|
34
34
|
},
|
|
35
|
+
"restoreFallback": {
|
|
36
|
+
"anyOf": [
|
|
37
|
+
{
|
|
38
|
+
"type": "string"
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"type": "null"
|
|
42
|
+
}
|
|
43
|
+
],
|
|
44
|
+
"description": "CSS selector, resolved against the document, for the element that receives focus when the previously focused element cannot take it back — typically because it was removed from the DOM while the trap was open. Without it, focus falls to `<body>`."
|
|
45
|
+
},
|
|
46
|
+
"preferRestoreFallback": {
|
|
47
|
+
"type": "boolean",
|
|
48
|
+
"description": "When true, `restoreFallback` is tried before the previously focused element rather than only after it. For hosts that know the captured element is about to be removed but cannot prove it yet, such as a delete that awaits a server round trip."
|
|
49
|
+
},
|
|
35
50
|
"class": {
|
|
36
51
|
"type": "string",
|
|
37
52
|
"description": "Additional class applied to the focus-trap wrapper element."
|
|
@@ -38,6 +38,23 @@ const schema = {
|
|
|
38
38
|
description:
|
|
39
39
|
'CSS selector for the element that receives focus when `initialFocus` is unset or unresolvable. Defaults to the trap container itself.',
|
|
40
40
|
},
|
|
41
|
+
restoreFallback: {
|
|
42
|
+
anyOf: [
|
|
43
|
+
{
|
|
44
|
+
type: 'string',
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
type: 'null',
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
description:
|
|
51
|
+
'CSS selector, resolved against the document, for the element that receives focus when the previously focused element cannot take it back — typically because it was removed from the DOM while the trap was open. Without it, focus falls to `<body>`.',
|
|
52
|
+
},
|
|
53
|
+
preferRestoreFallback: {
|
|
54
|
+
type: 'boolean',
|
|
55
|
+
description:
|
|
56
|
+
'When true, `restoreFallback` is tried before the previously focused element rather than only after it. For hosts that know the captured element is about to be removed but cannot prove it yet, such as a delete that awaits a server round trip.',
|
|
57
|
+
},
|
|
41
58
|
class: {
|
|
42
59
|
type: 'string',
|
|
43
60
|
description: 'Additional class applied to the focus-trap wrapper element.',
|
|
@@ -5,7 +5,7 @@ export {};
|
|
|
5
5
|
<script lang="ts">
|
|
6
6
|
import { classNames } from '../../utilities/class-names.ts';
|
|
7
7
|
import { createFocusTrap } from './focus-trap.utilities.svelte.ts';
|
|
8
|
-
let { active = true, restoreFocus = true, initialFocus = null, fallbackFocus = null, class: className, children, ...rest } = $props();
|
|
8
|
+
let { active = true, restoreFocus = true, initialFocus = null, fallbackFocus = null, restoreFallback = null, preferRestoreFallback = false, class: className, children, ...rest } = $props();
|
|
9
9
|
</script>
|
|
10
10
|
|
|
11
11
|
<div
|
|
@@ -14,6 +14,8 @@ let { active = true, restoreFocus = true, initialFocus = null, fallbackFocus = n
|
|
|
14
14
|
restoreFocus,
|
|
15
15
|
initialFocus: () => initialFocus,
|
|
16
16
|
fallbackFocus: () => fallbackFocus,
|
|
17
|
+
restoreFallback: () => restoreFallback,
|
|
18
|
+
preferRestoreFallback: () => preferRestoreFallback,
|
|
17
19
|
})}
|
|
18
20
|
class={classNames(className)}
|
|
19
21
|
{...rest}
|
|
@@ -9,6 +9,8 @@ export type FocusTrapProps = Omit<HTMLAttributes<HTMLDivElement>, 'children' | '
|
|
|
9
9
|
restoreFocus?: boolean;
|
|
10
10
|
initialFocus?: Exclude<FocusTargetInput, Function>;
|
|
11
11
|
fallbackFocus?: Exclude<FocusTargetInput, Function>;
|
|
12
|
+
restoreFallback?: Exclude<FocusTargetInput, Function>;
|
|
13
|
+
preferRestoreFallback?: boolean;
|
|
12
14
|
class?: string;
|
|
13
15
|
};
|
|
14
16
|
|
|
@@ -21,6 +23,10 @@ export interface FocusTrapSchemaProps {
|
|
|
21
23
|
initialFocus?: string | null;
|
|
22
24
|
/** CSS selector for the element that receives focus when `initialFocus` is unset or unresolvable. Defaults to the trap container itself. */
|
|
23
25
|
fallbackFocus?: string | null;
|
|
26
|
+
/** CSS selector, resolved against the document, for the element that receives focus when the previously focused element cannot take it back — typically because it was removed from the DOM while the trap was open. Without it, focus falls to `<body>`. */
|
|
27
|
+
restoreFallback?: string | null;
|
|
28
|
+
/** When true, `restoreFallback` is tried before the previously focused element rather than only after it. For hosts that know the captured element is about to be removed but cannot prove it yet, such as a delete that awaits a server round trip. */
|
|
29
|
+
preferRestoreFallback?: boolean;
|
|
24
30
|
/** Additional class applied to the focus-trap wrapper element. */
|
|
25
31
|
class?: string;
|
|
26
32
|
}
|
|
@@ -90,6 +90,32 @@ function getFallbackTarget(root, fallbackFocus) {
|
|
|
90
90
|
const resolved = resolveScopedTarget(root, fallbackFocus);
|
|
91
91
|
return resolved && isProgrammaticallyFocusable(resolved) ? resolved : null;
|
|
92
92
|
}
|
|
93
|
+
/**
|
|
94
|
+
* Resolve a focus target against the document rather than the trap root.
|
|
95
|
+
*
|
|
96
|
+
* Used only for {@link FocusTrapOptions.restoreFallback} — see that option for
|
|
97
|
+
* why restoration cannot use the root-scoped `resolveScopedTarget`.
|
|
98
|
+
*/
|
|
99
|
+
function getRestoreFallbackTarget(restoreFallback) {
|
|
100
|
+
const resolved = readOption(restoreFallback);
|
|
101
|
+
if (!resolved)
|
|
102
|
+
return null;
|
|
103
|
+
if (typeof resolved === 'string') {
|
|
104
|
+
if (typeof document === 'undefined')
|
|
105
|
+
return null;
|
|
106
|
+
let match;
|
|
107
|
+
try {
|
|
108
|
+
match = document.querySelector(resolved);
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
// An invalid selector is a caller mistake, not a reason to throw out of an
|
|
112
|
+
// unmount path and leave the trap stack inconsistent.
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
return match && isProgrammaticallyFocusable(match) ? match : null;
|
|
116
|
+
}
|
|
117
|
+
return resolved instanceof HTMLElement && isProgrammaticallyFocusable(resolved) ? resolved : null;
|
|
118
|
+
}
|
|
93
119
|
/**
|
|
94
120
|
* Calls `.focus()` and returns whether the element actually became `document.activeElement`.
|
|
95
121
|
* `isProgrammaticallyFocusable` cannot tell whether a plain `<div>` or `<h2>` (no `tabindex`,
|
|
@@ -133,6 +159,8 @@ export function createFocusTrap(options = {}) {
|
|
|
133
159
|
const restoreFocus = options.restoreFocus ?? true;
|
|
134
160
|
const initialFocus = options.initialFocus ?? null;
|
|
135
161
|
const fallbackFocus = options.fallbackFocus ?? null;
|
|
162
|
+
const restoreFallback = options.restoreFallback ?? null;
|
|
163
|
+
const preferRestoreFallback = options.preferRestoreFallback ?? false;
|
|
136
164
|
const manageInitialFocus = options.manageInitialFocus ?? true;
|
|
137
165
|
let activated = false;
|
|
138
166
|
// Bumped on every `activate()`. The deferred `focusTrapTarget` microtask snapshots this value
|
|
@@ -193,7 +221,19 @@ export function createFocusTrap(options = {}) {
|
|
|
193
221
|
restoreRootFocusability = noop;
|
|
194
222
|
removeTrap(trapId);
|
|
195
223
|
if (restoreFocus) {
|
|
196
|
-
|
|
224
|
+
// Both candidates, in preference order, taking the first that actually
|
|
225
|
+
// lands. `restoreFocusTo`'s own boolean is necessary but not sufficient:
|
|
226
|
+
// it reports success whenever `.focus()` did not throw, which is also
|
|
227
|
+
// true for a still-connected element that has since become `disabled` or
|
|
228
|
+
// `inert` and cannot take focus. Confirming `document.activeElement`
|
|
229
|
+
// is what makes "restored" mean restored.
|
|
230
|
+
const candidates = readOption(preferRestoreFallback ?? false)
|
|
231
|
+
? [getRestoreFallbackTarget(restoreFallback), capturedFocus]
|
|
232
|
+
: [capturedFocus, getRestoreFallbackTarget(restoreFallback)];
|
|
233
|
+
for (const candidate of candidates) {
|
|
234
|
+
if (restoreFocusTo(candidate) && document.activeElement === candidate)
|
|
235
|
+
break;
|
|
236
|
+
}
|
|
197
237
|
}
|
|
198
238
|
capturedFocus = null;
|
|
199
239
|
}
|