@react-aria/menu 3.14.1-nightly.4624 → 3.14.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/dist/useMenu.main.js +4 -4
- package/dist/useMenu.mjs +4 -4
- package/dist/useMenu.module.js +4 -4
- package/dist/useMenuItem.main.js +23 -23
- package/dist/useMenuItem.mjs +23 -23
- package/dist/useMenuItem.module.js +23 -23
- package/dist/useMenuSection.main.js +6 -6
- package/dist/useMenuSection.mjs +6 -6
- package/dist/useMenuSection.module.js +6 -6
- package/dist/useMenuTrigger.main.js +21 -21
- package/dist/useMenuTrigger.mjs +21 -21
- package/dist/useMenuTrigger.module.js +21 -21
- package/dist/useSafelyMouseToSubmenu.main.js +10 -10
- package/dist/useSafelyMouseToSubmenu.mjs +10 -10
- package/dist/useSafelyMouseToSubmenu.module.js +10 -10
- package/dist/useSubmenuTrigger.main.js +23 -23
- package/dist/useSubmenuTrigger.mjs +23 -23
- package/dist/useSubmenuTrigger.module.js +23 -23
- package/package.json +14 -14
package/dist/useMenuTrigger.mjs
CHANGED
|
@@ -24,55 +24,55 @@ function $parcel$interopDefault(a) {
|
|
|
24
24
|
|
|
25
25
|
|
|
26
26
|
function $168583247155ddda$export$dc9c12ed27dd1b49(props, state, ref) {
|
|
27
|
-
let { type: type =
|
|
27
|
+
let { type: type = 'menu', isDisabled: isDisabled, trigger: trigger = 'press' } = props;
|
|
28
28
|
let menuTriggerId = (0, $czs6v$useId)();
|
|
29
29
|
let { triggerProps: triggerProps, overlayProps: overlayProps } = (0, $czs6v$useOverlayTrigger)({
|
|
30
30
|
type: type
|
|
31
31
|
}, state, ref);
|
|
32
32
|
let onKeyDown = (e)=>{
|
|
33
33
|
if (isDisabled) return;
|
|
34
|
-
if (trigger ===
|
|
34
|
+
if (trigger === 'longPress' && !e.altKey) return;
|
|
35
35
|
if (ref && ref.current) switch(e.key){
|
|
36
|
-
case
|
|
37
|
-
case
|
|
38
|
-
if (trigger ===
|
|
36
|
+
case 'Enter':
|
|
37
|
+
case ' ':
|
|
38
|
+
if (trigger === 'longPress') return;
|
|
39
39
|
// fallthrough
|
|
40
|
-
case
|
|
40
|
+
case 'ArrowDown':
|
|
41
41
|
// Stop propagation, unless it would already be handled by useKeyboard.
|
|
42
|
-
if (!(
|
|
42
|
+
if (!('continuePropagation' in e)) e.stopPropagation();
|
|
43
43
|
e.preventDefault();
|
|
44
|
-
state.toggle(
|
|
44
|
+
state.toggle('first');
|
|
45
45
|
break;
|
|
46
|
-
case
|
|
47
|
-
if (!(
|
|
46
|
+
case 'ArrowUp':
|
|
47
|
+
if (!('continuePropagation' in e)) e.stopPropagation();
|
|
48
48
|
e.preventDefault();
|
|
49
|
-
state.toggle(
|
|
49
|
+
state.toggle('last');
|
|
50
50
|
break;
|
|
51
51
|
default:
|
|
52
52
|
// Allow other keys.
|
|
53
|
-
if (
|
|
53
|
+
if ('continuePropagation' in e) e.continuePropagation();
|
|
54
54
|
}
|
|
55
55
|
};
|
|
56
|
-
let stringFormatter = (0, $czs6v$useLocalizedStringFormatter)((0, ($parcel$interopDefault($czs6v$intlStringsmodulejs))),
|
|
56
|
+
let stringFormatter = (0, $czs6v$useLocalizedStringFormatter)((0, ($parcel$interopDefault($czs6v$intlStringsmodulejs))), '@react-aria/menu');
|
|
57
57
|
let { longPressProps: longPressProps } = (0, $czs6v$useLongPress)({
|
|
58
|
-
isDisabled: isDisabled || trigger !==
|
|
59
|
-
accessibilityDescription: stringFormatter.format(
|
|
58
|
+
isDisabled: isDisabled || trigger !== 'longPress',
|
|
59
|
+
accessibilityDescription: stringFormatter.format('longPressMessage'),
|
|
60
60
|
onLongPressStart () {
|
|
61
61
|
state.close();
|
|
62
62
|
},
|
|
63
63
|
onLongPress () {
|
|
64
|
-
state.open(
|
|
64
|
+
state.open('first');
|
|
65
65
|
}
|
|
66
66
|
});
|
|
67
67
|
let pressProps = {
|
|
68
68
|
onPressStart (e) {
|
|
69
69
|
// For consistency with native, open the menu on mouse/key down, but touch up.
|
|
70
|
-
if (e.pointerType !==
|
|
70
|
+
if (e.pointerType !== 'touch' && e.pointerType !== 'keyboard' && !isDisabled) // If opened with a screen reader, auto focus the first item.
|
|
71
71
|
// Otherwise, the menu itself will be focused.
|
|
72
|
-
state.open(e.pointerType ===
|
|
72
|
+
state.open(e.pointerType === 'virtual' ? 'first' : null);
|
|
73
73
|
},
|
|
74
74
|
onPress (e) {
|
|
75
|
-
if (e.pointerType ===
|
|
75
|
+
if (e.pointerType === 'touch' && !isDisabled) state.toggle();
|
|
76
76
|
}
|
|
77
77
|
};
|
|
78
78
|
// omit onPress from triggerProps since we override it above.
|
|
@@ -80,13 +80,13 @@ function $168583247155ddda$export$dc9c12ed27dd1b49(props, state, ref) {
|
|
|
80
80
|
return {
|
|
81
81
|
menuTriggerProps: {
|
|
82
82
|
...triggerProps,
|
|
83
|
-
...trigger ===
|
|
83
|
+
...trigger === 'press' ? pressProps : longPressProps,
|
|
84
84
|
id: menuTriggerId,
|
|
85
85
|
onKeyDown: onKeyDown
|
|
86
86
|
},
|
|
87
87
|
menuProps: {
|
|
88
88
|
...overlayProps,
|
|
89
|
-
|
|
89
|
+
'aria-labelledby': menuTriggerId,
|
|
90
90
|
autoFocus: state.focusStrategy || true,
|
|
91
91
|
onClose: state.close
|
|
92
92
|
}
|
|
@@ -24,55 +24,55 @@ function $parcel$interopDefault(a) {
|
|
|
24
24
|
|
|
25
25
|
|
|
26
26
|
function $168583247155ddda$export$dc9c12ed27dd1b49(props, state, ref) {
|
|
27
|
-
let { type: type =
|
|
27
|
+
let { type: type = 'menu', isDisabled: isDisabled, trigger: trigger = 'press' } = props;
|
|
28
28
|
let menuTriggerId = (0, $czs6v$useId)();
|
|
29
29
|
let { triggerProps: triggerProps, overlayProps: overlayProps } = (0, $czs6v$useOverlayTrigger)({
|
|
30
30
|
type: type
|
|
31
31
|
}, state, ref);
|
|
32
32
|
let onKeyDown = (e)=>{
|
|
33
33
|
if (isDisabled) return;
|
|
34
|
-
if (trigger ===
|
|
34
|
+
if (trigger === 'longPress' && !e.altKey) return;
|
|
35
35
|
if (ref && ref.current) switch(e.key){
|
|
36
|
-
case
|
|
37
|
-
case
|
|
38
|
-
if (trigger ===
|
|
36
|
+
case 'Enter':
|
|
37
|
+
case ' ':
|
|
38
|
+
if (trigger === 'longPress') return;
|
|
39
39
|
// fallthrough
|
|
40
|
-
case
|
|
40
|
+
case 'ArrowDown':
|
|
41
41
|
// Stop propagation, unless it would already be handled by useKeyboard.
|
|
42
|
-
if (!(
|
|
42
|
+
if (!('continuePropagation' in e)) e.stopPropagation();
|
|
43
43
|
e.preventDefault();
|
|
44
|
-
state.toggle(
|
|
44
|
+
state.toggle('first');
|
|
45
45
|
break;
|
|
46
|
-
case
|
|
47
|
-
if (!(
|
|
46
|
+
case 'ArrowUp':
|
|
47
|
+
if (!('continuePropagation' in e)) e.stopPropagation();
|
|
48
48
|
e.preventDefault();
|
|
49
|
-
state.toggle(
|
|
49
|
+
state.toggle('last');
|
|
50
50
|
break;
|
|
51
51
|
default:
|
|
52
52
|
// Allow other keys.
|
|
53
|
-
if (
|
|
53
|
+
if ('continuePropagation' in e) e.continuePropagation();
|
|
54
54
|
}
|
|
55
55
|
};
|
|
56
|
-
let stringFormatter = (0, $czs6v$useLocalizedStringFormatter)((0, ($parcel$interopDefault($czs6v$intlStringsmodulejs))),
|
|
56
|
+
let stringFormatter = (0, $czs6v$useLocalizedStringFormatter)((0, ($parcel$interopDefault($czs6v$intlStringsmodulejs))), '@react-aria/menu');
|
|
57
57
|
let { longPressProps: longPressProps } = (0, $czs6v$useLongPress)({
|
|
58
|
-
isDisabled: isDisabled || trigger !==
|
|
59
|
-
accessibilityDescription: stringFormatter.format(
|
|
58
|
+
isDisabled: isDisabled || trigger !== 'longPress',
|
|
59
|
+
accessibilityDescription: stringFormatter.format('longPressMessage'),
|
|
60
60
|
onLongPressStart () {
|
|
61
61
|
state.close();
|
|
62
62
|
},
|
|
63
63
|
onLongPress () {
|
|
64
|
-
state.open(
|
|
64
|
+
state.open('first');
|
|
65
65
|
}
|
|
66
66
|
});
|
|
67
67
|
let pressProps = {
|
|
68
68
|
onPressStart (e) {
|
|
69
69
|
// For consistency with native, open the menu on mouse/key down, but touch up.
|
|
70
|
-
if (e.pointerType !==
|
|
70
|
+
if (e.pointerType !== 'touch' && e.pointerType !== 'keyboard' && !isDisabled) // If opened with a screen reader, auto focus the first item.
|
|
71
71
|
// Otherwise, the menu itself will be focused.
|
|
72
|
-
state.open(e.pointerType ===
|
|
72
|
+
state.open(e.pointerType === 'virtual' ? 'first' : null);
|
|
73
73
|
},
|
|
74
74
|
onPress (e) {
|
|
75
|
-
if (e.pointerType ===
|
|
75
|
+
if (e.pointerType === 'touch' && !isDisabled) state.toggle();
|
|
76
76
|
}
|
|
77
77
|
};
|
|
78
78
|
// omit onPress from triggerProps since we override it above.
|
|
@@ -80,13 +80,13 @@ function $168583247155ddda$export$dc9c12ed27dd1b49(props, state, ref) {
|
|
|
80
80
|
return {
|
|
81
81
|
menuTriggerProps: {
|
|
82
82
|
...triggerProps,
|
|
83
|
-
...trigger ===
|
|
83
|
+
...trigger === 'press' ? pressProps : longPressProps,
|
|
84
84
|
id: menuTriggerId,
|
|
85
85
|
onKeyDown: onKeyDown
|
|
86
86
|
},
|
|
87
87
|
menuProps: {
|
|
88
88
|
...overlayProps,
|
|
89
|
-
|
|
89
|
+
'aria-labelledby': menuTriggerId,
|
|
90
90
|
autoFocus: state.focusStrategy || true,
|
|
91
91
|
onClose: state.close
|
|
92
92
|
}
|
|
@@ -42,8 +42,8 @@ function $62347d8c4183e713$export$85ec83e04c95f50a(options) {
|
|
|
42
42
|
};
|
|
43
43
|
let modality = (0, $g3RPq$reactariainteractions.useInteractionModality)();
|
|
44
44
|
(0, $g3RPq$react.useEffect)(()=>{
|
|
45
|
-
if (preventPointerEvents && menuRef.current) menuRef.current.style.pointerEvents =
|
|
46
|
-
else menuRef.current.style.pointerEvents =
|
|
45
|
+
if (preventPointerEvents && menuRef.current) menuRef.current.style.pointerEvents = 'none';
|
|
46
|
+
else menuRef.current.style.pointerEvents = '';
|
|
47
47
|
}, [
|
|
48
48
|
menuRef,
|
|
49
49
|
preventPointerEvents
|
|
@@ -51,13 +51,13 @@ function $62347d8c4183e713$export$85ec83e04c95f50a(options) {
|
|
|
51
51
|
(0, $g3RPq$react.useEffect)(()=>{
|
|
52
52
|
let submenu = submenuRef.current;
|
|
53
53
|
let menu = menuRef.current;
|
|
54
|
-
if (isDisabled || !submenu || !isOpen || modality !==
|
|
54
|
+
if (isDisabled || !submenu || !isOpen || modality !== 'pointer') {
|
|
55
55
|
reset();
|
|
56
56
|
return;
|
|
57
57
|
}
|
|
58
58
|
submenuRect.current = submenu.getBoundingClientRect();
|
|
59
59
|
let onPointerMove = (e)=>{
|
|
60
|
-
if (e.pointerType ===
|
|
60
|
+
if (e.pointerType === 'touch' || e.pointerType === 'pen') return;
|
|
61
61
|
let currentTime = Date.now();
|
|
62
62
|
// Throttle
|
|
63
63
|
if (currentTime - lastProcessedTime.current < $62347d8c4183e713$var$THROTTLE_TIME) return;
|
|
@@ -72,7 +72,7 @@ function $62347d8c4183e713$export$85ec83e04c95f50a(options) {
|
|
|
72
72
|
return;
|
|
73
73
|
}
|
|
74
74
|
if (!submenuRect.current) return;
|
|
75
|
-
if (!submenuSide.current) submenuSide.current = mouseX > submenuRect.current.right ?
|
|
75
|
+
if (!submenuSide.current) submenuSide.current = mouseX > submenuRect.current.right ? 'left' : 'right';
|
|
76
76
|
// Pointer is outside of parent menu
|
|
77
77
|
if (mouseX < menu.getBoundingClientRect().left || mouseX > menu.getBoundingClientRect().right || mouseY < menu.getBoundingClientRect().top || mouseY > menu.getBoundingClientRect().bottom) {
|
|
78
78
|
reset();
|
|
@@ -86,10 +86,10 @@ function $62347d8c4183e713$export$85ec83e04c95f50a(options) {
|
|
|
86
86
|
If the pointer delta angle value is between the top and bottom angle values, we know the pointer is moving towards the submenu.
|
|
87
87
|
*/ let prevMouseX = prevPointerPos.current.x;
|
|
88
88
|
let prevMouseY = prevPointerPos.current.y;
|
|
89
|
-
let toSubmenuX = submenuSide.current ===
|
|
89
|
+
let toSubmenuX = submenuSide.current === 'right' ? submenuRect.current.left - prevMouseX : prevMouseX - submenuRect.current.right;
|
|
90
90
|
let angleTop = Math.atan2(prevMouseY - submenuRect.current.top, toSubmenuX) + $62347d8c4183e713$var$ANGLE_PADDING;
|
|
91
91
|
let angleBottom = Math.atan2(prevMouseY - submenuRect.current.bottom, toSubmenuX) - $62347d8c4183e713$var$ANGLE_PADDING;
|
|
92
|
-
let anglePointer = Math.atan2(prevMouseY - mouseY, submenuSide.current ===
|
|
92
|
+
let anglePointer = Math.atan2(prevMouseY - mouseY, submenuSide.current === 'left' ? -(mouseX - prevMouseX) : mouseX - prevMouseX);
|
|
93
93
|
let isMovingTowardsSubmenu = anglePointer < angleTop && anglePointer > angleBottom;
|
|
94
94
|
movementsTowardsSubmenuCount.current = isMovingTowardsSubmenu ? Math.min(movementsTowardsSubmenuCount.current + 1, $62347d8c4183e713$var$ALLOWED_INVALID_MOVEMENTS) : Math.max(movementsTowardsSubmenuCount.current - 1, 0);
|
|
95
95
|
if (movementsTowardsSubmenuCount.current >= $62347d8c4183e713$var$ALLOWED_INVALID_MOVEMENTS) setPreventPointerEvents(true);
|
|
@@ -106,16 +106,16 @@ function $62347d8c4183e713$export$85ec83e04c95f50a(options) {
|
|
|
106
106
|
// Fire a pointerover event to trigger the menu to close.
|
|
107
107
|
// Wait until pointer-events:none is no longer applied
|
|
108
108
|
let target = document.elementFromPoint(mouseX, mouseY);
|
|
109
|
-
if (target && menu.contains(target)) target.dispatchEvent(new PointerEvent(
|
|
109
|
+
if (target && menu.contains(target)) target.dispatchEvent(new PointerEvent('pointerover', {
|
|
110
110
|
bubbles: true,
|
|
111
111
|
cancelable: true
|
|
112
112
|
}));
|
|
113
113
|
}, 100);
|
|
114
114
|
}, $62347d8c4183e713$var$TIMEOUT_TIME);
|
|
115
115
|
};
|
|
116
|
-
window.addEventListener(
|
|
116
|
+
window.addEventListener('pointermove', onPointerMove);
|
|
117
117
|
return ()=>{
|
|
118
|
-
window.removeEventListener(
|
|
118
|
+
window.removeEventListener('pointermove', onPointerMove);
|
|
119
119
|
clearTimeout(timeout.current);
|
|
120
120
|
clearTimeout(autoCloseTimeout.current);
|
|
121
121
|
movementsTowardsSubmenuCount.current = $62347d8c4183e713$var$ALLOWED_INVALID_MOVEMENTS;
|
|
@@ -36,8 +36,8 @@ function $d275435c250248f8$export$85ec83e04c95f50a(options) {
|
|
|
36
36
|
};
|
|
37
37
|
let modality = (0, $fUfeP$useInteractionModality)();
|
|
38
38
|
(0, $fUfeP$useEffect)(()=>{
|
|
39
|
-
if (preventPointerEvents && menuRef.current) menuRef.current.style.pointerEvents =
|
|
40
|
-
else menuRef.current.style.pointerEvents =
|
|
39
|
+
if (preventPointerEvents && menuRef.current) menuRef.current.style.pointerEvents = 'none';
|
|
40
|
+
else menuRef.current.style.pointerEvents = '';
|
|
41
41
|
}, [
|
|
42
42
|
menuRef,
|
|
43
43
|
preventPointerEvents
|
|
@@ -45,13 +45,13 @@ function $d275435c250248f8$export$85ec83e04c95f50a(options) {
|
|
|
45
45
|
(0, $fUfeP$useEffect)(()=>{
|
|
46
46
|
let submenu = submenuRef.current;
|
|
47
47
|
let menu = menuRef.current;
|
|
48
|
-
if (isDisabled || !submenu || !isOpen || modality !==
|
|
48
|
+
if (isDisabled || !submenu || !isOpen || modality !== 'pointer') {
|
|
49
49
|
reset();
|
|
50
50
|
return;
|
|
51
51
|
}
|
|
52
52
|
submenuRect.current = submenu.getBoundingClientRect();
|
|
53
53
|
let onPointerMove = (e)=>{
|
|
54
|
-
if (e.pointerType ===
|
|
54
|
+
if (e.pointerType === 'touch' || e.pointerType === 'pen') return;
|
|
55
55
|
let currentTime = Date.now();
|
|
56
56
|
// Throttle
|
|
57
57
|
if (currentTime - lastProcessedTime.current < $d275435c250248f8$var$THROTTLE_TIME) return;
|
|
@@ -66,7 +66,7 @@ function $d275435c250248f8$export$85ec83e04c95f50a(options) {
|
|
|
66
66
|
return;
|
|
67
67
|
}
|
|
68
68
|
if (!submenuRect.current) return;
|
|
69
|
-
if (!submenuSide.current) submenuSide.current = mouseX > submenuRect.current.right ?
|
|
69
|
+
if (!submenuSide.current) submenuSide.current = mouseX > submenuRect.current.right ? 'left' : 'right';
|
|
70
70
|
// Pointer is outside of parent menu
|
|
71
71
|
if (mouseX < menu.getBoundingClientRect().left || mouseX > menu.getBoundingClientRect().right || mouseY < menu.getBoundingClientRect().top || mouseY > menu.getBoundingClientRect().bottom) {
|
|
72
72
|
reset();
|
|
@@ -80,10 +80,10 @@ function $d275435c250248f8$export$85ec83e04c95f50a(options) {
|
|
|
80
80
|
If the pointer delta angle value is between the top and bottom angle values, we know the pointer is moving towards the submenu.
|
|
81
81
|
*/ let prevMouseX = prevPointerPos.current.x;
|
|
82
82
|
let prevMouseY = prevPointerPos.current.y;
|
|
83
|
-
let toSubmenuX = submenuSide.current ===
|
|
83
|
+
let toSubmenuX = submenuSide.current === 'right' ? submenuRect.current.left - prevMouseX : prevMouseX - submenuRect.current.right;
|
|
84
84
|
let angleTop = Math.atan2(prevMouseY - submenuRect.current.top, toSubmenuX) + $d275435c250248f8$var$ANGLE_PADDING;
|
|
85
85
|
let angleBottom = Math.atan2(prevMouseY - submenuRect.current.bottom, toSubmenuX) - $d275435c250248f8$var$ANGLE_PADDING;
|
|
86
|
-
let anglePointer = Math.atan2(prevMouseY - mouseY, submenuSide.current ===
|
|
86
|
+
let anglePointer = Math.atan2(prevMouseY - mouseY, submenuSide.current === 'left' ? -(mouseX - prevMouseX) : mouseX - prevMouseX);
|
|
87
87
|
let isMovingTowardsSubmenu = anglePointer < angleTop && anglePointer > angleBottom;
|
|
88
88
|
movementsTowardsSubmenuCount.current = isMovingTowardsSubmenu ? Math.min(movementsTowardsSubmenuCount.current + 1, $d275435c250248f8$var$ALLOWED_INVALID_MOVEMENTS) : Math.max(movementsTowardsSubmenuCount.current - 1, 0);
|
|
89
89
|
if (movementsTowardsSubmenuCount.current >= $d275435c250248f8$var$ALLOWED_INVALID_MOVEMENTS) setPreventPointerEvents(true);
|
|
@@ -100,16 +100,16 @@ function $d275435c250248f8$export$85ec83e04c95f50a(options) {
|
|
|
100
100
|
// Fire a pointerover event to trigger the menu to close.
|
|
101
101
|
// Wait until pointer-events:none is no longer applied
|
|
102
102
|
let target = document.elementFromPoint(mouseX, mouseY);
|
|
103
|
-
if (target && menu.contains(target)) target.dispatchEvent(new PointerEvent(
|
|
103
|
+
if (target && menu.contains(target)) target.dispatchEvent(new PointerEvent('pointerover', {
|
|
104
104
|
bubbles: true,
|
|
105
105
|
cancelable: true
|
|
106
106
|
}));
|
|
107
107
|
}, 100);
|
|
108
108
|
}, $d275435c250248f8$var$TIMEOUT_TIME);
|
|
109
109
|
};
|
|
110
|
-
window.addEventListener(
|
|
110
|
+
window.addEventListener('pointermove', onPointerMove);
|
|
111
111
|
return ()=>{
|
|
112
|
-
window.removeEventListener(
|
|
112
|
+
window.removeEventListener('pointermove', onPointerMove);
|
|
113
113
|
clearTimeout(timeout.current);
|
|
114
114
|
clearTimeout(autoCloseTimeout.current);
|
|
115
115
|
movementsTowardsSubmenuCount.current = $d275435c250248f8$var$ALLOWED_INVALID_MOVEMENTS;
|
|
@@ -36,8 +36,8 @@ function $d275435c250248f8$export$85ec83e04c95f50a(options) {
|
|
|
36
36
|
};
|
|
37
37
|
let modality = (0, $fUfeP$useInteractionModality)();
|
|
38
38
|
(0, $fUfeP$useEffect)(()=>{
|
|
39
|
-
if (preventPointerEvents && menuRef.current) menuRef.current.style.pointerEvents =
|
|
40
|
-
else menuRef.current.style.pointerEvents =
|
|
39
|
+
if (preventPointerEvents && menuRef.current) menuRef.current.style.pointerEvents = 'none';
|
|
40
|
+
else menuRef.current.style.pointerEvents = '';
|
|
41
41
|
}, [
|
|
42
42
|
menuRef,
|
|
43
43
|
preventPointerEvents
|
|
@@ -45,13 +45,13 @@ function $d275435c250248f8$export$85ec83e04c95f50a(options) {
|
|
|
45
45
|
(0, $fUfeP$useEffect)(()=>{
|
|
46
46
|
let submenu = submenuRef.current;
|
|
47
47
|
let menu = menuRef.current;
|
|
48
|
-
if (isDisabled || !submenu || !isOpen || modality !==
|
|
48
|
+
if (isDisabled || !submenu || !isOpen || modality !== 'pointer') {
|
|
49
49
|
reset();
|
|
50
50
|
return;
|
|
51
51
|
}
|
|
52
52
|
submenuRect.current = submenu.getBoundingClientRect();
|
|
53
53
|
let onPointerMove = (e)=>{
|
|
54
|
-
if (e.pointerType ===
|
|
54
|
+
if (e.pointerType === 'touch' || e.pointerType === 'pen') return;
|
|
55
55
|
let currentTime = Date.now();
|
|
56
56
|
// Throttle
|
|
57
57
|
if (currentTime - lastProcessedTime.current < $d275435c250248f8$var$THROTTLE_TIME) return;
|
|
@@ -66,7 +66,7 @@ function $d275435c250248f8$export$85ec83e04c95f50a(options) {
|
|
|
66
66
|
return;
|
|
67
67
|
}
|
|
68
68
|
if (!submenuRect.current) return;
|
|
69
|
-
if (!submenuSide.current) submenuSide.current = mouseX > submenuRect.current.right ?
|
|
69
|
+
if (!submenuSide.current) submenuSide.current = mouseX > submenuRect.current.right ? 'left' : 'right';
|
|
70
70
|
// Pointer is outside of parent menu
|
|
71
71
|
if (mouseX < menu.getBoundingClientRect().left || mouseX > menu.getBoundingClientRect().right || mouseY < menu.getBoundingClientRect().top || mouseY > menu.getBoundingClientRect().bottom) {
|
|
72
72
|
reset();
|
|
@@ -80,10 +80,10 @@ function $d275435c250248f8$export$85ec83e04c95f50a(options) {
|
|
|
80
80
|
If the pointer delta angle value is between the top and bottom angle values, we know the pointer is moving towards the submenu.
|
|
81
81
|
*/ let prevMouseX = prevPointerPos.current.x;
|
|
82
82
|
let prevMouseY = prevPointerPos.current.y;
|
|
83
|
-
let toSubmenuX = submenuSide.current ===
|
|
83
|
+
let toSubmenuX = submenuSide.current === 'right' ? submenuRect.current.left - prevMouseX : prevMouseX - submenuRect.current.right;
|
|
84
84
|
let angleTop = Math.atan2(prevMouseY - submenuRect.current.top, toSubmenuX) + $d275435c250248f8$var$ANGLE_PADDING;
|
|
85
85
|
let angleBottom = Math.atan2(prevMouseY - submenuRect.current.bottom, toSubmenuX) - $d275435c250248f8$var$ANGLE_PADDING;
|
|
86
|
-
let anglePointer = Math.atan2(prevMouseY - mouseY, submenuSide.current ===
|
|
86
|
+
let anglePointer = Math.atan2(prevMouseY - mouseY, submenuSide.current === 'left' ? -(mouseX - prevMouseX) : mouseX - prevMouseX);
|
|
87
87
|
let isMovingTowardsSubmenu = anglePointer < angleTop && anglePointer > angleBottom;
|
|
88
88
|
movementsTowardsSubmenuCount.current = isMovingTowardsSubmenu ? Math.min(movementsTowardsSubmenuCount.current + 1, $d275435c250248f8$var$ALLOWED_INVALID_MOVEMENTS) : Math.max(movementsTowardsSubmenuCount.current - 1, 0);
|
|
89
89
|
if (movementsTowardsSubmenuCount.current >= $d275435c250248f8$var$ALLOWED_INVALID_MOVEMENTS) setPreventPointerEvents(true);
|
|
@@ -100,16 +100,16 @@ function $d275435c250248f8$export$85ec83e04c95f50a(options) {
|
|
|
100
100
|
// Fire a pointerover event to trigger the menu to close.
|
|
101
101
|
// Wait until pointer-events:none is no longer applied
|
|
102
102
|
let target = document.elementFromPoint(mouseX, mouseY);
|
|
103
|
-
if (target && menu.contains(target)) target.dispatchEvent(new PointerEvent(
|
|
103
|
+
if (target && menu.contains(target)) target.dispatchEvent(new PointerEvent('pointerover', {
|
|
104
104
|
bubbles: true,
|
|
105
105
|
cancelable: true
|
|
106
106
|
}));
|
|
107
107
|
}, 100);
|
|
108
108
|
}, $d275435c250248f8$var$TIMEOUT_TIME);
|
|
109
109
|
};
|
|
110
|
-
window.addEventListener(
|
|
110
|
+
window.addEventListener('pointermove', onPointerMove);
|
|
111
111
|
return ()=>{
|
|
112
|
-
window.removeEventListener(
|
|
112
|
+
window.removeEventListener('pointermove', onPointerMove);
|
|
113
113
|
clearTimeout(timeout.current);
|
|
114
114
|
clearTimeout(autoCloseTimeout.current);
|
|
115
115
|
movementsTowardsSubmenuCount.current = $d275435c250248f8$var$ALLOWED_INVALID_MOVEMENTS;
|
|
@@ -24,7 +24,7 @@ $parcel$export(module.exports, "useSubmenuTrigger", () => $5f4753043c9f6cdf$expo
|
|
|
24
24
|
|
|
25
25
|
|
|
26
26
|
function $5f4753043c9f6cdf$export$7138b0d059a6e743(props, state, ref) {
|
|
27
|
-
let { parentMenuRef: parentMenuRef, submenuRef: submenuRef, type: type =
|
|
27
|
+
let { parentMenuRef: parentMenuRef, submenuRef: submenuRef, type: type = 'menu', isDisabled: isDisabled, node: node, delay: delay = 200 } = props;
|
|
28
28
|
let submenuTriggerId = (0, $23MMN$reactariautils.useId)();
|
|
29
29
|
let overlayId = (0, $23MMN$reactariautils.useId)();
|
|
30
30
|
let { direction: direction } = (0, $23MMN$reactariai18n.useLocale)();
|
|
@@ -54,21 +54,21 @@ function $5f4753043c9f6cdf$export$7138b0d059a6e743(props, state, ref) {
|
|
|
54
54
|
]);
|
|
55
55
|
let submenuKeyDown = (e)=>{
|
|
56
56
|
switch(e.key){
|
|
57
|
-
case
|
|
58
|
-
if (direction ===
|
|
57
|
+
case 'ArrowLeft':
|
|
58
|
+
if (direction === 'ltr' && e.currentTarget.contains(e.target)) {
|
|
59
59
|
e.stopPropagation();
|
|
60
60
|
onSubmenuClose();
|
|
61
61
|
ref.current.focus();
|
|
62
62
|
}
|
|
63
63
|
break;
|
|
64
|
-
case
|
|
65
|
-
if (direction ===
|
|
64
|
+
case 'ArrowRight':
|
|
65
|
+
if (direction === 'rtl' && e.currentTarget.contains(e.target)) {
|
|
66
66
|
e.stopPropagation();
|
|
67
67
|
onSubmenuClose();
|
|
68
68
|
ref.current.focus();
|
|
69
69
|
}
|
|
70
70
|
break;
|
|
71
|
-
case
|
|
71
|
+
case 'Escape':
|
|
72
72
|
e.stopPropagation();
|
|
73
73
|
state.closeAll();
|
|
74
74
|
break;
|
|
@@ -76,9 +76,9 @@ function $5f4753043c9f6cdf$export$7138b0d059a6e743(props, state, ref) {
|
|
|
76
76
|
};
|
|
77
77
|
let submenuProps = {
|
|
78
78
|
id: overlayId,
|
|
79
|
-
|
|
79
|
+
'aria-label': node.textValue,
|
|
80
80
|
submenuLevel: state.submenuLevel,
|
|
81
|
-
...type ===
|
|
81
|
+
...type === 'menu' && {
|
|
82
82
|
onClose: state.closeAll,
|
|
83
83
|
autoFocus: state.focusStrategy,
|
|
84
84
|
onKeyDown: submenuKeyDown
|
|
@@ -86,25 +86,25 @@ function $5f4753043c9f6cdf$export$7138b0d059a6e743(props, state, ref) {
|
|
|
86
86
|
};
|
|
87
87
|
let submenuTriggerKeyDown = (e)=>{
|
|
88
88
|
switch(e.key){
|
|
89
|
-
case
|
|
89
|
+
case 'ArrowRight':
|
|
90
90
|
if (!isDisabled) {
|
|
91
|
-
if (direction ===
|
|
92
|
-
if (!state.isOpen) onSubmenuOpen(
|
|
93
|
-
if (type ===
|
|
91
|
+
if (direction === 'ltr') {
|
|
92
|
+
if (!state.isOpen) onSubmenuOpen('first');
|
|
93
|
+
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();
|
|
94
94
|
} else if (state.isOpen) onSubmenuClose();
|
|
95
95
|
else e.continuePropagation();
|
|
96
96
|
}
|
|
97
97
|
break;
|
|
98
|
-
case
|
|
98
|
+
case 'ArrowLeft':
|
|
99
99
|
if (!isDisabled) {
|
|
100
|
-
if (direction ===
|
|
101
|
-
if (!state.isOpen) onSubmenuOpen(
|
|
102
|
-
if (type ===
|
|
100
|
+
if (direction === 'rtl') {
|
|
101
|
+
if (!state.isOpen) onSubmenuOpen('first');
|
|
102
|
+
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();
|
|
103
103
|
} else if (state.isOpen) onSubmenuClose();
|
|
104
104
|
else e.continuePropagation();
|
|
105
105
|
}
|
|
106
106
|
break;
|
|
107
|
-
case
|
|
107
|
+
case 'Escape':
|
|
108
108
|
state.closeAll();
|
|
109
109
|
break;
|
|
110
110
|
default:
|
|
@@ -113,11 +113,11 @@ function $5f4753043c9f6cdf$export$7138b0d059a6e743(props, state, ref) {
|
|
|
113
113
|
}
|
|
114
114
|
};
|
|
115
115
|
let onPressStart = (e)=>{
|
|
116
|
-
if (!isDisabled && (e.pointerType ===
|
|
117
|
-
onSubmenuOpen(
|
|
116
|
+
if (!isDisabled && (e.pointerType === 'virtual' || e.pointerType === 'keyboard')) // If opened with a screen reader or keyboard, auto focus the first submenu item.
|
|
117
|
+
onSubmenuOpen('first');
|
|
118
118
|
};
|
|
119
119
|
let onPress = (e)=>{
|
|
120
|
-
if (!isDisabled && (e.pointerType ===
|
|
120
|
+
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
|
|
121
121
|
// press up happening on the newly opened tray items
|
|
122
122
|
onSubmenuOpen();
|
|
123
123
|
};
|
|
@@ -146,9 +146,9 @@ function $5f4753043c9f6cdf$export$7138b0d059a6e743(props, state, ref) {
|
|
|
146
146
|
return {
|
|
147
147
|
submenuTriggerProps: {
|
|
148
148
|
id: submenuTriggerId,
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
149
|
+
'aria-controls': state.isOpen ? overlayId : undefined,
|
|
150
|
+
'aria-haspopup': !isDisabled ? type : undefined,
|
|
151
|
+
'aria-expanded': state.isOpen ? 'true' : 'false',
|
|
152
152
|
onPressStart: onPressStart,
|
|
153
153
|
onPress: onPress,
|
|
154
154
|
onHoverChange: onHoverChange,
|
|
@@ -18,7 +18,7 @@ import {useLocale as $dXlYe$useLocale} from "@react-aria/i18n";
|
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
function $0065b146e7192841$export$7138b0d059a6e743(props, state, ref) {
|
|
21
|
-
let { parentMenuRef: parentMenuRef, submenuRef: submenuRef, type: type =
|
|
21
|
+
let { parentMenuRef: parentMenuRef, submenuRef: submenuRef, type: type = 'menu', isDisabled: isDisabled, node: node, delay: delay = 200 } = props;
|
|
22
22
|
let submenuTriggerId = (0, $dXlYe$useId)();
|
|
23
23
|
let overlayId = (0, $dXlYe$useId)();
|
|
24
24
|
let { direction: direction } = (0, $dXlYe$useLocale)();
|
|
@@ -48,21 +48,21 @@ function $0065b146e7192841$export$7138b0d059a6e743(props, state, ref) {
|
|
|
48
48
|
]);
|
|
49
49
|
let submenuKeyDown = (e)=>{
|
|
50
50
|
switch(e.key){
|
|
51
|
-
case
|
|
52
|
-
if (direction ===
|
|
51
|
+
case 'ArrowLeft':
|
|
52
|
+
if (direction === 'ltr' && e.currentTarget.contains(e.target)) {
|
|
53
53
|
e.stopPropagation();
|
|
54
54
|
onSubmenuClose();
|
|
55
55
|
ref.current.focus();
|
|
56
56
|
}
|
|
57
57
|
break;
|
|
58
|
-
case
|
|
59
|
-
if (direction ===
|
|
58
|
+
case 'ArrowRight':
|
|
59
|
+
if (direction === 'rtl' && e.currentTarget.contains(e.target)) {
|
|
60
60
|
e.stopPropagation();
|
|
61
61
|
onSubmenuClose();
|
|
62
62
|
ref.current.focus();
|
|
63
63
|
}
|
|
64
64
|
break;
|
|
65
|
-
case
|
|
65
|
+
case 'Escape':
|
|
66
66
|
e.stopPropagation();
|
|
67
67
|
state.closeAll();
|
|
68
68
|
break;
|
|
@@ -70,9 +70,9 @@ function $0065b146e7192841$export$7138b0d059a6e743(props, state, ref) {
|
|
|
70
70
|
};
|
|
71
71
|
let submenuProps = {
|
|
72
72
|
id: overlayId,
|
|
73
|
-
|
|
73
|
+
'aria-label': node.textValue,
|
|
74
74
|
submenuLevel: state.submenuLevel,
|
|
75
|
-
...type ===
|
|
75
|
+
...type === 'menu' && {
|
|
76
76
|
onClose: state.closeAll,
|
|
77
77
|
autoFocus: state.focusStrategy,
|
|
78
78
|
onKeyDown: submenuKeyDown
|
|
@@ -80,25 +80,25 @@ function $0065b146e7192841$export$7138b0d059a6e743(props, state, ref) {
|
|
|
80
80
|
};
|
|
81
81
|
let submenuTriggerKeyDown = (e)=>{
|
|
82
82
|
switch(e.key){
|
|
83
|
-
case
|
|
83
|
+
case 'ArrowRight':
|
|
84
84
|
if (!isDisabled) {
|
|
85
|
-
if (direction ===
|
|
86
|
-
if (!state.isOpen) onSubmenuOpen(
|
|
87
|
-
if (type ===
|
|
85
|
+
if (direction === 'ltr') {
|
|
86
|
+
if (!state.isOpen) onSubmenuOpen('first');
|
|
87
|
+
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();
|
|
88
88
|
} else if (state.isOpen) onSubmenuClose();
|
|
89
89
|
else e.continuePropagation();
|
|
90
90
|
}
|
|
91
91
|
break;
|
|
92
|
-
case
|
|
92
|
+
case 'ArrowLeft':
|
|
93
93
|
if (!isDisabled) {
|
|
94
|
-
if (direction ===
|
|
95
|
-
if (!state.isOpen) onSubmenuOpen(
|
|
96
|
-
if (type ===
|
|
94
|
+
if (direction === 'rtl') {
|
|
95
|
+
if (!state.isOpen) onSubmenuOpen('first');
|
|
96
|
+
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();
|
|
97
97
|
} else if (state.isOpen) onSubmenuClose();
|
|
98
98
|
else e.continuePropagation();
|
|
99
99
|
}
|
|
100
100
|
break;
|
|
101
|
-
case
|
|
101
|
+
case 'Escape':
|
|
102
102
|
state.closeAll();
|
|
103
103
|
break;
|
|
104
104
|
default:
|
|
@@ -107,11 +107,11 @@ function $0065b146e7192841$export$7138b0d059a6e743(props, state, ref) {
|
|
|
107
107
|
}
|
|
108
108
|
};
|
|
109
109
|
let onPressStart = (e)=>{
|
|
110
|
-
if (!isDisabled && (e.pointerType ===
|
|
111
|
-
onSubmenuOpen(
|
|
110
|
+
if (!isDisabled && (e.pointerType === 'virtual' || e.pointerType === 'keyboard')) // If opened with a screen reader or keyboard, auto focus the first submenu item.
|
|
111
|
+
onSubmenuOpen('first');
|
|
112
112
|
};
|
|
113
113
|
let onPress = (e)=>{
|
|
114
|
-
if (!isDisabled && (e.pointerType ===
|
|
114
|
+
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
|
|
115
115
|
// press up happening on the newly opened tray items
|
|
116
116
|
onSubmenuOpen();
|
|
117
117
|
};
|
|
@@ -140,9 +140,9 @@ function $0065b146e7192841$export$7138b0d059a6e743(props, state, ref) {
|
|
|
140
140
|
return {
|
|
141
141
|
submenuTriggerProps: {
|
|
142
142
|
id: submenuTriggerId,
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
143
|
+
'aria-controls': state.isOpen ? overlayId : undefined,
|
|
144
|
+
'aria-haspopup': !isDisabled ? type : undefined,
|
|
145
|
+
'aria-expanded': state.isOpen ? 'true' : 'false',
|
|
146
146
|
onPressStart: onPressStart,
|
|
147
147
|
onPress: onPress,
|
|
148
148
|
onHoverChange: onHoverChange,
|