@box/blueprint-web 6.41.9 → 6.42.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib-esm/index.d.ts
CHANGED
|
@@ -54,5 +54,6 @@ export * from './toolbar';
|
|
|
54
54
|
export * from './tooltip';
|
|
55
55
|
export * from './trigger-button';
|
|
56
56
|
export * from './util-components/scrollable-container/scrollable-container';
|
|
57
|
+
export * from './util-components/focus-trap';
|
|
57
58
|
export * from './utils/useBreakpoint';
|
|
58
59
|
export * from './utils/keyboardUtils';
|
package/lib-esm/index.js
CHANGED
|
@@ -67,6 +67,7 @@ export { Toolbar } from './toolbar/index.js';
|
|
|
67
67
|
export { Tooltip, TooltipProvider } from './tooltip/tooltip.js';
|
|
68
68
|
export { TriggerButton } from './trigger-button/trigger-button.js';
|
|
69
69
|
export { ScrollContext, ScrollableContainer, useScroll, useScrollContext } from './util-components/scrollable-container/scrollable-container.js';
|
|
70
|
+
export { FocusTrap } from './util-components/focus-trap/focus-trap.js';
|
|
70
71
|
export { Breakpoint, useBreakpoint } from './utils/useBreakpoint.js';
|
|
71
72
|
export { isCtrlKeyPressed, isDeleteKeyPressed, keys } from './utils/keyboardUtils.js';
|
|
72
73
|
export { useNotification } from './primitives/notification/notification-provider.js';
|
|
@@ -9,7 +9,8 @@ const TabList = /*#__PURE__*/forwardRef(function TabList(props, ref) {
|
|
|
9
9
|
const {
|
|
10
10
|
className,
|
|
11
11
|
variant = 'default',
|
|
12
|
-
containerClassname
|
|
12
|
+
containerClassname,
|
|
13
|
+
...rest
|
|
13
14
|
} = props;
|
|
14
15
|
const tab = useTabs();
|
|
15
16
|
if (!tab) {
|
|
@@ -18,7 +19,7 @@ const TabList = /*#__PURE__*/forwardRef(function TabList(props, ref) {
|
|
|
18
19
|
return jsx("div", {
|
|
19
20
|
className: clsx(styles.tabsListContainer, containerClassname),
|
|
20
21
|
children: jsx(TabList$1, {
|
|
21
|
-
...
|
|
22
|
+
...rest,
|
|
22
23
|
ref: ref,
|
|
23
24
|
className: clsx(variant === 'contentSwitcher' ? styles.contentSwitchTabList : styles.tabList, className),
|
|
24
25
|
store: tab
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { useRef, useCallback, useEffect } from 'react';
|
|
3
|
+
import tabbable from 'tabbable';
|
|
4
|
+
|
|
5
|
+
// TODO(DISC-1141): write unit tests
|
|
6
|
+
const FocusTrap = ({
|
|
7
|
+
containerRef,
|
|
8
|
+
children,
|
|
9
|
+
customInitialFocus
|
|
10
|
+
}) => {
|
|
11
|
+
const previousFocusEl = useRef(null);
|
|
12
|
+
const getTabbableElements = useCallback(() => {
|
|
13
|
+
if (!containerRef.current) {
|
|
14
|
+
throw new Error('Could not initialize focus-trapping - container is missing');
|
|
15
|
+
}
|
|
16
|
+
const tabbableEls = tabbable(containerRef.current);
|
|
17
|
+
if (!tabbableEls.length) {
|
|
18
|
+
throw new Error('Could not initialize focus-trapping - focusable elements are missing');
|
|
19
|
+
}
|
|
20
|
+
return tabbableEls;
|
|
21
|
+
}, [containerRef]);
|
|
22
|
+
const focusFirstTabbableElement = useCallback(() => {
|
|
23
|
+
const tabbableEls = getTabbableElements();
|
|
24
|
+
tabbableEls[0].focus();
|
|
25
|
+
}, [getTabbableElements]);
|
|
26
|
+
const focusLastTabbableElement = useCallback(() => {
|
|
27
|
+
const tabbableEls = getTabbableElements();
|
|
28
|
+
tabbableEls[tabbableEls.length - 1].focus();
|
|
29
|
+
}, [getTabbableElements]);
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
previousFocusEl.current = document.activeElement;
|
|
32
|
+
customInitialFocus ? customInitialFocus(getTabbableElements()) : focusFirstTabbableElement();
|
|
33
|
+
return () => {
|
|
34
|
+
if (previousFocusEl.current) {
|
|
35
|
+
previousFocusEl.current.focus();
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}, [customInitialFocus, focusFirstTabbableElement, getTabbableElements]);
|
|
39
|
+
return jsxs(Fragment, {
|
|
40
|
+
children: [jsx("i", {
|
|
41
|
+
"aria-hidden": true,
|
|
42
|
+
onFocus: focusLastTabbableElement,
|
|
43
|
+
tabIndex: 0
|
|
44
|
+
}), children, jsx("i", {
|
|
45
|
+
"aria-hidden": true,
|
|
46
|
+
onFocus: focusFirstTabbableElement,
|
|
47
|
+
tabIndex: 0
|
|
48
|
+
})]
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export { FocusTrap };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@box/blueprint-web",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.42.1",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"@box/storybook-utils": "^0.0.8"
|
|
59
59
|
},
|
|
60
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "62264a08465fad473f298ca4b8deb24bb26a1e88",
|
|
61
61
|
"module": "lib-esm/index.js",
|
|
62
62
|
"main": "lib-esm/index.js",
|
|
63
63
|
"exports": {
|