@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.
Files changed (42) hide show
  1. package/dist/BottomSheet/BottomSheetPanel.d.ts.map +1 -1
  2. package/dist/BottomSheet/BottomSheetPanel.js +36 -9
  3. package/dist/BottomSheet/useSheetGestures.d.ts +36 -6
  4. package/dist/BottomSheet/useSheetGestures.d.ts.map +1 -1
  5. package/dist/BottomSheet/useSheetGestures.js +67 -10
  6. package/dist/FileInput/FileInput.d.ts.map +1 -1
  7. package/dist/FileInput/FileInput.js +27 -2
  8. package/dist/Layer/useTouchTrigger.d.ts +16 -2
  9. package/dist/Layer/useTouchTrigger.d.ts.map +1 -1
  10. package/dist/Layer/useTouchTrigger.js +56 -7
  11. package/dist/Toast/useToast.d.ts.map +1 -1
  12. package/dist/Toast/useToast.js +8 -2
  13. package/dist/ToggleButton/ToggleButton.d.ts.map +1 -1
  14. package/dist/ToggleButton/ToggleButton.js +8 -2
  15. package/dist/gestures/haptics.d.ts.map +1 -1
  16. package/dist/gestures/haptics.js +1 -5
  17. package/dist/hooks/useClickableContainer.d.ts +24 -4
  18. package/dist/hooks/useClickableContainer.d.ts.map +1 -1
  19. package/dist/hooks/useClickableContainer.js +41 -14
  20. package/dist/theme/Theme.d.ts +10 -0
  21. package/dist/theme/Theme.d.ts.map +1 -1
  22. package/dist/theme/Theme.js +8 -4
  23. package/dist/utils/pressDisabled.d.ts +21 -0
  24. package/dist/utils/pressDisabled.d.ts.map +1 -0
  25. package/dist/utils/pressDisabled.js +32 -0
  26. package/package.json +4 -4
  27. package/src/BottomSheet/BottomSheetPanel.tsx +39 -8
  28. package/src/BottomSheet/useSheetGestures.ts +92 -15
  29. package/src/FileInput/FileInput.tsx +29 -1
  30. package/src/HoverCard/HoverCard.doc.mjs +3 -3
  31. package/src/HoverCard/HoverCard.spec.md +16 -14
  32. package/src/HoverCard/useHoverCard.doc.mjs +1 -1
  33. package/src/Layer/useTouchTrigger.ts +70 -10
  34. package/src/Toast/useToast.tsx +8 -3
  35. package/src/ToggleButton/ToggleButton.tsx +9 -3
  36. package/src/Tooltip/Tooltip.doc.mjs +3 -3
  37. package/src/Tooltip/Tooltip.spec.md +17 -17
  38. package/src/Tooltip/useTooltip.doc.mjs +1 -1
  39. package/src/gestures/haptics.ts +1 -8
  40. package/src/hooks/useClickableContainer.ts +48 -17
  41. package/src/theme/Theme.tsx +8 -4
  42. 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
- '[data-pressable-container]',
63
+ `[${PRESSABLE_CONTAINER_ATTRIBUTE}]`,
56
64
  ].join(',');
57
65
 
58
66
  const NON_INTERACTIVE_SELECTORS = '[aria-readonly="true"]';
59
67
 
60
68
  /**
61
- * Check whether an element has an interactive ancestor between it and the root.
62
- * If the click target is inside a nested button/link/etc., we should NOT
63
- * handle it at the container level.
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
- let current: Element | null = el;
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('data-pressable-container', 'true');
198
+ el.setAttribute(PRESSABLE_CONTAINER_ATTRIBUTE, 'true');
168
199
  }
169
200
  }, [containerRef]);
170
201
 
@@ -83,11 +83,15 @@ const wrapperStyles = stylex.create({
83
83
  // =============================================================================
84
84
 
85
85
  /**
86
- * Context to detect whether this Theme is nested inside another.
87
- * The root provider (no parent context) syncs data-theme to <html>.
88
- * @internal
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
+ }