@carbon/ibm-products-web-components 0.22.0-rc.0 → 0.23.0-rc.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/es/components/interstitial-screen/interstitial-screen-body-item.js +2 -0
- package/es/components/interstitial-screen/interstitial-screen-body-item.js.map +1 -1
- package/es/components/interstitial-screen/interstitial-screen-body.js +15 -16
- package/es/components/interstitial-screen/interstitial-screen-body.js.map +1 -1
- package/es/components/interstitial-screen/interstitial-screen-footer.d.ts +1 -0
- package/es/components/interstitial-screen/interstitial-screen-footer.js +9 -4
- package/es/components/interstitial-screen/interstitial-screen-footer.js.map +1 -1
- package/es/components/interstitial-screen/interstitial-screen-header.d.ts +2 -1
- package/es/components/interstitial-screen/interstitial-screen-header.js +4 -0
- package/es/components/interstitial-screen/interstitial-screen-header.js.map +1 -1
- package/es/components/interstitial-screen/interstitial-screen.d.ts +1 -0
- package/es/components/interstitial-screen/interstitial-screen.js +9 -1
- package/es/components/interstitial-screen/interstitial-screen.js.map +1 -1
- package/es/components/notification-panel/notification-footer.js +3 -2
- package/es/components/notification-panel/notification-footer.js.map +1 -1
- package/es/components/notification-panel/notification.d.ts +1 -7
- package/es/components/notification-panel/notification.js +11 -10
- package/es/components/notification-panel/notification.js.map +1 -1
- package/es/components/options-tile/options-tile.js +3 -2
- package/es/components/options-tile/options-tile.js.map +1 -1
- package/es/components/page-header/_story-assets/set-of-breadcrumbs.js +3 -2
- package/es/components/page-header/_story-assets/set-of-breadcrumbs.js.map +1 -1
- package/es/components/page-header/page-header-scroller.js +5 -4
- package/es/components/page-header/page-header-scroller.js.map +1 -1
- package/es/components/page-header/page-header.test.js +3 -2
- package/es/components/page-header/page-header.test.js.map +1 -1
- package/es/components/side-panel/_story-assets/index.d.ts +3 -0
- package/es/components/side-panel/_story-assets/index.js +63 -5
- package/es/components/side-panel/_story-assets/index.js.map +1 -1
- package/es/components/side-panel/side-panel.d.ts +2 -0
- package/es/components/side-panel/side-panel.js +43 -5
- package/es/components/side-panel/side-panel.js.map +1 -1
- package/es/components/side-panel/side-panel.scss.js +1 -1
- package/es/components/side-panel/story-styles.scss.js +1 -1
- package/es/components/tearsheet/tearsheet.scss.js +1 -1
- package/es/components/user-avatar/user-avatar.d.ts +1 -5
- package/es/components/user-avatar/user-avatar.js +3 -2
- package/es/components/user-avatar/user-avatar.js.map +1 -1
- package/es/packages/ibm-products-web-components/package.json.js +1 -1
- package/es/utilities/manageFocusTrap/manageFocusTrap.d.ts +13 -0
- package/es/utilities/manageFocusTrap/manageFocusTrap.js +138 -0
- package/es/utilities/manageFocusTrap/manageFocusTrap.js.map +1 -0
- package/es-custom/components/about-modal/about-modal.scss.js +1 -1
- package/es-custom/components/full-page-error/full-page-error.scss.js +1 -1
- package/es-custom/components/interstitial-screen/interstitial-screen-body-item.js +2 -0
- package/es-custom/components/interstitial-screen/interstitial-screen-body-item.js.map +1 -1
- package/es-custom/components/interstitial-screen/interstitial-screen-body-item.scss.js +1 -1
- package/es-custom/components/interstitial-screen/interstitial-screen-body.js +15 -16
- package/es-custom/components/interstitial-screen/interstitial-screen-body.js.map +1 -1
- package/es-custom/components/interstitial-screen/interstitial-screen-body.scss.js +1 -1
- package/es-custom/components/interstitial-screen/interstitial-screen-footer.d.ts +1 -0
- package/es-custom/components/interstitial-screen/interstitial-screen-footer.js +9 -4
- package/es-custom/components/interstitial-screen/interstitial-screen-footer.js.map +1 -1
- package/es-custom/components/interstitial-screen/interstitial-screen-footer.scss.js +1 -1
- package/es-custom/components/interstitial-screen/interstitial-screen-header.d.ts +2 -1
- package/es-custom/components/interstitial-screen/interstitial-screen-header.js +4 -0
- package/es-custom/components/interstitial-screen/interstitial-screen-header.js.map +1 -1
- package/es-custom/components/interstitial-screen/interstitial-screen-header.scss.js +1 -1
- package/es-custom/components/interstitial-screen/interstitial-screen.d.ts +1 -0
- package/es-custom/components/interstitial-screen/interstitial-screen.js +9 -1
- package/es-custom/components/interstitial-screen/interstitial-screen.js.map +1 -1
- package/es-custom/components/interstitial-screen/interstitial-screen.scss.js +1 -1
- package/es-custom/components/notification-panel/notification-footer.js +3 -2
- package/es-custom/components/notification-panel/notification-footer.js.map +1 -1
- package/es-custom/components/notification-panel/notification-footer.scss.js +1 -1
- package/es-custom/components/notification-panel/notification-panel.scss.js +1 -1
- package/es-custom/components/notification-panel/notification.d.ts +1 -7
- package/es-custom/components/notification-panel/notification.js +11 -10
- package/es-custom/components/notification-panel/notification.js.map +1 -1
- package/es-custom/components/notification-panel/notification.scss.js +1 -1
- package/es-custom/components/options-tile/options-tile.js +3 -2
- package/es-custom/components/options-tile/options-tile.js.map +1 -1
- package/es-custom/components/options-tile/options-tile.scss.js +1 -1
- package/es-custom/components/page-header/_story-assets/set-of-breadcrumbs.js +3 -2
- package/es-custom/components/page-header/_story-assets/set-of-breadcrumbs.js.map +1 -1
- package/es-custom/components/page-header/_story-assets/set-of-breadcrumbs.scss.js +1 -1
- package/es-custom/components/page-header/_story-assets/set-of-tags/set-of-tags.scss.js +1 -1
- package/es-custom/components/page-header/page-header-scroller.js +5 -4
- package/es-custom/components/page-header/page-header-scroller.js.map +1 -1
- package/es-custom/components/page-header/page-header.scss.js +1 -1
- package/es-custom/components/page-header/page-header.test.js +3 -2
- package/es-custom/components/page-header/page-header.test.js.map +1 -1
- package/es-custom/components/side-panel/_story-assets/index.d.ts +3 -0
- package/es-custom/components/side-panel/_story-assets/index.js +63 -5
- package/es-custom/components/side-panel/_story-assets/index.js.map +1 -1
- package/es-custom/components/side-panel/side-panel.d.ts +2 -0
- package/es-custom/components/side-panel/side-panel.js +43 -5
- package/es-custom/components/side-panel/side-panel.js.map +1 -1
- package/es-custom/components/side-panel/side-panel.scss.js +1 -1
- package/es-custom/components/side-panel/story-styles.scss.js +1 -1
- package/es-custom/components/tearsheet/tearsheet.scss.js +1 -1
- package/es-custom/components/truncated-text/truncated-text.scss.js +1 -1
- package/es-custom/components/user-avatar/user-avatar.d.ts +1 -5
- package/es-custom/components/user-avatar/user-avatar.js +3 -2
- package/es-custom/components/user-avatar/user-avatar.js.map +1 -1
- package/es-custom/components/user-avatar/user-avatar.scss.js +1 -1
- package/es-custom/packages/ibm-products-web-components/package.json.js +1 -1
- package/es-custom/utilities/manageFocusTrap/manageFocusTrap.d.ts +13 -0
- package/es-custom/utilities/manageFocusTrap/manageFocusTrap.js +138 -0
- package/es-custom/utilities/manageFocusTrap/manageFocusTrap.js.map +1 -0
- package/lib/components/interstitial-screen/interstitial-screen-footer.d.ts +1 -0
- package/lib/components/interstitial-screen/interstitial-screen-header.d.ts +2 -1
- package/lib/components/interstitial-screen/interstitial-screen.d.ts +1 -0
- package/lib/components/notification-panel/notification.d.ts +1 -7
- package/lib/components/side-panel/_story-assets/index.d.ts +3 -0
- package/lib/components/side-panel/side-panel.d.ts +2 -0
- package/lib/components/user-avatar/user-avatar.d.ts +1 -5
- package/lib/utilities/manageFocusTrap/manageFocusTrap.d.ts +13 -0
- package/package.json +9 -7
- package/scss/components/side-panel/side-panel.scss +5 -0
- package/telemetry.yml +164 -1
- package/scss/components/about-modal/story-styles.scss +0 -34
- package/scss/components/api-key-modal/story-styles.scss +0 -10
- package/scss/components/full-page-error/story-styles.scss +0 -24
- package/scss/components/import-modal/story-styles.scss +0 -10
- package/scss/components/interstitial-screen/story-styles.scss +0 -27
- package/scss/components/notification-panel/story-styles.scss +0 -116
- package/scss/components/options-tile/story-styles.scss +0 -21
- package/scss/components/side-panel/story-styles.scss +0 -47
- package/scss/components/tearsheet/story-styles.scss +0 -21
- package/scss/components/truncated-text/story-styles.scss +0 -14
- package/scss/components/user-avatar/story-styles.scss +0 -10
@@ -0,0 +1,138 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright IBM Corp. 2024
|
3
|
+
*
|
4
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
6
|
+
*/
|
7
|
+
|
8
|
+
import { selectorTabbable, prefix } from '@carbon/web-components/es/globals/settings';
|
9
|
+
|
10
|
+
/**
|
11
|
+
* @license
|
12
|
+
*
|
13
|
+
* Copyright IBM Corp. 2025
|
14
|
+
*
|
15
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
16
|
+
* LICENSE file in the root directory of this source tree.
|
17
|
+
*/
|
18
|
+
/**
|
19
|
+
* Traps focus within a set of containers, ensuring it stays within focusable elements.
|
20
|
+
* @param {NodeListOf<Element>} containers - The containers to trap focus within.
|
21
|
+
* @returns {object} An object with a `cleanup` method to remove event listeners.
|
22
|
+
*/
|
23
|
+
let _containers = [];
|
24
|
+
const registerFocusableContainers = (container) => {
|
25
|
+
if (container) {
|
26
|
+
_containers.push(container);
|
27
|
+
}
|
28
|
+
};
|
29
|
+
const clearFocusableContainers = () => {
|
30
|
+
_containers.length = 0;
|
31
|
+
};
|
32
|
+
const trapFocus = (containers) => {
|
33
|
+
const selectorTabbable$1 = selectorTabbable.replace(`${prefix}-button`, `${prefix}-button:not([disabled]), ${prefix}-selectable-tag`);
|
34
|
+
if (containers && containers.length > 0) {
|
35
|
+
_containers = containers;
|
36
|
+
}
|
37
|
+
if (!_containers.length) {
|
38
|
+
return { cleanup: () => { } };
|
39
|
+
}
|
40
|
+
/**
|
41
|
+
* Given a container element, return the best candidate to focus.
|
42
|
+
* - If element itself is tabbable, return it.
|
43
|
+
* - Otherwise, find the first tabbable descendant.
|
44
|
+
*/
|
45
|
+
const getFocusTarget = (el) => {
|
46
|
+
if (!el) {
|
47
|
+
return null;
|
48
|
+
}
|
49
|
+
if (el.tagName === 'BUTTON' || el.tabIndex >= 0) {
|
50
|
+
return el;
|
51
|
+
}
|
52
|
+
const inner = el.querySelector('button, [tabindex]:not([tabindex="-1"])');
|
53
|
+
return inner || el;
|
54
|
+
};
|
55
|
+
/**
|
56
|
+
|
57
|
+
* Returns the "real" active element in the document, resolving through
|
58
|
+
* Shadow DOM and slot boundaries when necessary.
|
59
|
+
*
|
60
|
+
* In some cases `document.activeElement` may not reflect the actual
|
61
|
+
* tabbable node that has focus:
|
62
|
+
* - If focus is inside a shadow root, `document.activeElement` is the host,
|
63
|
+
* not the element inside. This utility dives into the shadowRoot to find
|
64
|
+
* the inner active element.
|
65
|
+
* - If focus is on a `<slot>` element, this function resolves to the first
|
66
|
+
* tabbable assigned element within the slot.
|
67
|
+
*/
|
68
|
+
const getRealActiveElement = () => {
|
69
|
+
var _a;
|
70
|
+
let activeElement = document.activeElement;
|
71
|
+
// If inside shadow DOM
|
72
|
+
if (activeElement &&
|
73
|
+
selectorTabbable$1.indexOf(activeElement.tagName.toLocaleLowerCase()) ==
|
74
|
+
-1 &&
|
75
|
+
((_a = activeElement === null || activeElement === void 0 ? void 0 : activeElement.shadowRoot) === null || _a === void 0 ? void 0 : _a.activeElement)) {
|
76
|
+
activeElement = activeElement.shadowRoot.activeElement;
|
77
|
+
}
|
78
|
+
// If active element is a slot
|
79
|
+
if ((activeElement === null || activeElement === void 0 ? void 0 : activeElement.tagName) === 'SLOT') {
|
80
|
+
let assigned;
|
81
|
+
if (activeElement instanceof HTMLSlotElement) {
|
82
|
+
assigned = activeElement.assignedElements({ flatten: true });
|
83
|
+
}
|
84
|
+
const candidate = assigned === null || assigned === void 0 ? void 0 : assigned.find((node) => node.matches('button, [tabindex]:not([tabindex="-1"])'));
|
85
|
+
if (candidate) {
|
86
|
+
activeElement = candidate;
|
87
|
+
}
|
88
|
+
}
|
89
|
+
return activeElement;
|
90
|
+
};
|
91
|
+
//Optionally focus first element immediately
|
92
|
+
requestAnimationFrame(() => {
|
93
|
+
var _a;
|
94
|
+
const elements = getAllFocusableElements(_containers);
|
95
|
+
(_a = getFocusTarget(elements[0])) === null || _a === void 0 ? void 0 : _a.focus({ preventScroll: true });
|
96
|
+
});
|
97
|
+
function onKeyDown(e) {
|
98
|
+
var _a, _b;
|
99
|
+
if (e.key !== 'Tab') {
|
100
|
+
return;
|
101
|
+
}
|
102
|
+
// Flatten all focusable elements from all containers
|
103
|
+
const elements = getAllFocusableElements(_containers);
|
104
|
+
const first = elements[0];
|
105
|
+
const last = elements[elements.length - 1];
|
106
|
+
const active = getRealActiveElement();
|
107
|
+
if (e.shiftKey) {
|
108
|
+
// Shift+Tab wrap
|
109
|
+
if (active === first || first.contains(active)) {
|
110
|
+
e.preventDefault();
|
111
|
+
(_a = getFocusTarget(last)) === null || _a === void 0 ? void 0 : _a.focus();
|
112
|
+
}
|
113
|
+
}
|
114
|
+
else {
|
115
|
+
// Tab wrap
|
116
|
+
if (active === last || last.contains(active)) {
|
117
|
+
e.preventDefault();
|
118
|
+
(_b = getFocusTarget(first)) === null || _b === void 0 ? void 0 : _b.focus();
|
119
|
+
}
|
120
|
+
}
|
121
|
+
}
|
122
|
+
/**
|
123
|
+
* Retrieves all focusable elements within the provided containers.
|
124
|
+
**/
|
125
|
+
const getAllFocusableElements = (containers) => containers
|
126
|
+
.flatMap((container) => [...container.querySelectorAll(selectorTabbable$1)])
|
127
|
+
.filter(Boolean);
|
128
|
+
document.addEventListener('keydown', onKeyDown, true);
|
129
|
+
return {
|
130
|
+
cleanup: () => {
|
131
|
+
document.removeEventListener('keydown', onKeyDown, true);
|
132
|
+
_containers.length = 0;
|
133
|
+
},
|
134
|
+
};
|
135
|
+
};
|
136
|
+
|
137
|
+
export { clearFocusableContainers, registerFocusableContainers, trapFocus };
|
138
|
+
//# sourceMappingURL=manageFocusTrap.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"manageFocusTrap.js","sources":["../../../src/utilities/manageFocusTrap/manageFocusTrap.ts"],"sourcesContent":[null],"names":["selectorTabbable","selectorTabbableCarbon","carbonPrefix"],"mappings":";;;;;;;;;AAAA;;;;;;;AAOG;AAMH;;;;AAIG;AACH,IAAI,WAAW,GAAkB,EAAE;AAEtB,MAAA,2BAA2B,GAAG,CAAC,SAAS,KAAI;IACvD,IAAI,SAAS,EAAE;AACb,QAAA,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC;;AAE/B;AACO,MAAM,wBAAwB,GAAG,MAAK;AAC3C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