@react-aria/menu 3.11.3-nightly.4318 → 3.11.3-nightly.4324
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/dist/import.mjs +321 -72
- package/dist/main.js +318 -68
- package/dist/main.js.map +1 -1
- package/dist/module.js +321 -72
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +44 -4
- package/dist/types.d.ts.map +1 -1
- package/package.json +14 -14
- package/src/index.ts +2 -0
- package/src/useMenu.ts +5 -5
- package/src/useMenuItem.ts +61 -82
- package/src/useSafelyMouseToSubmenu.ts +158 -0
- package/src/useSubmenuTrigger.ts +235 -0
package/dist/import.mjs
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import {useId as $1Hnir$useId, filterDOMProps as $1Hnir$filterDOMProps, mergeProps as $1Hnir$mergeProps,
|
|
1
|
+
import {useId as $1Hnir$useId, filterDOMProps as $1Hnir$filterDOMProps, mergeProps as $1Hnir$mergeProps, useRouter as $1Hnir$useRouter, useSlotId as $1Hnir$useSlotId, useEffectEvent as $1Hnir$useEffectEvent, useLayoutEffect as $1Hnir$useLayoutEffect, useResizeObserver as $1Hnir$useResizeObserver} from "@react-aria/utils";
|
|
2
2
|
import {useLocalizedStringFormatter as $1Hnir$useLocalizedStringFormatter, useLocale as $1Hnir$useLocale} from "@react-aria/i18n";
|
|
3
|
-
import {useLongPress as $1Hnir$useLongPress, usePress as $1Hnir$usePress, useHover as $1Hnir$useHover, isFocusVisible as $1Hnir$isFocusVisible, useKeyboard as $1Hnir$useKeyboard} from "@react-aria/interactions";
|
|
3
|
+
import {useLongPress as $1Hnir$useLongPress, usePress as $1Hnir$usePress, useHover as $1Hnir$useHover, isFocusVisible as $1Hnir$isFocusVisible, useKeyboard as $1Hnir$useKeyboard, useFocus as $1Hnir$useFocus, useInteractionModality as $1Hnir$useInteractionModality} from "@react-aria/interactions";
|
|
4
4
|
import {useOverlayTrigger as $1Hnir$useOverlayTrigger} from "@react-aria/overlays";
|
|
5
5
|
import {useSelectableList as $1Hnir$useSelectableList, useSelectableItem as $1Hnir$useSelectableItem} from "@react-aria/selection";
|
|
6
|
-
import {focusSafely as $1Hnir$focusSafely} from "@react-aria/focus";
|
|
7
6
|
import {getItemCount as $1Hnir$getItemCount} from "@react-stately/collections";
|
|
8
|
-
import {useRef as $1Hnir$useRef, useCallback as $1Hnir$useCallback} from "react";
|
|
7
|
+
import {useRef as $1Hnir$useRef, useCallback as $1Hnir$useCallback, useState as $1Hnir$useState, useEffect as $1Hnir$useEffect} from "react";
|
|
9
8
|
|
|
10
9
|
|
|
11
10
|
function $parcel$interopDefault(a) {
|
|
@@ -363,7 +362,7 @@ function $168583247155ddda$export$dc9c12ed27dd1b49(props, state, ref) {
|
|
|
363
362
|
|
|
364
363
|
const $d5336fe17ce95402$export$6f49b4016bfc8d56 = new WeakMap();
|
|
365
364
|
function $d5336fe17ce95402$export$38eaa17faae8f579(props, state, ref) {
|
|
366
|
-
let { shouldFocusWrap: shouldFocusWrap = true, ...otherProps } = props;
|
|
365
|
+
let { shouldFocusWrap: shouldFocusWrap = true, onKeyDown: onKeyDown, onKeyUp: onKeyUp, ...otherProps } = props;
|
|
367
366
|
if (!props["aria-label"] && !props["aria-labelledby"]) console.warn("An aria-label or aria-labelledby prop is required for accessibility.");
|
|
368
367
|
let domProps = (0, $1Hnir$filterDOMProps)(props, {
|
|
369
368
|
labelable: true
|
|
@@ -383,9 +382,10 @@ function $d5336fe17ce95402$export$38eaa17faae8f579(props, state, ref) {
|
|
|
383
382
|
});
|
|
384
383
|
return {
|
|
385
384
|
menuProps: (0, $1Hnir$mergeProps)(domProps, {
|
|
385
|
+
onKeyDown: onKeyDown,
|
|
386
|
+
onKeyUp: onKeyUp
|
|
387
|
+
}, {
|
|
386
388
|
role: "menu",
|
|
387
|
-
// this forces AT to move their cursors into any open sub dialogs, the sub dialogs contain hidden close buttons in order to come back to this level of the menu
|
|
388
|
-
"aria-hidden": state.expandedKeys.size > 0 ? true : undefined,
|
|
389
389
|
...listProps,
|
|
390
390
|
onKeyDown: (e)=>{
|
|
391
391
|
// don't clear the menu selected keys if the user is presses escape since escape closes the menu
|
|
@@ -411,55 +411,27 @@ function $d5336fe17ce95402$export$38eaa17faae8f579(props, state, ref) {
|
|
|
411
411
|
|
|
412
412
|
|
|
413
413
|
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
414
|
function $a2e5df62f93c7633$export$9d32628fc2aea7da(props, state, ref) {
|
|
418
415
|
var _item_props;
|
|
419
|
-
let { key: key, closeOnSelect: closeOnSelect, isVirtualized: isVirtualized, "aria-haspopup": hasPopup } = props;
|
|
420
|
-
let { direction: direction } = (0, $1Hnir$useLocale)();
|
|
416
|
+
let { key: key, closeOnSelect: closeOnSelect, isVirtualized: isVirtualized, "aria-haspopup": hasPopup, onPressStart: pressStartProp, onPressUp: pressUpProp, onPress: onPress, onPressChange: onPressChange, onPressEnd: onPressEnd, onHoverStart: hoverStartProp, onHoverChange: onHoverChange, onHoverEnd: onHoverEnd, onKeyDown: onKeyDown, onKeyUp: onKeyUp, onFocus: onFocus, onFocusChange: onFocusChange, onBlur: onBlur } = props;
|
|
421
417
|
let isTrigger = !!hasPopup;
|
|
422
|
-
let isOpen = state.expandedKeys.has(key);
|
|
423
418
|
var _props_isDisabled;
|
|
424
419
|
let isDisabled = (_props_isDisabled = props.isDisabled) !== null && _props_isDisabled !== void 0 ? _props_isDisabled : state.disabledKeys.has(key);
|
|
425
420
|
var _props_isSelected;
|
|
426
421
|
let isSelected = (_props_isSelected = props.isSelected) !== null && _props_isSelected !== void 0 ? _props_isSelected : state.selectionManager.isSelected(key);
|
|
427
|
-
let openTimeout = (0, $1Hnir$useRef)();
|
|
428
|
-
let cancelOpenTimeout = (0, $1Hnir$useCallback)(()=>{
|
|
429
|
-
if (openTimeout.current) {
|
|
430
|
-
clearTimeout(openTimeout.current);
|
|
431
|
-
openTimeout.current = undefined;
|
|
432
|
-
}
|
|
433
|
-
}, [
|
|
434
|
-
openTimeout
|
|
435
|
-
]);
|
|
436
|
-
let onSubmenuOpen = (0, $1Hnir$useEffectEvent)(()=>{
|
|
437
|
-
cancelOpenTimeout();
|
|
438
|
-
state.setExpandedKeys(new Set([
|
|
439
|
-
key
|
|
440
|
-
]));
|
|
441
|
-
});
|
|
442
|
-
(0, $1Hnir$useLayoutEffect)(()=>{
|
|
443
|
-
return ()=>cancelOpenTimeout();
|
|
444
|
-
}, [
|
|
445
|
-
cancelOpenTimeout
|
|
446
|
-
]);
|
|
447
422
|
let data = (0, $d5336fe17ce95402$export$6f49b4016bfc8d56).get(state);
|
|
448
423
|
let onClose = props.onClose || data.onClose;
|
|
449
|
-
let
|
|
450
|
-
onSubmenuOpen();
|
|
451
|
-
// will need to disable this lint rule when using useEffectEvent https://react.dev/learn/separating-events-from-effects#logic-inside-effects-is-reactive
|
|
452
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
453
|
-
}, []);
|
|
454
|
-
let onAction = isTrigger ? onActionMenuDialogTrigger : props.onAction || data.onAction;
|
|
424
|
+
let onAction = isTrigger ? ()=>{} : props.onAction || data.onAction;
|
|
455
425
|
let router = (0, $1Hnir$useRouter)();
|
|
456
426
|
let performAction = (e)=>{
|
|
457
427
|
if (onAction) onAction(key);
|
|
458
428
|
if (e.target instanceof HTMLAnchorElement) router.open(e.target, e);
|
|
459
429
|
};
|
|
460
430
|
let role = "menuitem";
|
|
461
|
-
if (
|
|
462
|
-
|
|
431
|
+
if (!isTrigger) {
|
|
432
|
+
if (state.selectionManager.selectionMode === "single") role = "menuitemradio";
|
|
433
|
+
else if (state.selectionManager.selectionMode === "multiple") role = "menuitemcheckbox";
|
|
434
|
+
}
|
|
463
435
|
let labelId = (0, $1Hnir$useSlotId)();
|
|
464
436
|
let descriptionId = (0, $1Hnir$useSlotId)();
|
|
465
437
|
let keyboardId = (0, $1Hnir$useSlotId)();
|
|
@@ -471,20 +443,20 @@ function $a2e5df62f93c7633$export$9d32628fc2aea7da(props, state, ref) {
|
|
|
471
443
|
"aria-describedby": [
|
|
472
444
|
descriptionId,
|
|
473
445
|
keyboardId
|
|
474
|
-
].filter(Boolean).join(" ") || undefined
|
|
446
|
+
].filter(Boolean).join(" ") || undefined,
|
|
447
|
+
"aria-controls": props["aria-controls"],
|
|
448
|
+
"aria-haspopup": hasPopup,
|
|
449
|
+
"aria-expanded": props["aria-expanded"]
|
|
475
450
|
};
|
|
476
|
-
if (state.selectionManager.selectionMode !== "none") ariaProps["aria-checked"] = isSelected;
|
|
451
|
+
if (state.selectionManager.selectionMode !== "none" && !isTrigger) ariaProps["aria-checked"] = isSelected;
|
|
477
452
|
let item = state.collection.getItem(key);
|
|
478
453
|
if (isVirtualized) {
|
|
479
454
|
ariaProps["aria-posinset"] = item === null || item === void 0 ? void 0 : item.index;
|
|
480
455
|
ariaProps["aria-setsize"] = (0, $1Hnir$getItemCount)(state.collection);
|
|
481
456
|
}
|
|
482
|
-
if (hasPopup != null) {
|
|
483
|
-
ariaProps["aria-haspopup"] = hasPopup;
|
|
484
|
-
ariaProps["aria-expanded"] = isOpen ? "true" : "false";
|
|
485
|
-
}
|
|
486
457
|
let onPressStart = (e)=>{
|
|
487
458
|
if (e.pointerType === "keyboard") performAction(e);
|
|
459
|
+
pressStartProp === null || pressStartProp === void 0 ? void 0 : pressStartProp(e);
|
|
488
460
|
};
|
|
489
461
|
let onPressUp = (e)=>{
|
|
490
462
|
if (e.pointerType !== "keyboard") {
|
|
@@ -493,6 +465,7 @@ function $a2e5df62f93c7633$export$9d32628fc2aea7da(props, state, ref) {
|
|
|
493
465
|
// selection mode, except if overridden by the closeOnSelect prop.
|
|
494
466
|
if (!isTrigger && onClose && (closeOnSelect !== null && closeOnSelect !== void 0 ? closeOnSelect : state.selectionManager.selectionMode !== "multiple" || state.selectionManager.isLink(key))) onClose();
|
|
495
467
|
}
|
|
468
|
+
pressUpProp === null || pressUpProp === void 0 ? void 0 : pressUpProp(e);
|
|
496
469
|
};
|
|
497
470
|
let { itemProps: itemProps, isFocused: isFocused } = (0, $1Hnir$useSelectableItem)({
|
|
498
471
|
selectionManager: state.selectionManager,
|
|
@@ -508,27 +481,23 @@ function $a2e5df62f93c7633$export$9d32628fc2aea7da(props, state, ref) {
|
|
|
508
481
|
});
|
|
509
482
|
let { pressProps: pressProps, isPressed: isPressed } = (0, $1Hnir$usePress)({
|
|
510
483
|
onPressStart: onPressStart,
|
|
484
|
+
onPress: onPress,
|
|
511
485
|
onPressUp: onPressUp,
|
|
512
|
-
|
|
486
|
+
onPressChange: onPressChange,
|
|
487
|
+
onPressEnd: onPressEnd,
|
|
488
|
+
isDisabled: isDisabled
|
|
513
489
|
});
|
|
514
490
|
let { hoverProps: hoverProps } = (0, $1Hnir$useHover)({
|
|
515
491
|
isDisabled: isDisabled,
|
|
516
|
-
onHoverStart () {
|
|
517
|
-
if (!(0, $1Hnir$isFocusVisible)()
|
|
492
|
+
onHoverStart (e) {
|
|
493
|
+
if (!(0, $1Hnir$isFocusVisible)()) {
|
|
518
494
|
state.selectionManager.setFocused(true);
|
|
519
495
|
state.selectionManager.setFocusedKey(key);
|
|
520
|
-
// focus immediately so that a focus scope opened on hover has the correct restore node
|
|
521
|
-
let isFocused = key === state.selectionManager.focusedKey;
|
|
522
|
-
if (isFocused && state.selectionManager.isFocused && document.activeElement !== ref.current) (0, $1Hnir$focusSafely)(ref.current);
|
|
523
496
|
}
|
|
497
|
+
hoverStartProp === null || hoverStartProp === void 0 ? void 0 : hoverStartProp(e);
|
|
524
498
|
},
|
|
525
|
-
onHoverChange:
|
|
526
|
-
|
|
527
|
-
if (!openTimeout.current) openTimeout.current = setTimeout(()=>{
|
|
528
|
-
onSubmenuOpen();
|
|
529
|
-
}, 200);
|
|
530
|
-
} else if (!isHovered) cancelOpenTimeout();
|
|
531
|
-
}
|
|
499
|
+
onHoverChange: onHoverChange,
|
|
500
|
+
onHoverEnd: onHoverEnd
|
|
532
501
|
});
|
|
533
502
|
let { keyboardProps: keyboardProps } = (0, $1Hnir$useKeyboard)({
|
|
534
503
|
onKeyDown: (e)=>{
|
|
@@ -546,19 +515,18 @@ function $a2e5df62f93c7633$export$9d32628fc2aea7da(props, state, ref) {
|
|
|
546
515
|
// The Enter key should always close on select, except if overridden.
|
|
547
516
|
if (!isDisabled && closeOnSelect !== false && !isTrigger && onClose) onClose();
|
|
548
517
|
break;
|
|
549
|
-
case "ArrowRight":
|
|
550
|
-
if (isTrigger && direction === "ltr") onSubmenuOpen();
|
|
551
|
-
else e.continuePropagation();
|
|
552
|
-
break;
|
|
553
|
-
case "ArrowLeft":
|
|
554
|
-
if (isTrigger && direction === "rtl") onSubmenuOpen();
|
|
555
|
-
else e.continuePropagation();
|
|
556
|
-
break;
|
|
557
518
|
default:
|
|
558
|
-
e.continuePropagation();
|
|
519
|
+
if (!isTrigger) e.continuePropagation();
|
|
520
|
+
onKeyDown === null || onKeyDown === void 0 ? void 0 : onKeyDown(e);
|
|
559
521
|
break;
|
|
560
522
|
}
|
|
561
|
-
}
|
|
523
|
+
},
|
|
524
|
+
onKeyUp: onKeyUp
|
|
525
|
+
});
|
|
526
|
+
let { focusProps: focusProps } = (0, $1Hnir$useFocus)({
|
|
527
|
+
onBlur: onBlur,
|
|
528
|
+
onFocus: onFocus,
|
|
529
|
+
onFocusChange: onFocusChange
|
|
562
530
|
});
|
|
563
531
|
let domProps = (0, $1Hnir$filterDOMProps)(item.props, {
|
|
564
532
|
isLink: !!(item === null || item === void 0 ? void 0 : (_item_props = item.props) === null || _item_props === void 0 ? void 0 : _item_props.href)
|
|
@@ -567,7 +535,10 @@ function $a2e5df62f93c7633$export$9d32628fc2aea7da(props, state, ref) {
|
|
|
567
535
|
return {
|
|
568
536
|
menuItemProps: {
|
|
569
537
|
...ariaProps,
|
|
570
|
-
...(0, $1Hnir$mergeProps)(domProps,
|
|
538
|
+
...(0, $1Hnir$mergeProps)(domProps, isTrigger ? {
|
|
539
|
+
onFocus: itemProps.onFocus
|
|
540
|
+
} : itemProps, pressProps, hoverProps, keyboardProps, focusProps),
|
|
541
|
+
tabIndex: itemProps.tabIndex != null ? -1 : undefined
|
|
571
542
|
},
|
|
572
543
|
labelProps: {
|
|
573
544
|
id: labelId
|
|
@@ -620,7 +591,285 @@ function $3e5eb2498db5b506$export$73f7a44322579622(props) {
|
|
|
620
591
|
}
|
|
621
592
|
|
|
622
593
|
|
|
594
|
+
/*
|
|
595
|
+
* Copyright 2023 Adobe. All rights reserved.
|
|
596
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
597
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
598
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
599
|
+
*
|
|
600
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
601
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
602
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
603
|
+
* governing permissions and limitations under the License.
|
|
604
|
+
*/
|
|
605
|
+
|
|
606
|
+
|
|
607
|
+
|
|
608
|
+
|
|
609
|
+
|
|
610
|
+
const $d275435c250248f8$var$ALLOWED_INVALID_MOVEMENTS = 2;
|
|
611
|
+
const $d275435c250248f8$var$THROTTLE_TIME = 50;
|
|
612
|
+
const $d275435c250248f8$var$TIMEOUT_TIME = 1000;
|
|
613
|
+
const $d275435c250248f8$var$ANGLE_PADDING = Math.PI / 12; // 15°
|
|
614
|
+
function $d275435c250248f8$export$85ec83e04c95f50a(options) {
|
|
615
|
+
let { menuRef: menuRef, submenuRef: submenuRef, isOpen: isOpen, isDisabled: isDisabled } = options;
|
|
616
|
+
let prevPointerPos = (0, $1Hnir$useRef)();
|
|
617
|
+
let submenuRect = (0, $1Hnir$useRef)();
|
|
618
|
+
let lastProcessedTime = (0, $1Hnir$useRef)(0);
|
|
619
|
+
let timeout = (0, $1Hnir$useRef)();
|
|
620
|
+
let autoCloseTimeout = (0, $1Hnir$useRef)();
|
|
621
|
+
let submenuSide = (0, $1Hnir$useRef)();
|
|
622
|
+
let movementsTowardsSubmenuCount = (0, $1Hnir$useRef)(2);
|
|
623
|
+
let [preventPointerEvents, setPreventPointerEvents] = (0, $1Hnir$useState)(false);
|
|
624
|
+
let updateSubmenuRect = ()=>{
|
|
625
|
+
if (submenuRef.current) {
|
|
626
|
+
submenuRect.current = submenuRef.current.getBoundingClientRect();
|
|
627
|
+
submenuSide.current = undefined;
|
|
628
|
+
}
|
|
629
|
+
};
|
|
630
|
+
(0, $1Hnir$useResizeObserver)({
|
|
631
|
+
ref: submenuRef,
|
|
632
|
+
onResize: updateSubmenuRect
|
|
633
|
+
});
|
|
634
|
+
let reset = ()=>{
|
|
635
|
+
setPreventPointerEvents(false);
|
|
636
|
+
movementsTowardsSubmenuCount.current = $d275435c250248f8$var$ALLOWED_INVALID_MOVEMENTS;
|
|
637
|
+
};
|
|
638
|
+
let modality = (0, $1Hnir$useInteractionModality)();
|
|
639
|
+
(0, $1Hnir$useEffect)(()=>{
|
|
640
|
+
if (preventPointerEvents && menuRef.current) menuRef.current.style.pointerEvents = "none";
|
|
641
|
+
else menuRef.current.style.pointerEvents = "";
|
|
642
|
+
}, [
|
|
643
|
+
menuRef,
|
|
644
|
+
preventPointerEvents
|
|
645
|
+
]);
|
|
646
|
+
(0, $1Hnir$useEffect)(()=>{
|
|
647
|
+
let submenu = submenuRef.current;
|
|
648
|
+
let menu = menuRef.current;
|
|
649
|
+
if (isDisabled || !submenu || !isOpen || modality !== "pointer") {
|
|
650
|
+
reset();
|
|
651
|
+
return;
|
|
652
|
+
}
|
|
653
|
+
submenuRect.current = submenu.getBoundingClientRect();
|
|
654
|
+
let onPointerMove = (e)=>{
|
|
655
|
+
if (e.pointerType === "touch" || e.pointerType === "pen") return;
|
|
656
|
+
let currentTime = Date.now();
|
|
657
|
+
// Throttle
|
|
658
|
+
if (currentTime - lastProcessedTime.current < $d275435c250248f8$var$THROTTLE_TIME) return;
|
|
659
|
+
clearTimeout(timeout.current);
|
|
660
|
+
clearTimeout(autoCloseTimeout.current);
|
|
661
|
+
let { clientX: mouseX, clientY: mouseY } = e;
|
|
662
|
+
if (!prevPointerPos.current) {
|
|
663
|
+
prevPointerPos.current = {
|
|
664
|
+
x: mouseX,
|
|
665
|
+
y: mouseY
|
|
666
|
+
};
|
|
667
|
+
return;
|
|
668
|
+
}
|
|
669
|
+
if (!submenuRect.current) return;
|
|
670
|
+
if (!submenuSide.current) submenuSide.current = mouseX > submenuRect.current.right ? "left" : "right";
|
|
671
|
+
// Pointer is outside of parent menu
|
|
672
|
+
if (mouseX < menu.getBoundingClientRect().left || mouseX > menu.getBoundingClientRect().right || mouseY < menu.getBoundingClientRect().top || mouseY > menu.getBoundingClientRect().bottom) {
|
|
673
|
+
reset();
|
|
674
|
+
return;
|
|
675
|
+
}
|
|
676
|
+
/* Check if pointer is moving towards submenu.
|
|
677
|
+
Uses the 2-argument arctangent (https://en.wikipedia.org/wiki/Atan2) to calculate:
|
|
678
|
+
- angle between previous pointer and top of submenu
|
|
679
|
+
- angle between previous pointer and bottom of submenu
|
|
680
|
+
- angle between previous pointer and current pointer (delta)
|
|
681
|
+
If the pointer delta angle value is between the top and bottom angle values, we know the pointer is moving towards the submenu.
|
|
682
|
+
*/ let prevMouseX = prevPointerPos.current.x;
|
|
683
|
+
let prevMouseY = prevPointerPos.current.y;
|
|
684
|
+
let toSubmenuX = submenuSide.current === "right" ? submenuRect.current.left - prevMouseX : prevMouseX - submenuRect.current.right;
|
|
685
|
+
let angleTop = Math.atan2(prevMouseY - submenuRect.current.top, toSubmenuX) + $d275435c250248f8$var$ANGLE_PADDING;
|
|
686
|
+
let angleBottom = Math.atan2(prevMouseY - submenuRect.current.bottom, toSubmenuX) - $d275435c250248f8$var$ANGLE_PADDING;
|
|
687
|
+
let anglePointer = Math.atan2(prevMouseY - mouseY, submenuSide.current === "left" ? -(mouseX - prevMouseX) : mouseX - prevMouseX);
|
|
688
|
+
let isMovingTowardsSubmenu = anglePointer < angleTop && anglePointer > angleBottom;
|
|
689
|
+
movementsTowardsSubmenuCount.current = isMovingTowardsSubmenu ? Math.min(movementsTowardsSubmenuCount.current + 1, $d275435c250248f8$var$ALLOWED_INVALID_MOVEMENTS) : Math.max(movementsTowardsSubmenuCount.current - 1, 0);
|
|
690
|
+
if (movementsTowardsSubmenuCount.current >= $d275435c250248f8$var$ALLOWED_INVALID_MOVEMENTS) setPreventPointerEvents(true);
|
|
691
|
+
else setPreventPointerEvents(false);
|
|
692
|
+
lastProcessedTime.current = currentTime;
|
|
693
|
+
prevPointerPos.current = {
|
|
694
|
+
x: mouseX,
|
|
695
|
+
y: mouseY
|
|
696
|
+
};
|
|
697
|
+
// If the pointer is moving towards the submenu, start a timeout to close if no other movements are made after 500ms.
|
|
698
|
+
if (isMovingTowardsSubmenu) timeout.current = setTimeout(()=>{
|
|
699
|
+
reset();
|
|
700
|
+
autoCloseTimeout.current = setTimeout(()=>{
|
|
701
|
+
// Fire a pointerover event to trigger the menu to close.
|
|
702
|
+
// Wait until pointer-events:none is no longer applied
|
|
703
|
+
let target = document.elementFromPoint(mouseX, mouseY);
|
|
704
|
+
if (target && menu.contains(target)) target.dispatchEvent(new PointerEvent("pointerover", {
|
|
705
|
+
bubbles: true,
|
|
706
|
+
cancelable: true
|
|
707
|
+
}));
|
|
708
|
+
}, 100);
|
|
709
|
+
}, $d275435c250248f8$var$TIMEOUT_TIME);
|
|
710
|
+
};
|
|
711
|
+
window.addEventListener("pointermove", onPointerMove);
|
|
712
|
+
return ()=>{
|
|
713
|
+
window.removeEventListener("pointermove", onPointerMove);
|
|
714
|
+
clearTimeout(timeout.current);
|
|
715
|
+
clearTimeout(autoCloseTimeout.current);
|
|
716
|
+
movementsTowardsSubmenuCount.current = $d275435c250248f8$var$ALLOWED_INVALID_MOVEMENTS;
|
|
717
|
+
};
|
|
718
|
+
}, [
|
|
719
|
+
isDisabled,
|
|
720
|
+
isOpen,
|
|
721
|
+
menuRef,
|
|
722
|
+
modality,
|
|
723
|
+
setPreventPointerEvents,
|
|
724
|
+
submenuRef
|
|
725
|
+
]);
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
|
|
729
|
+
function $0065b146e7192841$export$3819f8ee9f4ce664(props, state, ref) {
|
|
730
|
+
let { parentMenuRef: parentMenuRef, submenuRef: submenuRef, type: type = "menu", isDisabled: isDisabled, node: node } = props;
|
|
731
|
+
let submenuTriggerId = (0, $1Hnir$useId)();
|
|
732
|
+
let overlayId = (0, $1Hnir$useId)();
|
|
733
|
+
let { direction: direction } = (0, $1Hnir$useLocale)();
|
|
734
|
+
let openTimeout = (0, $1Hnir$useRef)();
|
|
735
|
+
let cancelOpenTimeout = (0, $1Hnir$useCallback)(()=>{
|
|
736
|
+
if (openTimeout.current) {
|
|
737
|
+
clearTimeout(openTimeout.current);
|
|
738
|
+
openTimeout.current = undefined;
|
|
739
|
+
}
|
|
740
|
+
}, [
|
|
741
|
+
openTimeout
|
|
742
|
+
]);
|
|
743
|
+
let onSubmenuOpen = (0, $1Hnir$useEffectEvent)((focusStrategy)=>{
|
|
744
|
+
cancelOpenTimeout();
|
|
745
|
+
state.open(focusStrategy);
|
|
746
|
+
});
|
|
747
|
+
let onSubmenuClose = (0, $1Hnir$useEffectEvent)(()=>{
|
|
748
|
+
cancelOpenTimeout();
|
|
749
|
+
state.close();
|
|
750
|
+
});
|
|
751
|
+
(0, $1Hnir$useLayoutEffect)(()=>{
|
|
752
|
+
return ()=>{
|
|
753
|
+
cancelOpenTimeout();
|
|
754
|
+
};
|
|
755
|
+
}, [
|
|
756
|
+
cancelOpenTimeout
|
|
757
|
+
]);
|
|
758
|
+
let submenuKeyDown = (e)=>{
|
|
759
|
+
switch(e.key){
|
|
760
|
+
case "ArrowLeft":
|
|
761
|
+
if (direction === "ltr" && e.currentTarget.contains(e.target)) {
|
|
762
|
+
e.stopPropagation();
|
|
763
|
+
onSubmenuClose();
|
|
764
|
+
ref.current.focus();
|
|
765
|
+
}
|
|
766
|
+
break;
|
|
767
|
+
case "ArrowRight":
|
|
768
|
+
if (direction === "rtl" && e.currentTarget.contains(e.target)) {
|
|
769
|
+
e.stopPropagation();
|
|
770
|
+
onSubmenuClose();
|
|
771
|
+
ref.current.focus();
|
|
772
|
+
}
|
|
773
|
+
break;
|
|
774
|
+
case "Escape":
|
|
775
|
+
e.stopPropagation();
|
|
776
|
+
state.closeAll();
|
|
777
|
+
break;
|
|
778
|
+
}
|
|
779
|
+
};
|
|
780
|
+
let submenuProps = {
|
|
781
|
+
id: overlayId,
|
|
782
|
+
"aria-label": node.textValue,
|
|
783
|
+
submenuLevel: state.submenuLevel,
|
|
784
|
+
...type === "menu" && {
|
|
785
|
+
onClose: state.closeAll,
|
|
786
|
+
autoFocus: state.focusStrategy,
|
|
787
|
+
onKeyDown: submenuKeyDown
|
|
788
|
+
}
|
|
789
|
+
};
|
|
790
|
+
let submenuTriggerKeyDown = (e)=>{
|
|
791
|
+
switch(e.key){
|
|
792
|
+
case "ArrowRight":
|
|
793
|
+
if (!isDisabled) {
|
|
794
|
+
if (direction === "ltr") {
|
|
795
|
+
if (!state.isOpen) onSubmenuOpen("first");
|
|
796
|
+
if (type === "menu" && !!(submenuRef === null || submenuRef === void 0 ? void 0 : submenuRef.current) && document.activeElement === (ref === null || ref === void 0 ? void 0 : ref.current)) submenuRef.current.focus();
|
|
797
|
+
} else if (state.isOpen) onSubmenuClose();
|
|
798
|
+
else e.continuePropagation();
|
|
799
|
+
}
|
|
800
|
+
break;
|
|
801
|
+
case "ArrowLeft":
|
|
802
|
+
if (!isDisabled) {
|
|
803
|
+
if (direction === "rtl") {
|
|
804
|
+
if (!state.isOpen) onSubmenuOpen("first");
|
|
805
|
+
if (type === "menu" && !!(submenuRef === null || submenuRef === void 0 ? void 0 : submenuRef.current) && document.activeElement === (ref === null || ref === void 0 ? void 0 : ref.current)) submenuRef.current.focus();
|
|
806
|
+
} else if (state.isOpen) onSubmenuClose();
|
|
807
|
+
else e.continuePropagation();
|
|
808
|
+
}
|
|
809
|
+
break;
|
|
810
|
+
case "Escape":
|
|
811
|
+
state.closeAll();
|
|
812
|
+
break;
|
|
813
|
+
default:
|
|
814
|
+
e.continuePropagation();
|
|
815
|
+
break;
|
|
816
|
+
}
|
|
817
|
+
};
|
|
818
|
+
let onPressStart = (e)=>{
|
|
819
|
+
if (!isDisabled && (e.pointerType === "virtual" || e.pointerType === "keyboard")) // If opened with a screen reader or keyboard, auto focus the first submenu item.
|
|
820
|
+
onSubmenuOpen("first");
|
|
821
|
+
};
|
|
822
|
+
let onPress = (e)=>{
|
|
823
|
+
if (!isDisabled && (e.pointerType === "touch" || e.pointerType === "mouse")) // For touch or on a desktop device with a small screen open on press up to possible problems with
|
|
824
|
+
// press up happening on the newly opened tray items
|
|
825
|
+
onSubmenuOpen();
|
|
826
|
+
};
|
|
827
|
+
let onHoverChange = (isHovered)=>{
|
|
828
|
+
if (!isDisabled) {
|
|
829
|
+
if (isHovered && !state.isOpen) {
|
|
830
|
+
if (!openTimeout.current) openTimeout.current = setTimeout(()=>{
|
|
831
|
+
onSubmenuOpen();
|
|
832
|
+
}, 200);
|
|
833
|
+
} else if (!isHovered) cancelOpenTimeout();
|
|
834
|
+
}
|
|
835
|
+
};
|
|
836
|
+
let onBlur = (e)=>{
|
|
837
|
+
if (state.isOpen && parentMenuRef.current.contains(e.relatedTarget)) onSubmenuClose();
|
|
838
|
+
};
|
|
839
|
+
let shouldCloseOnInteractOutside = (target)=>{
|
|
840
|
+
if (target !== ref.current) return true;
|
|
841
|
+
return false;
|
|
842
|
+
};
|
|
843
|
+
(0, $d275435c250248f8$export$85ec83e04c95f50a)({
|
|
844
|
+
menuRef: parentMenuRef,
|
|
845
|
+
submenuRef: submenuRef,
|
|
846
|
+
isOpen: state.isOpen,
|
|
847
|
+
isDisabled: isDisabled
|
|
848
|
+
});
|
|
849
|
+
return {
|
|
850
|
+
submenuTriggerProps: {
|
|
851
|
+
id: submenuTriggerId,
|
|
852
|
+
"aria-controls": state.isOpen ? overlayId : undefined,
|
|
853
|
+
"aria-haspopup": !isDisabled ? type : undefined,
|
|
854
|
+
"aria-expanded": state.isOpen ? "true" : "false",
|
|
855
|
+
onPressStart: onPressStart,
|
|
856
|
+
onPress: onPress,
|
|
857
|
+
onHoverChange: onHoverChange,
|
|
858
|
+
onKeyDown: submenuTriggerKeyDown,
|
|
859
|
+
onBlur: onBlur,
|
|
860
|
+
isOpen: state.isOpen
|
|
861
|
+
},
|
|
862
|
+
submenuProps: submenuProps,
|
|
863
|
+
popoverProps: {
|
|
864
|
+
isNonModal: true,
|
|
865
|
+
disableFocusManagement: true,
|
|
866
|
+
shouldCloseOnInteractOutside: shouldCloseOnInteractOutside
|
|
867
|
+
}
|
|
868
|
+
};
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
|
|
623
872
|
|
|
624
873
|
|
|
625
|
-
export {$168583247155ddda$export$dc9c12ed27dd1b49 as useMenuTrigger, $d5336fe17ce95402$export$38eaa17faae8f579 as useMenu, $a2e5df62f93c7633$export$9d32628fc2aea7da as useMenuItem, $3e5eb2498db5b506$export$73f7a44322579622 as useMenuSection};
|
|
874
|
+
export {$168583247155ddda$export$dc9c12ed27dd1b49 as useMenuTrigger, $d5336fe17ce95402$export$38eaa17faae8f579 as useMenu, $a2e5df62f93c7633$export$9d32628fc2aea7da as useMenuItem, $3e5eb2498db5b506$export$73f7a44322579622 as useMenuSection, $0065b146e7192841$export$3819f8ee9f4ce664 as UNSTABLE_useSubmenuTrigger};
|
|
626
875
|
//# sourceMappingURL=module.js.map
|