@lumx/react 4.30.0-next.5 → 4.30.1-next.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/index.js +81 -35
- package/index.js.map +1 -1
- package/package.json +5 -5
package/index.js
CHANGED
|
@@ -8541,6 +8541,20 @@ const ListboxOptionMoreInfo$1 = (props, {
|
|
|
8541
8541
|
});
|
|
8542
8542
|
};
|
|
8543
8543
|
|
|
8544
|
+
/**
|
|
8545
|
+
* Get the focused element, also inside open shadow roots.
|
|
8546
|
+
* (The `activeElement` of a document or a shadow root is the shadow host when the focus is in its shadow root.)
|
|
8547
|
+
*/
|
|
8548
|
+
function getDeepActiveElement(root) {
|
|
8549
|
+
let {
|
|
8550
|
+
activeElement
|
|
8551
|
+
} = root;
|
|
8552
|
+
while (activeElement?.shadowRoot?.activeElement) {
|
|
8553
|
+
activeElement = activeElement.shadowRoot.activeElement;
|
|
8554
|
+
}
|
|
8555
|
+
return activeElement;
|
|
8556
|
+
}
|
|
8557
|
+
|
|
8544
8558
|
/** CSS selector listing all tabbable elements. */
|
|
8545
8559
|
const TABBABLE_ELEMENTS_SELECTOR = 'a[href], button, textarea, input:not([type="hidden"]):not([hidden]), [tabindex]';
|
|
8546
8560
|
|
|
@@ -8553,9 +8567,47 @@ const TABBABLE_ELEMENTS_SELECTOR = 'a[href], button, textarea, input:not([type="
|
|
|
8553
8567
|
*/
|
|
8554
8568
|
const DISABLED_SELECTOR = '[hidden], [tabindex="-1"], [disabled]:not([disabled="false"])';
|
|
8555
8569
|
|
|
8556
|
-
|
|
8557
|
-
|
|
8558
|
-
|
|
8570
|
+
/** CSS selector matching containers whose descendants can not get the focus. */
|
|
8571
|
+
const UNFOCUSABLE_SUBTREE_SELECTOR = '[hidden], [inert]';
|
|
8572
|
+
|
|
8573
|
+
const isFocusable = element => element.matches(TABBABLE_ELEMENTS_SELECTOR) && !element.matches(DISABLED_SELECTOR);
|
|
8574
|
+
|
|
8575
|
+
/** Yield the rendered children of a node: the content of an open shadow root or of a slot replaces the light DOM. */
|
|
8576
|
+
function* composedChildren(node, reverse) {
|
|
8577
|
+
if (node instanceof Element && node.shadowRoot) {
|
|
8578
|
+
yield* composedChildren(node.shadowRoot, reverse);
|
|
8579
|
+
return;
|
|
8580
|
+
}
|
|
8581
|
+
if (node instanceof HTMLSlotElement) {
|
|
8582
|
+
const assigned = node.assignedElements({
|
|
8583
|
+
flatten: true
|
|
8584
|
+
});
|
|
8585
|
+
if (assigned.length) {
|
|
8586
|
+
yield* reverse ? assigned.reverse() : assigned;
|
|
8587
|
+
return;
|
|
8588
|
+
}
|
|
8589
|
+
}
|
|
8590
|
+
let child = reverse ? node.lastElementChild : node.firstElementChild;
|
|
8591
|
+
while (child) {
|
|
8592
|
+
yield child;
|
|
8593
|
+
child = reverse ? child.previousElementSibling : child.nextElementSibling;
|
|
8594
|
+
}
|
|
8595
|
+
}
|
|
8596
|
+
|
|
8597
|
+
/** Yield the focusable elements in the composed tree order (open shadow roots included), or in the reverse order. */
|
|
8598
|
+
function* focusableElements(node, reverse = false) {
|
|
8599
|
+
for (const child of composedChildren(node, reverse)) {
|
|
8600
|
+
if (child.matches(UNFOCUSABLE_SUBTREE_SELECTOR)) continue;
|
|
8601
|
+
// A host comes before its content in the composed tree order.
|
|
8602
|
+
if (!reverse && isFocusable(child)) yield child;
|
|
8603
|
+
yield* focusableElements(child, reverse);
|
|
8604
|
+
if (reverse && isFocusable(child)) yield child;
|
|
8605
|
+
}
|
|
8606
|
+
}
|
|
8607
|
+
|
|
8608
|
+
/** Find the first (or the last, with `reverse`) focusable element in the composed tree order, with an early stop. */
|
|
8609
|
+
function findFocusable(node, reverse = false) {
|
|
8610
|
+
return focusableElements(node, reverse).next().value || undefined;
|
|
8559
8611
|
}
|
|
8560
8612
|
|
|
8561
8613
|
/**
|
|
@@ -8565,12 +8617,10 @@ function getFocusableElements(element) {
|
|
|
8565
8617
|
* @return first and last focusable elements
|
|
8566
8618
|
*/
|
|
8567
8619
|
function getFirstAndLastFocusable(parentElement) {
|
|
8568
|
-
const focusableElements = getFocusableElements(parentElement);
|
|
8569
|
-
|
|
8570
8620
|
// First non disabled element.
|
|
8571
|
-
const first =
|
|
8621
|
+
const first = findFocusable(parentElement);
|
|
8572
8622
|
// Last non disabled element.
|
|
8573
|
-
const last =
|
|
8623
|
+
const last = first && findFocusable(parentElement, true);
|
|
8574
8624
|
if (last && first) {
|
|
8575
8625
|
return {
|
|
8576
8626
|
first,
|
|
@@ -8580,6 +8630,23 @@ function getFirstAndLastFocusable(parentElement) {
|
|
|
8580
8630
|
return {};
|
|
8581
8631
|
}
|
|
8582
8632
|
|
|
8633
|
+
/**
|
|
8634
|
+
* Check if the focus is on the given element or inside it.
|
|
8635
|
+
*
|
|
8636
|
+
* Reads the active element of the element's own root node (Document or ShadowRoot), so it also works when the
|
|
8637
|
+
* element lives in a shadow DOM.
|
|
8638
|
+
*
|
|
8639
|
+
* @param element The element to check.
|
|
8640
|
+
* @return whether the active element is the element itself or one of its descendants.
|
|
8641
|
+
*/
|
|
8642
|
+
function isFocusWithin(element) {
|
|
8643
|
+
if (!element) return false;
|
|
8644
|
+
const {
|
|
8645
|
+
activeElement
|
|
8646
|
+
} = element.getRootNode();
|
|
8647
|
+
return Boolean(activeElement && element.contains(activeElement));
|
|
8648
|
+
}
|
|
8649
|
+
|
|
8583
8650
|
/**
|
|
8584
8651
|
* Focus the zone element itself (last-resort fallback, e.g. an empty dialog).
|
|
8585
8652
|
*
|
|
@@ -8686,16 +8753,14 @@ function setupFocusTrap(options, signal) {
|
|
|
8686
8753
|
focusZoneFallback(focusZoneElement, signal);
|
|
8687
8754
|
return;
|
|
8688
8755
|
}
|
|
8689
|
-
const
|
|
8690
|
-
activeElement
|
|
8691
|
-
} = rootNode;
|
|
8756
|
+
const activeElement = getDeepActiveElement(rootNode);
|
|
8692
8757
|
if (
|
|
8693
8758
|
// No previous focus.
|
|
8694
8759
|
!activeElement ||
|
|
8695
8760
|
// Previous focus is at the end of the focus zone.
|
|
8696
8761
|
!evt.shiftKey && activeElement === focusable.last ||
|
|
8697
8762
|
// Previous focus is outside the focus zone.
|
|
8698
|
-
!focusZoneElement
|
|
8763
|
+
!isFocusWithin(focusZoneElement)) {
|
|
8699
8764
|
focusable.first.focus();
|
|
8700
8765
|
evt.preventDefault();
|
|
8701
8766
|
return;
|
|
@@ -12942,23 +13007,6 @@ const useTransitionVisibility = (ref, isComponentVisible, timeout, onVisibilityC
|
|
|
12942
13007
|
return isVisible || isComponentVisible;
|
|
12943
13008
|
};
|
|
12944
13009
|
|
|
12945
|
-
/**
|
|
12946
|
-
* Check if the focus is on the given element or inside it.
|
|
12947
|
-
*
|
|
12948
|
-
* Reads the active element of the element's own root node (Document or ShadowRoot), so it also works when the
|
|
12949
|
-
* element lives in a shadow DOM.
|
|
12950
|
-
*
|
|
12951
|
-
* @param element The element to check.
|
|
12952
|
-
* @return whether the active element is the element itself or one of its descendants.
|
|
12953
|
-
*/
|
|
12954
|
-
function isFocusWithin(element) {
|
|
12955
|
-
if (!element) return false;
|
|
12956
|
-
const {
|
|
12957
|
-
activeElement
|
|
12958
|
-
} = element.getRootNode();
|
|
12959
|
-
return Boolean(activeElement && element.contains(activeElement));
|
|
12960
|
-
}
|
|
12961
|
-
|
|
12962
13010
|
/**
|
|
12963
13011
|
* Dialog label id key in IdsRegistry
|
|
12964
13012
|
*/
|
|
@@ -21140,7 +21188,9 @@ const useSlideFocusManagement = ({
|
|
|
21140
21188
|
*/
|
|
21141
21189
|
const blockSlide = () => {
|
|
21142
21190
|
element.setAttribute('aria-hidden', 'true');
|
|
21143
|
-
|
|
21191
|
+
// Light DOM only: `enableSlide` cannot find the blocked elements inside shadow roots.
|
|
21192
|
+
element.querySelectorAll(TABBABLE_ELEMENTS_SELECTOR).forEach(focusableElement => {
|
|
21193
|
+
if (focusableElement.matches(DISABLED_SELECTOR)) return;
|
|
21144
21194
|
focusableElement.setAttribute('tabindex', '-1');
|
|
21145
21195
|
focusableElement.classList.add(BLOCKED_FOCUS_CLASSNAME);
|
|
21146
21196
|
});
|
|
@@ -21158,12 +21208,8 @@ const useSlideFocusManagement = ({
|
|
|
21158
21208
|
|
|
21159
21209
|
// Callback function to execute when mutations are observed
|
|
21160
21210
|
const callback = mutationsList => {
|
|
21161
|
-
if (element) {
|
|
21162
|
-
|
|
21163
|
-
if (mutation.type === 'childList') {
|
|
21164
|
-
handleDisplay();
|
|
21165
|
-
}
|
|
21166
|
-
}
|
|
21211
|
+
if (element && mutationsList.some(mutation => mutation.type === 'childList')) {
|
|
21212
|
+
handleDisplay();
|
|
21167
21213
|
}
|
|
21168
21214
|
};
|
|
21169
21215
|
|