@box/blueprint-web 19.6.0 → 20.0.0
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/THIRD_PARTY_LICENSES +119 -0
- package/dist/lib-esm/accordion/accordion.js +6 -6
- package/dist/lib-esm/accordion/types.d.ts +1 -1
- package/dist/lib-esm/checkbox/checkbox-item.js +3 -3
- package/dist/lib-esm/checkbox/types.d.ts +1 -1
- package/dist/lib-esm/collapsible/collapsible-section.js +5 -5
- package/dist/lib-esm/collapsible/types.d.ts +1 -1
- package/dist/lib-esm/combobox-group/combobox-group-combobox.js +1 -1
- package/dist/lib-esm/date-picker/date-picker.js +8 -7
- package/dist/lib-esm/guided-tooltip/guided-tooltip.js +7 -7
- package/dist/lib-esm/guided-tooltip/types.d.ts +1 -1
- package/dist/lib-esm/modal/alert-modal.types.d.ts +1 -1
- package/dist/lib-esm/modal/modal-close.js +2 -2
- package/dist/lib-esm/modal/modal-content.d.ts +1 -1
- package/dist/lib-esm/modal/modal-content.js +4 -4
- package/dist/lib-esm/modal/modal-description.js +2 -2
- package/dist/lib-esm/modal/modal-title.js +2 -2
- package/dist/lib-esm/modal/modal-trigger.js +2 -2
- package/dist/lib-esm/modal/modal.d.ts +1 -1
- package/dist/lib-esm/modal/modal.js +1 -1
- package/dist/lib-esm/modal/types.d.ts +1 -1
- package/dist/lib-esm/navigation-menu/index.d.ts +4 -2
- package/dist/lib-esm/navigation-menu/navigation-menu-item.d.ts +1 -1
- package/dist/lib-esm/navigation-menu/navigation-menu-trigger.d.ts +3 -1
- package/dist/lib-esm/primitives/chips/chip.d.ts +1 -1
- package/dist/lib-esm/primitives/chips/chip.js +2 -2
- package/dist/lib-esm/primitives/chips/chips-group.js +2 -2
- package/dist/lib-esm/primitives/chips/filter-chip/filter-chip-button.d.ts +1 -1
- package/dist/lib-esm/primitives/chips/filter-chip/filter-chip.d.ts +1 -1
- package/dist/lib-esm/primitives/chips/filter-chip/filter-combo-chip.d.ts +2 -2
- package/dist/lib-esm/primitives/chips/filter-chip/filter-trigger-chip.d.ts +1 -1
- package/dist/lib-esm/primitives/chips/filter-chip/index.d.ts +5 -5
- package/dist/lib-esm/primitives/chips/types.d.ts +1 -1
- package/dist/lib-esm/primitives/context-menu/context-menu-item.d.ts +2 -2
- package/dist/lib-esm/primitives/context-menu/context-menu-item.js +2 -2
- package/dist/lib-esm/primitives/context-menu/context-menu-menu-content.d.ts +1 -1
- package/dist/lib-esm/primitives/context-menu/context-menu-menu-content.js +5 -5
- package/dist/lib-esm/primitives/context-menu/context-menu-menu-header.js +3 -10
- package/dist/lib-esm/primitives/context-menu/context-menu-menu-root.d.ts +1 -1
- package/dist/lib-esm/primitives/context-menu/context-menu-menu-root.js +1 -1
- package/dist/lib-esm/primitives/context-menu/context-menu-menu-trigger.d.ts +1 -1
- package/dist/lib-esm/primitives/context-menu/context-menu-menu-trigger.js +1 -1
- package/dist/lib-esm/primitives/context-menu/context-menu-sub-menu-content.d.ts +1 -1
- package/dist/lib-esm/primitives/context-menu/context-menu-sub-menu-content.js +5 -5
- package/dist/lib-esm/primitives/context-menu/context-menu-sub-menu-root.d.ts +1 -1
- package/dist/lib-esm/primitives/context-menu/context-menu-sub-menu-root.js +1 -1
- package/dist/lib-esm/primitives/context-menu/context-menu-sub-menu-trigger.d.ts +2 -2
- package/dist/lib-esm/primitives/context-menu/context-menu-sub-menu-trigger.js +1 -1
- package/dist/lib-esm/primitives/context-menu/index.d.ts +3 -3
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-checkbox-item.d.ts +2 -2
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-checkbox-item.js +3 -3
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-content.d.ts +1 -1
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-content.js +5 -5
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-group.d.ts +4 -2
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-group.js +2 -2
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-item.d.ts +2 -2
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-item.js +2 -2
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-radio-group.d.ts +2 -2
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-radio-group.js +2 -2
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-radio-select-item.d.ts +2 -2
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-radio-select-item.js +3 -3
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-root.d.ts +1 -1
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-root.js +2 -2
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-sub-header.d.ts +4 -2
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-sub-header.js +2 -2
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-sub-menu-content.d.ts +1 -1
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-sub-menu-content.js +5 -5
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-sub-menu-root.d.ts +1 -1
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-sub-menu-root.js +2 -2
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-sub-menu-trigger.d.ts +2 -2
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-sub-menu-trigger.js +2 -2
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-trigger.d.ts +4 -2
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-trigger.js +2 -2
- package/dist/lib-esm/primitives/dropdown-menu/index.d.ts +14 -8
- package/dist/lib-esm/primitives/notification/hooks/use-notification-layer.d.ts +15 -0
- package/dist/lib-esm/primitives/notification/hooks/use-notification-layer.js +49 -0
- package/dist/lib-esm/primitives/notification/notification-provider.js +2 -2
- package/dist/lib-esm/primitives/notification/notification.viewport-animated.js +12 -8
- package/dist/lib-esm/primitives/notification/notification.viewport.js +5 -1
- package/dist/lib-esm/primitives/notification/private-notification-element-animated.js +44 -6
- package/dist/lib-esm/primitives/notification/private-notification-element.js +34 -4
- package/dist/lib-esm/primitives/popover/index.d.ts +11 -5
- package/dist/lib-esm/primitives/popover/popover-anchor.d.ts +4 -2
- package/dist/lib-esm/primitives/popover/popover-anchor.js +2 -2
- package/dist/lib-esm/primitives/popover/popover-close.d.ts +4 -2
- package/dist/lib-esm/primitives/popover/popover-close.js +2 -2
- package/dist/lib-esm/primitives/popover/popover-content-container.d.ts +1 -1
- package/dist/lib-esm/primitives/popover/popover-content-container.js +3 -3
- package/dist/lib-esm/primitives/popover/popover-footer.d.ts +1 -1
- package/dist/lib-esm/primitives/popover/popover-main-content.d.ts +1 -1
- package/dist/lib-esm/primitives/popover/popover-root.d.ts +1 -1
- package/dist/lib-esm/primitives/popover/popover-root.js +2 -2
- package/dist/lib-esm/primitives/popover/popover-trigger.d.ts +4 -2
- package/dist/lib-esm/primitives/popover/popover-trigger.js +2 -2
- package/dist/lib-esm/radio-group/index.d.ts +1 -1
- package/dist/lib-esm/radio-group/radio-group.d.ts +1 -1
- package/dist/lib-esm/radio-group/radio-group.js +2 -2
- package/dist/lib-esm/radio-group/radio-item.js +3 -3
- package/dist/lib-esm/radio-group/types.d.ts +1 -1
- package/dist/lib-esm/select/select.js +12 -12
- package/dist/lib-esm/select/types.d.ts +1 -1
- package/dist/lib-esm/select/utils/use-select-exit-animation.d.ts +3 -3
- package/dist/lib-esm/select/utils/use-select-exit-animation.js +3 -3
- package/dist/lib-esm/side-panel/side-panel-close.js +2 -2
- package/dist/lib-esm/side-panel/side-panel-content.js +3 -3
- package/dist/lib-esm/side-panel/side-panel-header.js +2 -2
- package/dist/lib-esm/side-panel/side-panel-overlay.js +3 -3
- package/dist/lib-esm/side-panel/side-panel-trigger.js +2 -2
- package/dist/lib-esm/side-panel/side-panel.js +1 -1
- package/dist/lib-esm/side-panel/types.d.ts +1 -1
- package/dist/lib-esm/switch/switch-item.js +3 -3
- package/dist/lib-esm/switch/types.d.ts +1 -1
- package/dist/lib-esm/toolbar/index.d.ts +2 -2
- package/dist/lib-esm/toolbar/toolbar-button.js +2 -2
- package/dist/lib-esm/toolbar/toolbar-input.js +2 -2
- package/dist/lib-esm/toolbar/toolbar-link.js +2 -2
- package/dist/lib-esm/toolbar/toolbar-root.js +3 -3
- package/dist/lib-esm/toolbar/toolbar-separator.d.ts +1 -1
- package/dist/lib-esm/toolbar/toolbar-separator.js +2 -2
- package/dist/lib-esm/toolbar/toolbar-text-toggle-item.js +2 -2
- package/dist/lib-esm/toolbar/toolbar-toggle-group.d.ts +1 -2
- package/dist/lib-esm/toolbar/toolbar-toggle-group.js +2 -2
- package/dist/lib-esm/toolbar/toolbar-toggle-item.js +2 -2
- package/dist/lib-esm/toolbar/types.d.ts +1 -1
- package/dist/lib-esm/tooltip/tooltip.d.ts +1 -1
- package/dist/lib-esm/tooltip/tooltip.js +6 -6
- package/dist/lib-esm/tooltip/types.d.ts +1 -1
- package/dist/lib-esm/utils/radix-compat/accordion.d.ts +45 -0
- package/dist/lib-esm/utils/radix-compat/accordion.js +299 -0
- package/dist/lib-esm/utils/radix-compat/allow-auto-focus.d.ts +9 -0
- package/dist/lib-esm/utils/radix-compat/allow-auto-focus.js +16 -0
- package/dist/lib-esm/utils/radix-compat/bubble-input.d.ts +14 -0
- package/dist/lib-esm/utils/radix-compat/bubble-input.js +70 -0
- package/dist/lib-esm/utils/radix-compat/button-controls.d.ts +9 -0
- package/dist/lib-esm/utils/radix-compat/button-controls.js +6 -0
- package/dist/lib-esm/utils/radix-compat/checkbox.d.ts +18 -0
- package/dist/lib-esm/utils/radix-compat/checkbox.js +131 -0
- package/dist/lib-esm/utils/radix-compat/collapsible.d.ts +33 -0
- package/dist/lib-esm/utils/radix-compat/collapsible.js +133 -0
- package/dist/lib-esm/utils/radix-compat/collection.d.ts +21 -0
- package/dist/lib-esm/utils/radix-compat/collection.js +82 -0
- package/dist/lib-esm/utils/radix-compat/compose-refs.d.ts +8 -0
- package/dist/lib-esm/utils/radix-compat/compose-refs.js +44 -0
- package/dist/lib-esm/utils/radix-compat/content-size.d.ts +15 -0
- package/dist/lib-esm/utils/radix-compat/content-size.js +61 -0
- package/dist/lib-esm/utils/radix-compat/context-menu.d.ts +56 -0
- package/dist/lib-esm/utils/radix-compat/context-menu.js +191 -0
- package/dist/lib-esm/utils/radix-compat/dialog.d.ts +50 -0
- package/dist/lib-esm/utils/radix-compat/dialog.js +367 -0
- package/dist/lib-esm/utils/radix-compat/dismiss-marker.d.ts +5 -0
- package/dist/lib-esm/utils/radix-compat/dismiss-marker.js +12 -0
- package/dist/lib-esm/utils/radix-compat/dismissable.d.ts +34 -0
- package/dist/lib-esm/utils/radix-compat/dismissable.js +205 -0
- package/dist/lib-esm/utils/radix-compat/dropdown-menu.d.ts +57 -0
- package/dist/lib-esm/utils/radix-compat/dropdown-menu.js +187 -0
- package/dist/lib-esm/utils/radix-compat/focus-scope-component.d.ts +16 -0
- package/dist/lib-esm/utils/radix-compat/focus-scope-component.js +41 -0
- package/dist/lib-esm/utils/radix-compat/focus-scope.d.ts +37 -0
- package/dist/lib-esm/utils/radix-compat/focus-scope.js +288 -0
- package/dist/lib-esm/utils/radix-compat/hide-others.d.ts +6 -0
- package/dist/lib-esm/utils/radix-compat/hide-others.js +18 -0
- package/dist/lib-esm/utils/radix-compat/index.d.ts +14 -0
- package/dist/lib-esm/utils/radix-compat/layers.d.ts +25 -0
- package/dist/lib-esm/utils/radix-compat/layers.js +61 -0
- package/dist/lib-esm/utils/radix-compat/menu.d.ts +98 -0
- package/dist/lib-esm/utils/radix-compat/menu.js +1041 -0
- package/dist/lib-esm/utils/radix-compat/popover.d.ts +44 -0
- package/dist/lib-esm/utils/radix-compat/popover.js +386 -0
- package/dist/lib-esm/utils/radix-compat/popper.d.ts +60 -0
- package/dist/lib-esm/utils/radix-compat/popper.js +416 -0
- package/dist/lib-esm/utils/radix-compat/portal.d.ts +11 -0
- package/dist/lib-esm/utils/radix-compat/portal.js +20 -0
- package/dist/lib-esm/utils/radix-compat/presence.d.ts +20 -0
- package/dist/lib-esm/utils/radix-compat/presence.js +110 -0
- package/dist/lib-esm/utils/radix-compat/radio-group.d.ts +27 -0
- package/dist/lib-esm/utils/radix-compat/radio-group.js +189 -0
- package/dist/lib-esm/utils/radix-compat/roving-focus.d.ts +35 -0
- package/dist/lib-esm/utils/radix-compat/roving-focus.js +237 -0
- package/dist/lib-esm/utils/radix-compat/select.d.ts +82 -0
- package/dist/lib-esm/utils/radix-compat/select.js +901 -0
- package/dist/lib-esm/utils/radix-compat/slot.d.ts +31 -0
- package/dist/lib-esm/utils/radix-compat/slot.js +119 -0
- package/dist/lib-esm/utils/radix-compat/store-options.d.ts +8 -0
- package/dist/lib-esm/utils/radix-compat/store-options.js +10 -0
- package/dist/lib-esm/utils/radix-compat/switch.d.ts +16 -0
- package/dist/lib-esm/utils/radix-compat/switch.js +97 -0
- package/dist/lib-esm/utils/radix-compat/toggle-group.d.ts +41 -0
- package/dist/lib-esm/utils/radix-compat/toggle-group.js +195 -0
- package/dist/lib-esm/utils/radix-compat/toolbar.d.ts +32 -0
- package/dist/lib-esm/utils/radix-compat/toolbar.js +136 -0
- package/dist/lib-esm/utils/radix-compat/tooltip.d.ts +59 -0
- package/dist/lib-esm/utils/radix-compat/tooltip.js +636 -0
- package/dist/lib-esm/utils/radix-compat/typeahead.d.ts +22 -0
- package/dist/lib-esm/utils/radix-compat/typeahead.js +64 -0
- package/dist/lib-esm/utils/radix-compat/types.d.ts +53 -0
- package/dist/lib-esm/utils/radix-compat/viewport-height.d.ts +5 -0
- package/dist/lib-esm/utils/radix-compat/viewport-height.js +28 -0
- package/dist/lib-esm/utils/radix-compat/visually-hidden.d.ts +2 -0
- package/dist/lib-esm/utils/radix-compat/visually-hidden.js +24 -0
- package/package.json +8 -19
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
import { useRef, useEffect, useCallback } from 'react';
|
|
2
|
+
import { useCallbackRef } from '../useCallbackRef.js';
|
|
3
|
+
import { isInsidePersistentElement } from './layers.js';
|
|
4
|
+
|
|
5
|
+
const AUTOFOCUS_ON_MOUNT = 'focusScope.autoFocusOnMount';
|
|
6
|
+
const AUTOFOCUS_ON_UNMOUNT = 'focusScope.autoFocusOnUnmount';
|
|
7
|
+
const EVENT_OPTIONS = {
|
|
8
|
+
bubbles: false,
|
|
9
|
+
cancelable: true
|
|
10
|
+
};
|
|
11
|
+
function arrayRemove(array, item) {
|
|
12
|
+
const updatedArray = [...array];
|
|
13
|
+
const index = updatedArray.indexOf(item);
|
|
14
|
+
if (index !== -1) {
|
|
15
|
+
updatedArray.splice(index, 1);
|
|
16
|
+
}
|
|
17
|
+
return updatedArray;
|
|
18
|
+
}
|
|
19
|
+
function createFocusScopesStack() {
|
|
20
|
+
let stack = [];
|
|
21
|
+
return {
|
|
22
|
+
add(focusScope) {
|
|
23
|
+
const activeFocusScope = stack[0];
|
|
24
|
+
if (focusScope !== activeFocusScope) {
|
|
25
|
+
activeFocusScope?.pause();
|
|
26
|
+
}
|
|
27
|
+
stack = arrayRemove(stack, focusScope);
|
|
28
|
+
stack.unshift(focusScope);
|
|
29
|
+
},
|
|
30
|
+
remove(focusScope) {
|
|
31
|
+
stack = arrayRemove(stack, focusScope);
|
|
32
|
+
stack[0]?.resume();
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
const focusScopesStack = createFocusScopesStack();
|
|
37
|
+
function isSelectableInput(element) {
|
|
38
|
+
return element instanceof HTMLInputElement && 'select' in element;
|
|
39
|
+
}
|
|
40
|
+
function focusElement(element, {
|
|
41
|
+
select = false
|
|
42
|
+
} = {}) {
|
|
43
|
+
if (element && element.focus) {
|
|
44
|
+
const previouslyFocusedElement = document.activeElement;
|
|
45
|
+
element.focus({
|
|
46
|
+
preventScroll: true
|
|
47
|
+
});
|
|
48
|
+
if (element !== previouslyFocusedElement && isSelectableInput(element) && select) {
|
|
49
|
+
element.select();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Focuses the first candidate that actually receives focus.
|
|
55
|
+
*/
|
|
56
|
+
function focusFirst(candidates, {
|
|
57
|
+
select = false
|
|
58
|
+
} = {}) {
|
|
59
|
+
const previouslyFocusedElement = document.activeElement;
|
|
60
|
+
for (const candidate of candidates) {
|
|
61
|
+
focusElement(candidate, {
|
|
62
|
+
select
|
|
63
|
+
});
|
|
64
|
+
if (document.activeElement !== previouslyFocusedElement) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Elements inside `container` that the browser considers tabbable, in DOM order.
|
|
71
|
+
*/
|
|
72
|
+
function getTabbableCandidates(container) {
|
|
73
|
+
const nodes = [];
|
|
74
|
+
const walker = document.createTreeWalker(container, NodeFilter.SHOW_ELEMENT, {
|
|
75
|
+
acceptNode: node => {
|
|
76
|
+
const element = node;
|
|
77
|
+
const isHiddenInput = element.tagName === 'INPUT' && element.type === 'hidden';
|
|
78
|
+
if (element.disabled || element.hidden || isHiddenInput) {
|
|
79
|
+
return NodeFilter.FILTER_SKIP;
|
|
80
|
+
}
|
|
81
|
+
return element.tabIndex >= 0 ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
while (walker.nextNode()) {
|
|
85
|
+
nodes.push(walker.currentNode);
|
|
86
|
+
}
|
|
87
|
+
return nodes;
|
|
88
|
+
}
|
|
89
|
+
function isHidden(node, upTo) {
|
|
90
|
+
if (getComputedStyle(node).visibility === 'hidden') {
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
let current = node;
|
|
94
|
+
while (current) {
|
|
95
|
+
if (current === upTo) {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
if (getComputedStyle(current).display === 'none') {
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
current = current.parentElement;
|
|
102
|
+
}
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
function findVisible(elements, container) {
|
|
106
|
+
return elements.find(element => !isHidden(element, container));
|
|
107
|
+
}
|
|
108
|
+
function getTabbableEdges(container) {
|
|
109
|
+
const candidates = getTabbableCandidates(container);
|
|
110
|
+
const first = findVisible(candidates, container);
|
|
111
|
+
const last = findVisible(candidates.reverse(), container);
|
|
112
|
+
return [first, last];
|
|
113
|
+
}
|
|
114
|
+
function removeLinks(items) {
|
|
115
|
+
return items.filter(item => item.tagName !== 'A');
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Focus management of the Radix `FocusScope`: initial focus, focus restore and Tab looping/trapping.
|
|
119
|
+
* Nested scopes pause the outer ones, so only the innermost scope handles Tab.
|
|
120
|
+
*/
|
|
121
|
+
function useFocusScope({
|
|
122
|
+
container,
|
|
123
|
+
loop = false,
|
|
124
|
+
trapped = false,
|
|
125
|
+
onMountAutoFocus: onMountAutoFocusProp,
|
|
126
|
+
onUnmountAutoFocus: onUnmountAutoFocusProp,
|
|
127
|
+
getMountAutoFocusCandidates
|
|
128
|
+
}) {
|
|
129
|
+
const onMountAutoFocus = useCallbackRef(onMountAutoFocusProp);
|
|
130
|
+
const onUnmountAutoFocus = useCallbackRef(onUnmountAutoFocusProp);
|
|
131
|
+
const getCandidates = useCallbackRef(getMountAutoFocusCandidates ?? (node => removeLinks(getTabbableCandidates(node))));
|
|
132
|
+
const focusScope = useRef({
|
|
133
|
+
paused: false,
|
|
134
|
+
pause() {
|
|
135
|
+
this.paused = true;
|
|
136
|
+
},
|
|
137
|
+
resume() {
|
|
138
|
+
this.paused = false;
|
|
139
|
+
}
|
|
140
|
+
}).current;
|
|
141
|
+
const lastFocusedElementRef = useRef(null);
|
|
142
|
+
useEffect(() => {
|
|
143
|
+
if (!trapped || !container) {
|
|
144
|
+
return undefined;
|
|
145
|
+
}
|
|
146
|
+
// Listening on the document (bubble phase) like Radix: when focusing an element moves focus again, the
|
|
147
|
+
// outer element is recorded last.
|
|
148
|
+
const handleFocusIn = event => {
|
|
149
|
+
if (focusScope.paused) {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
const target = event.target;
|
|
153
|
+
if (container.contains(target)) {
|
|
154
|
+
lastFocusedElementRef.current = target;
|
|
155
|
+
} else if (!isInsidePersistentElement(target)) {
|
|
156
|
+
focusElement(lastFocusedElementRef.current, {
|
|
157
|
+
select: true
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
const handleFocusOut = event => {
|
|
162
|
+
if (focusScope.paused) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
const relatedTarget = event.relatedTarget;
|
|
166
|
+
// A `null` related target means the window lost focus, or the focused element was removed.
|
|
167
|
+
if (relatedTarget === null) {
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
if (!container.contains(relatedTarget) && !isInsidePersistentElement(relatedTarget)) {
|
|
171
|
+
focusElement(lastFocusedElementRef.current, {
|
|
172
|
+
select: true
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
// When the focused element gets removed from the DOM, browsers move focus to the body.
|
|
177
|
+
const handleMutations = mutations => {
|
|
178
|
+
if (document.activeElement !== document.body) {
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
if (mutations.some(mutation => mutation.removedNodes.length > 0)) {
|
|
182
|
+
focusElement(container);
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
document.addEventListener('focusin', handleFocusIn);
|
|
186
|
+
document.addEventListener('focusout', handleFocusOut);
|
|
187
|
+
const mutationObserver = new MutationObserver(handleMutations);
|
|
188
|
+
mutationObserver.observe(container, {
|
|
189
|
+
childList: true,
|
|
190
|
+
subtree: true
|
|
191
|
+
});
|
|
192
|
+
return () => {
|
|
193
|
+
document.removeEventListener('focusin', handleFocusIn);
|
|
194
|
+
document.removeEventListener('focusout', handleFocusOut);
|
|
195
|
+
mutationObserver.disconnect();
|
|
196
|
+
};
|
|
197
|
+
}, [trapped, container, focusScope]);
|
|
198
|
+
useEffect(() => {
|
|
199
|
+
if (!container) {
|
|
200
|
+
return undefined;
|
|
201
|
+
}
|
|
202
|
+
focusScopesStack.add(focusScope);
|
|
203
|
+
const previouslyFocusedElement = document.activeElement;
|
|
204
|
+
const hasFocusedCandidate = container.contains(previouslyFocusedElement);
|
|
205
|
+
if (!hasFocusedCandidate) {
|
|
206
|
+
const mountEvent = new CustomEvent(AUTOFOCUS_ON_MOUNT, EVENT_OPTIONS);
|
|
207
|
+
container.addEventListener(AUTOFOCUS_ON_MOUNT, onMountAutoFocus);
|
|
208
|
+
container.dispatchEvent(mountEvent);
|
|
209
|
+
if (!mountEvent.defaultPrevented) {
|
|
210
|
+
focusFirst(getCandidates(container), {
|
|
211
|
+
select: true
|
|
212
|
+
});
|
|
213
|
+
if (document.activeElement === previouslyFocusedElement) {
|
|
214
|
+
focusElement(container);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
return () => {
|
|
219
|
+
container.removeEventListener(AUTOFOCUS_ON_MOUNT, onMountAutoFocus);
|
|
220
|
+
// Focusing during unmount is delayed until the element is gone.
|
|
221
|
+
setTimeout(() => {
|
|
222
|
+
const unmountEvent = new CustomEvent(AUTOFOCUS_ON_UNMOUNT, EVENT_OPTIONS);
|
|
223
|
+
container.addEventListener(AUTOFOCUS_ON_UNMOUNT, onUnmountAutoFocus);
|
|
224
|
+
container.dispatchEvent(unmountEvent);
|
|
225
|
+
if (!unmountEvent.defaultPrevented) {
|
|
226
|
+
focusElement(previouslyFocusedElement ?? document.body, {
|
|
227
|
+
select: true
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
container.removeEventListener(AUTOFOCUS_ON_UNMOUNT, onUnmountAutoFocus);
|
|
231
|
+
focusScopesStack.remove(focusScope);
|
|
232
|
+
}, 0);
|
|
233
|
+
};
|
|
234
|
+
}, [container, onMountAutoFocus, onUnmountAutoFocus, getCandidates, focusScope]);
|
|
235
|
+
const onKeyDown = useCallback(event => {
|
|
236
|
+
if (!loop && !trapped) {
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
if (focusScope.paused) {
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
const isTabKey = event.key === 'Tab' && !event.altKey && !event.ctrlKey && !event.metaKey;
|
|
243
|
+
const focusedElement = document.activeElement;
|
|
244
|
+
if (isTabKey && focusedElement) {
|
|
245
|
+
const scopeContainer = event.currentTarget;
|
|
246
|
+
const [first, last] = getTabbableEdges(scopeContainer);
|
|
247
|
+
const hasTabbableElementsInside = first && last;
|
|
248
|
+
if (!hasTabbableElementsInside) {
|
|
249
|
+
if (focusedElement === scopeContainer) {
|
|
250
|
+
event.preventDefault();
|
|
251
|
+
}
|
|
252
|
+
} else if (!event.shiftKey && focusedElement === last) {
|
|
253
|
+
event.preventDefault();
|
|
254
|
+
if (loop) {
|
|
255
|
+
focusElement(first, {
|
|
256
|
+
select: true
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
} else if (event.shiftKey && focusedElement === first) {
|
|
260
|
+
event.preventDefault();
|
|
261
|
+
if (loop) {
|
|
262
|
+
focusElement(last, {
|
|
263
|
+
select: true
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
// Inert elements outside a modal can't take focus, so a Tab that heads outside doesn't move it. Radix
|
|
269
|
+
// brought focus back to the last focused element in that case, so it's done here too.
|
|
270
|
+
if (isTabKey && trapped && focusedElement && !event.defaultPrevented) {
|
|
271
|
+
const {
|
|
272
|
+
nativeEvent
|
|
273
|
+
} = event;
|
|
274
|
+
window.setTimeout(() => {
|
|
275
|
+
if (!nativeEvent.defaultPrevented && document.activeElement === focusedElement) {
|
|
276
|
+
focusElement(lastFocusedElementRef.current, {
|
|
277
|
+
select: true
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
}, [loop, trapped, focusScope]);
|
|
283
|
+
return {
|
|
284
|
+
onKeyDown
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
export { focusElement, focusFirst, getTabbableCandidates, getTabbableEdges, removeLinks, useFocusScope };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hides everything but the content of a modal overlay with `aria-hidden` while it is mounted, like Radix did.
|
|
3
|
+
* Ariakit makes the rest of the page inert as well, but tools that read the accessibility tree, like Testing
|
|
4
|
+
* Library queries, only leave out `aria-hidden` content.
|
|
5
|
+
*/
|
|
6
|
+
export declare function useHideOthers(content: HTMLElement | null, enabled: boolean): void;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { hideOthers } from 'aria-hidden';
|
|
2
|
+
import { useEffect } from 'react';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Hides everything but the content of a modal overlay with `aria-hidden` while it is mounted, like Radix did.
|
|
6
|
+
* Ariakit makes the rest of the page inert as well, but tools that read the accessibility tree, like Testing
|
|
7
|
+
* Library queries, only leave out `aria-hidden` content.
|
|
8
|
+
*/
|
|
9
|
+
function useHideOthers(content, enabled) {
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
if (!enabled || !content) {
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
return hideOthers(content);
|
|
15
|
+
}, [content, enabled]);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { useHideOthers };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { BubbleInput, isFormControl } from './bubble-input';
|
|
2
|
+
export { createCollection } from './collection';
|
|
3
|
+
export { composeRefs, useComposedRefs } from './compose-refs';
|
|
4
|
+
export { useCollapsibleContentSize } from './content-size';
|
|
5
|
+
export { preventRightClickDismiss, useDismissable } from './dismissable';
|
|
6
|
+
export { focusElement, focusFirst, getTabbableCandidates, getTabbableEdges, removeLinks, useFocusScope, type UseFocusScopeOptions, } from './focus-scope';
|
|
7
|
+
export { getPersistentElements, isInsidePersistentElement, useLayer, usePersistentElement } from './layers';
|
|
8
|
+
export { getPopperCssVariables, POPPER_WRAPPER_ATTRIBUTE, PopperArrow, PopperArrowProvider, usePopper, type PopperAnchor, type PopperArrowProps, } from './popper';
|
|
9
|
+
export { Portal, type PortalComponentProps } from './portal';
|
|
10
|
+
export { Presence, usePresence } from './presence';
|
|
11
|
+
export { RovingFocusGroup, RovingFocusGroupItem, wrapArray, type RovingFocusGroupItemProps, type RovingFocusGroupProps, } from './roving-focus';
|
|
12
|
+
export { getElementRef, mergeSlotProps, Slot, type SlotProps } from './slot';
|
|
13
|
+
export { findNextItem, getNextMatch, isTypeaheadKey, useTypeaheadSearch } from './typeahead';
|
|
14
|
+
export type { Align, Direction, DismissableLayerProps, FocusOutsideEvent, FocusScopeProps, Orientation, PointerDownOutsideEvent, PopperContentProps, PortalProps, PrimitiveProps, Side, } from './types';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Blueprint layers (overlays and notifications) in the order they opened.
|
|
3
|
+
*
|
|
4
|
+
* Overlays use Ariakit while notifications use Radix Toast. Radix arbitrated Escape between all its layers
|
|
5
|
+
* with a single stack, which this registry keeps for the two libraries: only the most recently opened layer
|
|
6
|
+
* reacts to a document level Escape key press. Like in Radix, a layer that blocks outside pointer events (a modal
|
|
7
|
+
* one) also keeps the layers below it from reacting to pointer downs outside of them.
|
|
8
|
+
*/
|
|
9
|
+
export type LayerKind = 'overlay' | 'notification';
|
|
10
|
+
/**
|
|
11
|
+
* Registers a layer while `enabled`, and tells which layers opened after it.
|
|
12
|
+
*/
|
|
13
|
+
export declare function useLayer(kind: LayerKind, enabled: boolean, blocksOutsidePointerEvents?: boolean): {
|
|
14
|
+
/** Whether a layer of the given kind opened after this one. */
|
|
15
|
+
hasLayerAbove: (otherKind: LayerKind) => boolean;
|
|
16
|
+
/** Whether a layer that blocks outside pointer events opened after this one. */
|
|
17
|
+
hasBlockingLayerAbove: () => boolean;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Registers an element that must stay interactive while a modal overlay is open, like the notification viewport.
|
|
21
|
+
* Pointer and focus interactions inside it also don't dismiss open overlays.
|
|
22
|
+
*/
|
|
23
|
+
export declare function usePersistentElement(element: HTMLElement | null): void;
|
|
24
|
+
export declare function getPersistentElements(): HTMLElement[];
|
|
25
|
+
export declare function isInsidePersistentElement(target: EventTarget | null): boolean;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { useRef, useEffect, useMemo } from 'react';
|
|
2
|
+
|
|
3
|
+
let layers = [];
|
|
4
|
+
const persistentElements = new Set();
|
|
5
|
+
function addLayer(layer) {
|
|
6
|
+
layers = [...layers.filter(item => item !== layer), layer];
|
|
7
|
+
}
|
|
8
|
+
function removeLayer(layer) {
|
|
9
|
+
layers = layers.filter(item => item !== layer);
|
|
10
|
+
}
|
|
11
|
+
function getLayersAbove(layer) {
|
|
12
|
+
const index = layers.indexOf(layer);
|
|
13
|
+
return index === -1 ? [] : layers.slice(index + 1);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Registers a layer while `enabled`, and tells which layers opened after it.
|
|
17
|
+
*/
|
|
18
|
+
function useLayer(kind, enabled, blocksOutsidePointerEvents = false) {
|
|
19
|
+
const layerRef = useRef({
|
|
20
|
+
kind,
|
|
21
|
+
blocksOutsidePointerEvents
|
|
22
|
+
});
|
|
23
|
+
layerRef.current.blocksOutsidePointerEvents = blocksOutsidePointerEvents;
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
if (!enabled) {
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
const layer = layerRef.current;
|
|
29
|
+
addLayer(layer);
|
|
30
|
+
return () => removeLayer(layer);
|
|
31
|
+
}, [enabled]);
|
|
32
|
+
return useMemo(() => ({
|
|
33
|
+
/** Whether a layer of the given kind opened after this one. */
|
|
34
|
+
hasLayerAbove: otherKind => getLayersAbove(layerRef.current).some(item => item.kind === otherKind),
|
|
35
|
+
/** Whether a layer that blocks outside pointer events opened after this one. */
|
|
36
|
+
hasBlockingLayerAbove: () => getLayersAbove(layerRef.current).some(item => item.blocksOutsidePointerEvents)
|
|
37
|
+
}), []);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Registers an element that must stay interactive while a modal overlay is open, like the notification viewport.
|
|
41
|
+
* Pointer and focus interactions inside it also don't dismiss open overlays.
|
|
42
|
+
*/
|
|
43
|
+
function usePersistentElement(element) {
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
if (!element) {
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
persistentElements.add(element);
|
|
49
|
+
return () => {
|
|
50
|
+
persistentElements.delete(element);
|
|
51
|
+
};
|
|
52
|
+
}, [element]);
|
|
53
|
+
}
|
|
54
|
+
function getPersistentElements() {
|
|
55
|
+
return Array.from(persistentElements).filter(element => element.isConnected);
|
|
56
|
+
}
|
|
57
|
+
function isInsidePersistentElement(target) {
|
|
58
|
+
return target instanceof Node && getPersistentElements().some(element => element.contains(target));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export { getPersistentElements, isInsidePersistentElement, useLayer, usePersistentElement };
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { type MutableRefObject, type ReactNode } from 'react';
|
|
2
|
+
import { type PopperAnchor, type PopperArrowProps } from './popper';
|
|
3
|
+
import { type Direction, type DismissableLayerProps, type FocusScopeProps, type PopperContentProps, type PortalProps, type PrimitiveProps } from './types';
|
|
4
|
+
type CheckedState = boolean | 'indeterminate';
|
|
5
|
+
/** Closes the whole menu from anywhere inside it. */
|
|
6
|
+
export declare function useMenuClose(): () => void;
|
|
7
|
+
export interface MenuProps {
|
|
8
|
+
children?: ReactNode;
|
|
9
|
+
open?: boolean;
|
|
10
|
+
onOpenChange?(open: boolean): void;
|
|
11
|
+
dir?: Direction;
|
|
12
|
+
modal?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export declare const Root: {
|
|
15
|
+
(props: MenuProps): import("react/jsx-runtime").JSX.Element;
|
|
16
|
+
displayName: string;
|
|
17
|
+
};
|
|
18
|
+
export interface MenuAnchorProps extends PrimitiveProps<'div'> {
|
|
19
|
+
/** Positions the content against a virtual element, e.g. the pointer position of a context menu. */
|
|
20
|
+
virtualRef?: MutableRefObject<PopperAnchor>;
|
|
21
|
+
}
|
|
22
|
+
export declare const Anchor: import("react").ForwardRefExoticComponent<MenuAnchorProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
23
|
+
export interface MenuPortalProps extends PortalProps {
|
|
24
|
+
children?: ReactNode;
|
|
25
|
+
}
|
|
26
|
+
export declare const Portal: {
|
|
27
|
+
({ forceMount, children, container }: MenuPortalProps): import("react/jsx-runtime").JSX.Element;
|
|
28
|
+
displayName: string;
|
|
29
|
+
};
|
|
30
|
+
export interface MenuContentProps extends PrimitiveProps<'div'>, PopperContentProps, DismissableLayerProps, Pick<FocusScopeProps, 'onCloseAutoFocus'> {
|
|
31
|
+
/** Whether keyboard navigation loops from the last item to the first and back. */
|
|
32
|
+
loop?: boolean;
|
|
33
|
+
/** Called when focus moves into the content after opening. Can be prevented. */
|
|
34
|
+
onOpenAutoFocus?: (event: Event) => void;
|
|
35
|
+
/** Called when the keyboard focuses the content, before focus moves to the first item. Can be prevented. */
|
|
36
|
+
onEntryFocus?: (event: Event) => void;
|
|
37
|
+
/** Keeps the content mounted when closed, for animations controlled from the outside. */
|
|
38
|
+
forceMount?: true;
|
|
39
|
+
}
|
|
40
|
+
export declare const Content: import("react").ForwardRefExoticComponent<MenuContentProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
41
|
+
export type MenuGroupProps = PrimitiveProps<'div'>;
|
|
42
|
+
export declare const Group: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
|
|
43
|
+
asChild?: boolean;
|
|
44
|
+
} & import("react").RefAttributes<HTMLDivElement>>;
|
|
45
|
+
export type MenuLabelProps = PrimitiveProps<'div'>;
|
|
46
|
+
export declare const Label: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
|
|
47
|
+
asChild?: boolean;
|
|
48
|
+
} & import("react").RefAttributes<HTMLDivElement>>;
|
|
49
|
+
export interface MenuItemProps extends Omit<PrimitiveProps<'div'>, 'onSelect'> {
|
|
50
|
+
disabled?: boolean;
|
|
51
|
+
/** Text used by typeahead instead of the item's text content. */
|
|
52
|
+
textValue?: string;
|
|
53
|
+
/** Called when the item is selected; call `event.preventDefault()` to keep the menu open. */
|
|
54
|
+
onSelect?: (event: Event) => void;
|
|
55
|
+
}
|
|
56
|
+
export declare const Item: import("react").ForwardRefExoticComponent<MenuItemProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
57
|
+
export interface MenuItemImplProps extends PrimitiveProps<'div'> {
|
|
58
|
+
disabled?: boolean;
|
|
59
|
+
textValue?: string;
|
|
60
|
+
}
|
|
61
|
+
export interface MenuCheckboxItemProps extends MenuItemProps {
|
|
62
|
+
checked?: CheckedState;
|
|
63
|
+
onCheckedChange?: (checked: boolean) => void;
|
|
64
|
+
}
|
|
65
|
+
export declare const CheckboxItem: import("react").ForwardRefExoticComponent<MenuCheckboxItemProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
66
|
+
export interface MenuRadioGroupProps extends MenuGroupProps {
|
|
67
|
+
value?: string;
|
|
68
|
+
onValueChange?: (value: string) => void;
|
|
69
|
+
}
|
|
70
|
+
export declare const RadioGroup: import("react").ForwardRefExoticComponent<MenuRadioGroupProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
71
|
+
export interface MenuRadioItemProps extends MenuItemProps {
|
|
72
|
+
value: string;
|
|
73
|
+
}
|
|
74
|
+
export declare const RadioItem: import("react").ForwardRefExoticComponent<MenuRadioItemProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
75
|
+
export interface MenuItemIndicatorProps extends PrimitiveProps<'span'> {
|
|
76
|
+
forceMount?: true;
|
|
77
|
+
}
|
|
78
|
+
export declare const ItemIndicator: import("react").ForwardRefExoticComponent<MenuItemIndicatorProps & import("react").RefAttributes<HTMLSpanElement>>;
|
|
79
|
+
export type MenuSeparatorProps = PrimitiveProps<'div'>;
|
|
80
|
+
export declare const Separator: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
|
|
81
|
+
asChild?: boolean;
|
|
82
|
+
} & import("react").RefAttributes<HTMLDivElement>>;
|
|
83
|
+
export type MenuArrowProps = PopperArrowProps;
|
|
84
|
+
export declare const Arrow: import("react").ForwardRefExoticComponent<Omit<PopperArrowProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
|
|
85
|
+
export interface MenuSubProps {
|
|
86
|
+
children?: ReactNode;
|
|
87
|
+
open?: boolean;
|
|
88
|
+
onOpenChange?(open: boolean): void;
|
|
89
|
+
}
|
|
90
|
+
export declare const Sub: {
|
|
91
|
+
(props: MenuSubProps): import("react/jsx-runtime").JSX.Element;
|
|
92
|
+
displayName: string;
|
|
93
|
+
};
|
|
94
|
+
export type MenuSubTriggerProps = MenuItemImplProps;
|
|
95
|
+
export declare const SubTrigger: import("react").ForwardRefExoticComponent<MenuItemImplProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
96
|
+
export type MenuSubContentProps = Omit<MenuContentProps, 'onCloseAutoFocus' | 'onEntryFocus' | 'side' | 'align' | 'onOpenAutoFocus'>;
|
|
97
|
+
export declare const SubContent: import("react").ForwardRefExoticComponent<MenuSubContentProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
98
|
+
export {};
|