@astryxdesign/core 0.7.6-canary.2a905bb → 0.7.6-canary.2fa4cef
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/BottomSheet/BottomSheetPanel.d.ts.map +1 -1
- package/dist/BottomSheet/BottomSheetPanel.js +36 -9
- package/dist/BottomSheet/useSheetGestures.d.ts +36 -6
- package/dist/BottomSheet/useSheetGestures.d.ts.map +1 -1
- package/dist/BottomSheet/useSheetGestures.js +67 -10
- package/dist/FileInput/FileInput.d.ts.map +1 -1
- package/dist/FileInput/FileInput.js +27 -2
- package/dist/Layer/useTouchTrigger.d.ts +16 -2
- package/dist/Layer/useTouchTrigger.d.ts.map +1 -1
- package/dist/Layer/useTouchTrigger.js +56 -7
- package/dist/Toast/useToast.d.ts.map +1 -1
- package/dist/Toast/useToast.js +8 -2
- package/dist/ToggleButton/ToggleButton.d.ts.map +1 -1
- package/dist/ToggleButton/ToggleButton.js +8 -2
- package/dist/gestures/haptics.d.ts.map +1 -1
- package/dist/gestures/haptics.js +1 -5
- package/dist/hooks/useClickableContainer.d.ts +24 -4
- package/dist/hooks/useClickableContainer.d.ts.map +1 -1
- package/dist/hooks/useClickableContainer.js +41 -14
- package/dist/theme/Theme.d.ts +10 -0
- package/dist/theme/Theme.d.ts.map +1 -1
- package/dist/theme/Theme.js +8 -4
- package/dist/utils/pressDisabled.d.ts +21 -0
- package/dist/utils/pressDisabled.d.ts.map +1 -0
- package/dist/utils/pressDisabled.js +32 -0
- package/package.json +4 -4
- package/src/BottomSheet/BottomSheetPanel.tsx +39 -8
- package/src/BottomSheet/useSheetGestures.ts +92 -15
- package/src/FileInput/FileInput.tsx +29 -1
- package/src/HoverCard/HoverCard.doc.mjs +3 -3
- package/src/HoverCard/HoverCard.spec.md +16 -14
- package/src/HoverCard/useHoverCard.doc.mjs +1 -1
- package/src/Layer/useTouchTrigger.ts +70 -10
- package/src/Toast/useToast.tsx +8 -3
- package/src/ToggleButton/ToggleButton.tsx +9 -3
- package/src/Tooltip/Tooltip.doc.mjs +3 -3
- package/src/Tooltip/Tooltip.spec.md +17 -17
- package/src/Tooltip/useTooltip.doc.mjs +1 -1
- package/src/gestures/haptics.ts +1 -8
- package/src/hooks/useClickableContainer.ts +48 -17
- package/src/theme/Theme.tsx +8 -4
- package/src/utils/pressDisabled.ts +32 -0
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
/**
|
|
6
6
|
* @file useClickableContainer.ts
|
|
7
7
|
* @input Container ref, interactive element ref, click/href handlers
|
|
8
|
-
* @output onClick and onMouseUp handlers for the container; INTERACTIVE_SELECTORS list
|
|
8
|
+
* @output onClick and onMouseUp handlers for the container; INTERACTIVE_SELECTORS list;
|
|
9
|
+
* hasInteractiveAncestor and the shared innermostInteractive walk
|
|
9
10
|
* @position Core hook for clickable containers that safely handle nested interactive elements
|
|
10
11
|
*
|
|
11
12
|
* Solves the "nested interactive elements" problem: when a card is clickable
|
|
@@ -23,6 +24,13 @@
|
|
|
23
24
|
import {useCallback, useEffect, type RefObject, type MouseEvent} from 'react';
|
|
24
25
|
import {isSafeUrl} from '../utils/safeUrl';
|
|
25
26
|
|
|
27
|
+
/**
|
|
28
|
+
* The attribute this hook sets on the container it makes clickable. A click
|
|
29
|
+
* inside a nested marked container belongs to that container (see
|
|
30
|
+
* INTERACTIVE_SELECTORS).
|
|
31
|
+
*/
|
|
32
|
+
export const PRESSABLE_CONTAINER_ATTRIBUTE = 'data-pressable-container';
|
|
33
|
+
|
|
26
34
|
/**
|
|
27
35
|
* Canonical list of interactive element selectors — native controls plus
|
|
28
36
|
* role-based interactive elements. Clicks on these (or their descendants)
|
|
@@ -52,15 +60,48 @@ export const INTERACTIVE_SELECTORS = [
|
|
|
52
60
|
'[role="listbox"]',
|
|
53
61
|
'[role="slider"]',
|
|
54
62
|
'[role="spinbutton"]',
|
|
55
|
-
|
|
63
|
+
`[${PRESSABLE_CONTAINER_ATTRIBUTE}]`,
|
|
56
64
|
].join(',');
|
|
57
65
|
|
|
58
66
|
const NON_INTERACTIVE_SELECTORS = '[aria-readonly="true"]';
|
|
59
67
|
|
|
60
68
|
/**
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
|
|
69
|
+
* Whether this element is interactive by INTERACTIVE_SELECTORS: a control,
|
|
70
|
+
* link, editor, or nested clickable container, and not marked read-only.
|
|
71
|
+
*/
|
|
72
|
+
export function matchesInteractiveSelectors(element: Element): boolean {
|
|
73
|
+
return (
|
|
74
|
+
element.matches(INTERACTIVE_SELECTORS) &&
|
|
75
|
+
!element.matches(NON_INTERACTIVE_SELECTORS)
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* The innermost element, from `el` up to (not including) `rootEl` or the
|
|
81
|
+
* document body, that `isInteractive` accepts: by default the
|
|
82
|
+
* INTERACTIVE_SELECTORS match. The one walk every "does this event belong
|
|
83
|
+
* to a control" check shares; a hover layer's tap passes its own test
|
|
84
|
+
* (useTouchTrigger's `tapLandsOnDisabledControl`).
|
|
85
|
+
*/
|
|
86
|
+
export function innermostInteractive(
|
|
87
|
+
el: Element,
|
|
88
|
+
rootEl: Element | null,
|
|
89
|
+
isInteractive: (element: Element) => boolean = matchesInteractiveSelectors,
|
|
90
|
+
): Element | null {
|
|
91
|
+
let current: Element | null = el;
|
|
92
|
+
while (current != null && current !== rootEl && current !== document.body) {
|
|
93
|
+
if (isInteractive(current)) {
|
|
94
|
+
return current;
|
|
95
|
+
}
|
|
96
|
+
current = current.parentElement;
|
|
97
|
+
}
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Check whether an element has an interactive ancestor between it and the
|
|
103
|
+
* root (the element itself included). If the click target is inside a nested
|
|
104
|
+
* button/link/etc., we should NOT handle it at the container level.
|
|
64
105
|
*
|
|
65
106
|
* Exported for containers that cannot use the hook itself — a `<tr>` whose
|
|
66
107
|
* props are assembled inside a Table plugin's `transformBodyRow`, for
|
|
@@ -69,17 +110,7 @@ const NON_INTERACTIVE_SELECTORS = '[aria-readonly="true"]';
|
|
|
69
110
|
* instead of a short hand-rolled selector list per caller.
|
|
70
111
|
*/
|
|
71
112
|
export function hasInteractiveAncestor(el: Element, rootEl: Element): boolean {
|
|
72
|
-
|
|
73
|
-
while (current != null && current !== rootEl && current !== document.body) {
|
|
74
|
-
if (
|
|
75
|
-
current.matches(INTERACTIVE_SELECTORS) &&
|
|
76
|
-
!current.matches(NON_INTERACTIVE_SELECTORS)
|
|
77
|
-
) {
|
|
78
|
-
return true;
|
|
79
|
-
}
|
|
80
|
-
current = current.parentElement;
|
|
81
|
-
}
|
|
82
|
-
return false;
|
|
113
|
+
return innermostInteractive(el, rootEl) != null;
|
|
83
114
|
}
|
|
84
115
|
|
|
85
116
|
/**
|
|
@@ -164,7 +195,7 @@ export function useClickableContainer({
|
|
|
164
195
|
useEffect(() => {
|
|
165
196
|
const el = containerRef.current;
|
|
166
197
|
if (el) {
|
|
167
|
-
el.setAttribute(
|
|
198
|
+
el.setAttribute(PRESSABLE_CONTAINER_ATTRIBUTE, 'true');
|
|
168
199
|
}
|
|
169
200
|
}, [containerRef]);
|
|
170
201
|
|
package/src/theme/Theme.tsx
CHANGED
|
@@ -83,11 +83,15 @@ const wrapperStyles = stylex.create({
|
|
|
83
83
|
// =============================================================================
|
|
84
84
|
|
|
85
85
|
/**
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
86
|
+
* True below a Theme; the root Theme (no parent context) syncs data-theme
|
|
87
|
+
* to <html>. A detached React root that conceptually sits inside the app
|
|
88
|
+
* (useToast's fallback viewport) provides it as `true` itself, so a Theme
|
|
89
|
+
* rendered in toast content themes its subtree without claiming <html> as
|
|
90
|
+
* if it were the app's root Theme.
|
|
91
|
+
* @internal Not exported from the theme barrel; useToast imports it from
|
|
92
|
+
* './theme/Theme' directly.
|
|
89
93
|
*/
|
|
90
|
-
const ThemeNestingContext = React.createContext(false);
|
|
94
|
+
export const ThemeNestingContext = React.createContext(false);
|
|
91
95
|
ThemeNestingContext.displayName = 'ThemeNestingContext';
|
|
92
96
|
|
|
93
97
|
// =============================================================================
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file pressDisabled.ts
|
|
5
|
+
* @input An element
|
|
6
|
+
* @output `isDisabledControl`: whether an element is a disabled control, so a
|
|
7
|
+
* press on it performs no action
|
|
8
|
+
* @position The one disabled-control check that press feedback
|
|
9
|
+
* (../gestures/haptics) and the hover layers' touch trigger
|
|
10
|
+
* (../Layer/useTouchTrigger) share, so the two never disagree about a
|
|
11
|
+
* control. It lives outside the gesture code, which a public import that
|
|
12
|
+
* uses no gesture never carries (architecture:react-component-runtime
|
|
13
|
+
* INV13).
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Whether `element` is a disabled control: `aria-disabled="true"`, or a form
|
|
18
|
+
* control the browser counts as `:disabled` (a disabled fieldset's controls
|
|
19
|
+
* included). A disabled control performs no action, so it gives no press
|
|
20
|
+
* feedback (spec:AST-094 FR23), and a tap on it opens its reason instead
|
|
21
|
+
* (component:Tooltip FR5).
|
|
22
|
+
*/
|
|
23
|
+
export function isDisabledControl(element: Element): boolean {
|
|
24
|
+
if (element.getAttribute('aria-disabled') === 'true') {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
return element.matches(':disabled');
|
|
29
|
+
} catch {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
}
|