@astryxdesign/core 0.7.7-canary.bf14580 → 0.7.7-canary.c19ca12
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/AlertDialog/AlertDialog.d.ts +4 -1
- package/dist/AlertDialog/AlertDialog.d.ts.map +1 -1
- package/dist/AlertDialog/AlertDialog.js +36 -6
- package/dist/BottomSheet/BottomSheet.d.ts.map +1 -1
- package/dist/BottomSheet/BottomSheet.js +76 -6
- package/dist/BottomSheet/BottomSheetPanel.d.ts.map +1 -1
- package/dist/BottomSheet/BottomSheetPanel.js +23 -4
- package/dist/BottomSheet/bottomSheetStack.d.ts.map +1 -1
- package/dist/BottomSheet/bottomSheetStack.js +5 -4
- package/dist/BottomSheet/useSheetGestures.d.ts.map +1 -1
- package/dist/BottomSheet/useSheetGestures.js +3 -1
- package/dist/Button/Button.d.ts.map +1 -1
- package/dist/Button/Button.js +47 -3
- package/dist/CheckboxInput/CheckboxInput.d.ts.map +1 -1
- package/dist/CheckboxInput/CheckboxInput.js +13 -2
- package/dist/ComplexSelector/ComplexSelector.d.ts +4 -1
- package/dist/ComplexSelector/ComplexSelector.d.ts.map +1 -1
- package/dist/ComplexSelector/ComplexSelector.js +14 -4
- package/dist/ContextMenu/ContextMenu.js +2 -2
- package/dist/DateInput/MonthScroller.d.ts.map +1 -1
- package/dist/DateInput/MonthScroller.js +13 -27
- package/dist/DateInput/Wheel.d.ts.map +1 -1
- package/dist/DateInput/Wheel.js +22 -41
- package/dist/Dialog/Dialog.d.ts.map +1 -1
- package/dist/Dialog/Dialog.js +7 -31
- package/dist/Field/Field.js +2 -2
- package/dist/HoverCard/HoverCard.d.ts +4 -3
- package/dist/HoverCard/HoverCard.d.ts.map +1 -1
- package/dist/HoverCard/HoverCard.js +27 -2
- package/dist/HoverCard/useHoverCard.d.ts +5 -4
- package/dist/HoverCard/useHoverCard.d.ts.map +1 -1
- package/dist/HoverCard/useHoverCard.js +17 -31
- package/dist/Icon/Icon.d.ts +5 -1
- package/dist/Icon/Icon.d.ts.map +1 -1
- package/dist/Icon/Icon.js +5 -2
- package/dist/Layer/layerAnimations.stylex.d.ts +7 -8
- package/dist/Layer/layerAnimations.stylex.d.ts.map +1 -1
- package/dist/Layer/layerAnimations.stylex.js +25 -20
- package/dist/Layer/usePressPin.d.ts +17 -5
- package/dist/Layer/usePressPin.d.ts.map +1 -1
- package/dist/Layer/usePressPin.js +62 -12
- package/dist/Lightbox/Lightbox.d.ts.map +1 -1
- package/dist/Lightbox/Lightbox.js +18 -0
- package/dist/PowerSearch/PowerSearch.d.ts +36 -3
- package/dist/PowerSearch/PowerSearch.d.ts.map +1 -1
- package/dist/PowerSearch/PowerSearch.js +522 -269
- package/dist/PowerSearch/PowerSearchBottomSheet.d.ts +100 -0
- package/dist/PowerSearch/PowerSearchBottomSheet.d.ts.map +1 -0
- package/dist/PowerSearch/PowerSearchBottomSheet.js +1913 -0
- package/dist/PowerSearch/PowerSearchEditPopover.d.ts +32 -1
- package/dist/PowerSearch/PowerSearchEditPopover.d.ts.map +1 -1
- package/dist/PowerSearch/PowerSearchEditPopover.js +17 -6
- package/dist/PowerSearch/PowerSearchValueEditor.d.ts +38 -3
- package/dist/PowerSearch/PowerSearchValueEditor.d.ts.map +1 -1
- package/dist/PowerSearch/PowerSearchValueEditor.js +170 -61
- package/dist/PowerSearch/formatFilterValue.d.ts +7 -0
- package/dist/PowerSearch/formatFilterValue.d.ts.map +1 -1
- package/dist/PowerSearch/formatFilterValue.js +11 -1
- package/dist/PowerSearch/formatTokenValue.d.ts +28 -0
- package/dist/PowerSearch/formatTokenValue.d.ts.map +1 -0
- package/dist/PowerSearch/formatTokenValue.js +160 -0
- package/dist/PowerSearch/powerSearchSheetUtils.d.ts +65 -0
- package/dist/PowerSearch/powerSearchSheetUtils.d.ts.map +1 -0
- package/dist/PowerSearch/powerSearchSheetUtils.js +168 -0
- package/dist/RadioList/RadioList.d.ts.map +1 -1
- package/dist/RadioList/RadioList.js +3 -2
- package/dist/RadioList/RadioListItem.d.ts +1 -1
- package/dist/RadioList/RadioListItem.d.ts.map +1 -1
- package/dist/RadioList/RadioListItem.js +5 -3
- package/dist/SegmentedControl/useSegmentedSelectionMotion.d.ts.map +1 -1
- package/dist/SegmentedControl/useSegmentedSelectionMotion.js +3 -3
- package/dist/Slider/sliderTouchController.js +2 -2
- package/dist/Spinner/Spinner.d.ts +1 -1
- package/dist/Spinner/Spinner.d.ts.map +1 -1
- package/dist/Spinner/Spinner.js +60 -58
- package/dist/Switch/useSwitchTouch.js +4 -4
- package/dist/Table/BaseTable.d.ts.map +1 -1
- package/dist/Table/BaseTable.js +29 -8
- package/dist/TextInput/TextInput.d.ts +2 -2
- package/dist/TextInput/TextInput.d.ts.map +1 -1
- package/dist/TextInput/TextInput.js +10 -7
- package/dist/Toast/Toast.d.ts +11 -1
- package/dist/Toast/Toast.d.ts.map +1 -1
- package/dist/Toast/Toast.js +25 -15
- package/dist/Toast/ToastViewport.d.ts.map +1 -1
- package/dist/Toast/ToastViewport.js +94 -34
- package/dist/Toast/types.d.ts +9 -3
- package/dist/Toast/types.d.ts.map +1 -1
- package/dist/Token/Token.d.ts +2 -2
- package/dist/Token/Token.d.ts.map +1 -1
- package/dist/Token/Token.js +12 -4
- package/dist/Token/TokenNamingContext.d.ts +14 -0
- package/dist/Token/TokenNamingContext.d.ts.map +1 -0
- package/dist/Token/TokenNamingContext.js +23 -0
- package/dist/Tooltip/useTooltip.d.ts +19 -1
- package/dist/Tooltip/useTooltip.d.ts.map +1 -1
- package/dist/Tooltip/useTooltip.js +34 -53
- package/dist/Typeahead/TypeaheadItem.d.ts +2 -1
- package/dist/Typeahead/TypeaheadItem.d.ts.map +1 -1
- package/dist/animator/createAnimator.d.ts +98 -0
- package/dist/animator/createAnimator.d.ts.map +1 -0
- package/dist/animator/createAnimator.js +259 -0
- package/dist/astryx.css +22 -6
- package/dist/gestures/GestureHost.d.ts +27 -1
- package/dist/gestures/GestureHost.d.ts.map +1 -1
- package/dist/gestures/GestureHost.js +90 -8
- package/dist/gestures/PressTracker.d.ts.map +1 -1
- package/dist/gestures/PressTracker.js +4 -3
- package/dist/hooks/actionGroupTracker.d.ts +4 -1
- package/dist/hooks/actionGroupTracker.d.ts.map +1 -1
- package/dist/hooks/actionGroupTracker.js +13 -3
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +1 -0
- package/dist/hooks/pressGroupContext.d.ts +6 -0
- package/dist/hooks/pressGroupContext.d.ts.map +1 -0
- package/dist/hooks/pressGroupContext.js +20 -0
- package/dist/hooks/useActionGroupTracking.d.ts +53 -0
- package/dist/hooks/useActionGroupTracking.d.ts.map +1 -0
- package/dist/hooks/useActionGroupTracking.js +174 -0
- package/dist/hooks/useAnimator.d.ts +41 -0
- package/dist/hooks/useAnimator.d.ts.map +1 -0
- package/dist/hooks/useAnimator.js +70 -0
- package/dist/hooks/useAttachment.d.ts +1 -1
- package/dist/hooks/useAttachment.js +1 -1
- package/dist/hooks/useInputStatusIcon.d.ts +1 -1
- package/dist/hooks/useInputStatusIcon.d.ts.map +1 -1
- package/dist/hooks/useInputStatusIcon.js +2 -2
- package/dist/hooks/useLongPress.d.ts +6 -2
- package/dist/hooks/useLongPress.d.ts.map +1 -1
- package/dist/hooks/useLongPress.js +95 -15
- package/dist/hooks/useMenuPress.d.ts.map +1 -1
- package/dist/hooks/useMenuPress.js +4 -2
- package/dist/i18n/generated-english/PowerSearch/PowerSearchBottomSheet.generated.d.ts +8 -0
- package/dist/i18n/generated-english/PowerSearch/PowerSearchBottomSheet.generated.d.ts.map +1 -0
- package/dist/i18n/generated-english/PowerSearch/PowerSearchBottomSheet.generated.js +42 -0
- package/dist/i18n/generated-english/PowerSearch/PowerSearchValueEditor.generated.d.ts.map +1 -1
- package/dist/i18n/generated-english/PowerSearch/PowerSearchValueEditor.generated.js +6 -0
- package/dist/i18n/generated-english/PowerSearch/formatTokenValue.generated.d.ts +8 -0
- package/dist/i18n/generated-english/PowerSearch/formatTokenValue.generated.d.ts.map +1 -0
- package/dist/i18n/generated-english/PowerSearch/formatTokenValue.generated.js +14 -0
- package/dist/i18n/generated-locales/en.generated.d.ts.map +1 -1
- package/dist/i18n/generated-locales/en.generated.js +30 -0
- package/dist/i18n/generated-locales/pseudo.generated.d.ts.map +1 -1
- package/dist/i18n/generated-locales/pseudo.generated.js +30 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/internal/indicatorPress.stylex.d.ts +20 -0
- package/dist/internal/indicatorPress.stylex.d.ts.map +1 -0
- package/dist/internal/indicatorPress.stylex.js +26 -0
- package/dist/motion/animator.d.ts +14 -14
- package/dist/motion/animator.d.ts.map +1 -1
- package/dist/motion/animator.js +41 -18
- package/dist/motion/reducedMotion.d.ts +24 -0
- package/dist/motion/reducedMotion.d.ts.map +1 -1
- package/dist/motion/reducedMotion.js +78 -1
- package/dist/motion/uikit/alert.d.ts +41 -0
- package/dist/motion/uikit/alert.d.ts.map +1 -0
- package/dist/motion/uikit/alert.js +43 -0
- package/dist/privateAttributes/pressGroupItem.stylex.d.ts +15 -0
- package/dist/privateAttributes/pressGroupItem.stylex.d.ts.map +1 -0
- package/dist/privateAttributes/pressGroupItem.stylex.js +23 -0
- package/dist/utils/clickGuard.d.ts +8 -1
- package/dist/utils/clickGuard.d.ts.map +1 -1
- package/dist/utils/clickGuard.js +24 -1
- package/dist/utils/dateParser.d.ts.map +1 -1
- package/dist/utils/dateParser.js +12 -0
- package/dist/utils/focusReturn.d.ts +15 -0
- package/dist/utils/focusReturn.d.ts.map +1 -1
- package/dist/utils/focusReturn.js +28 -0
- package/dist/utils/interactionOverlay.stylex.d.ts +3 -2
- package/dist/utils/interactionOverlay.stylex.d.ts.map +1 -1
- package/dist/utils/interactionOverlay.stylex.js +3 -2
- package/dist/utils/pressFeedback.d.ts.map +1 -1
- package/dist/utils/pressFeedback.js +19 -6
- package/dist/utils/triggerFocus.d.ts +36 -0
- package/dist/utils/triggerFocus.d.ts.map +1 -0
- package/dist/utils/triggerFocus.js +65 -0
- package/locales/en.json +120 -0
- package/locales/pseudo.json +90 -0
- package/package.json +9 -4
- package/src/AlertDialog/AlertDialog.doc.mjs +2 -2
- package/src/AlertDialog/AlertDialog.tsx +37 -5
- package/src/BottomSheet/BottomSheet.tsx +85 -5
- package/src/BottomSheet/BottomSheetPanel.tsx +40 -5
- package/src/BottomSheet/bottomSheetStack.ts +8 -4
- package/src/BottomSheet/useSheetGestures.ts +3 -1
- package/src/Button/Button.tsx +63 -5
- package/src/CheckboxInput/CheckboxInput.doc.mjs +18 -0
- package/src/CheckboxInput/CheckboxInput.tsx +36 -9
- package/src/ComplexSelector/ComplexSelector.tsx +20 -5
- package/src/ContextMenu/ContextMenu.tsx +2 -2
- package/src/DateInput/MonthScroller.tsx +18 -22
- package/src/DateInput/Wheel.tsx +30 -32
- package/src/Dialog/Dialog.tsx +10 -31
- package/src/Field/Field.tsx +2 -2
- package/src/HoverCard/HoverCard.doc.mjs +4 -2
- package/src/HoverCard/HoverCard.tsx +35 -4
- package/src/HoverCard/useHoverCard.doc.mjs +178 -36
- package/src/HoverCard/useHoverCard.tsx +46 -52
- package/src/Icon/Icon.doc.mjs +49 -8
- package/src/Icon/Icon.tsx +15 -7
- package/src/Layer/layerAnimations.stylex.ts +24 -16
- package/src/Layer/usePressPin.ts +81 -15
- package/src/Lightbox/Lightbox.tsx +18 -0
- package/src/PowerSearch/PowerSearch.doc.mjs +54 -5
- package/src/PowerSearch/PowerSearch.tsx +734 -288
- package/src/PowerSearch/PowerSearchBottomSheet.tsx +2515 -0
- package/src/PowerSearch/PowerSearchEditPopover.tsx +28 -6
- package/src/PowerSearch/PowerSearchValueEditor.tsx +203 -38
- package/src/PowerSearch/formatFilterValue.ts +18 -1
- package/src/PowerSearch/formatTokenValue.ts +215 -0
- package/src/PowerSearch/powerSearchSheetUtils.ts +224 -0
- package/src/RadioList/RadioList.tsx +3 -2
- package/src/RadioList/RadioListItem.tsx +5 -3
- package/src/SegmentedControl/useSegmentedSelectionMotion.ts +6 -3
- package/src/Slider/sliderTouchController.ts +2 -2
- package/src/Spinner/Spinner.tsx +77 -63
- package/src/Switch/useSwitchTouch.ts +4 -4
- package/src/Table/BaseTable.tsx +46 -12
- package/src/TextInput/TextInput.tsx +11 -10
- package/src/Toast/Toast.doc.mjs +4 -3
- package/src/Toast/Toast.tsx +52 -32
- package/src/Toast/ToastViewport.tsx +121 -35
- package/src/Toast/types.ts +9 -3
- package/src/Token/Token.tsx +13 -4
- package/src/Token/TokenNamingContext.ts +28 -0
- package/src/Tooltip/useTooltip.doc.mjs +24 -0
- package/src/Tooltip/useTooltip.tsx +61 -56
- package/src/Typeahead/TypeaheadItem.doc.mjs +6 -3
- package/src/Typeahead/TypeaheadItem.tsx +2 -1
- package/src/animator/createAnimator.doc.mjs +153 -0
- package/src/animator/createAnimator.ts +324 -0
- package/src/gestures/GestureHost.ts +105 -10
- package/src/gestures/PressTracker.ts +4 -3
- package/src/gestures/README.md +7 -1
- package/src/hooks/actionGroupTracker.ts +20 -5
- package/src/hooks/index.ts +2 -0
- package/src/hooks/pressGroupContext.ts +21 -0
- package/src/hooks/useActionGroupTracking.ts +224 -0
- package/src/hooks/useAnimator.doc.mjs +109 -0
- package/src/hooks/useAnimator.ts +67 -0
- package/src/hooks/useAttachment.ts +1 -1
- package/src/hooks/useInputStatusIcon.tsx +3 -2
- package/src/hooks/useLongPress.doc.mjs +2 -2
- package/src/hooks/useLongPress.ts +136 -15
- package/src/hooks/useMenuPress.ts +8 -2
- package/src/i18n/generated-english/PowerSearch/PowerSearchBottomSheet.generated.ts +43 -0
- package/src/i18n/generated-english/PowerSearch/PowerSearchValueEditor.generated.ts +6 -0
- package/src/i18n/generated-english/PowerSearch/formatTokenValue.generated.ts +15 -0
- package/src/i18n/generated-locales/en.generated.ts +41 -0
- package/src/i18n/generated-locales/pseudo.generated.ts +42 -0
- package/src/index.ts +13 -0
- package/src/internal/indicatorPress.stylex.ts +24 -0
- package/src/motion/README.md +8 -5
- package/src/motion/animator.ts +61 -29
- package/src/motion/reducedMotion.ts +79 -1
- package/src/motion/uikit/alert.ts +43 -0
- package/src/privateAttributes/pressGroupItem.stylex.ts +23 -0
- package/src/utils/clickGuard.ts +37 -1
- package/src/utils/dateParser.ts +16 -0
- package/src/utils/focusReturn.ts +30 -0
- package/src/utils/interactionOverlay.stylex.ts +3 -2
- package/src/utils/pressFeedback.ts +19 -6
- package/src/utils/triggerFocus.ts +80 -0
|
@@ -13,13 +13,14 @@
|
|
|
13
13
|
* SYNC: When placement, stacking, hosting, focus, announcement, or safe-area
|
|
14
14
|
* behavior changes, update ToastViewport.test.tsx, Toast.doc.mjs, and Toast.stories.tsx.
|
|
15
15
|
*/
|
|
16
|
-
import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
|
|
16
|
+
import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from 'react';
|
|
17
17
|
import { createPortal } from 'react-dom';
|
|
18
18
|
import * as stylex from '@stylexjs/stylex';
|
|
19
19
|
import "../theme/tokens.stylex.js";
|
|
20
20
|
import { spacingVars, durationVars, easeVars } from "../theme/tokens.stylex.js";
|
|
21
21
|
import { mergeProps } from "../utils/index.js";
|
|
22
22
|
import { getNodeText } from "../utils/getNodeText.js";
|
|
23
|
+
import { moveFocusLeftBehind, noteFocusWithin } from "../utils/focusReturn.js";
|
|
23
24
|
import { INTERACTIVE_SELECTORS } from "../hooks/useClickableContainer.js";
|
|
24
25
|
import { useAnnounce } from "../hooks/useAnnounce.js";
|
|
25
26
|
import { layerTextReset } from "../Layer/layerTextReset.stylex.js";
|
|
@@ -122,7 +123,8 @@ function ToastRow({
|
|
|
122
123
|
isExiting,
|
|
123
124
|
isReversed,
|
|
124
125
|
onExited,
|
|
125
|
-
onDismiss
|
|
126
|
+
onDismiss,
|
|
127
|
+
isLiveRegion
|
|
126
128
|
}) {
|
|
127
129
|
const o = entry.options;
|
|
128
130
|
const type = o.type ?? 'info';
|
|
@@ -194,12 +196,16 @@ function ToastRow({
|
|
|
194
196
|
isExiting: isExiting,
|
|
195
197
|
gestureDirection: isReversed ? -1 : 1,
|
|
196
198
|
onDismiss: reason => onDismiss(entry.id, reason),
|
|
197
|
-
renderContent: o.renderContent
|
|
199
|
+
renderContent: o.renderContent,
|
|
200
|
+
timerKey: entry.id,
|
|
201
|
+
isLiveRegion: isLiveRegion
|
|
198
202
|
})
|
|
199
203
|
})
|
|
200
204
|
});
|
|
201
205
|
}
|
|
202
206
|
ToastRow.displayName = 'ToastRow';
|
|
207
|
+
const hasActiveModalOutlet = () => getActiveModalOutlet() != null;
|
|
208
|
+
const hasNoModalOutlet = () => false;
|
|
203
209
|
|
|
204
210
|
/**
|
|
205
211
|
* Container that renders and manages toast notifications. Place at the root
|
|
@@ -260,6 +266,11 @@ export function ToastViewport({
|
|
|
260
266
|
// The next toast id that should receive focus once the dismissed toast has
|
|
261
267
|
// unmounted, or 'restore' to fall back to the previously-focused element.
|
|
262
268
|
const pendingFocusRef = useRef(null);
|
|
269
|
+
// The id of a toast whose overwrite updated a row that held focus. If the
|
|
270
|
+
// update removed the focused control, the commit hands focus off.
|
|
271
|
+
const overwriteFocusRef = useRef(null);
|
|
272
|
+
// Where focus was inside a toast whose dismissal hands focus off.
|
|
273
|
+
const dismissFocusNoteRef = useRef(null);
|
|
263
274
|
|
|
264
275
|
// Collect a focusable control within a toast node, if any.
|
|
265
276
|
// Reuses the canonical INTERACTIVE_SELECTORS list (native controls plus
|
|
@@ -280,13 +291,9 @@ export function ToastViewport({
|
|
|
280
291
|
return null;
|
|
281
292
|
}, []);
|
|
282
293
|
|
|
283
|
-
// Announce toasts through the persistent singleton live regions.
|
|
284
|
-
//
|
|
285
|
-
//
|
|
286
|
-
// screen readers do not announce (see useAnnounce.ts); the singleton regions
|
|
287
|
-
// are mounted empty and only mutated afterwards, so they are what actually
|
|
288
|
-
// guarantees the announcement (the per-toast markup is kept for browse-mode
|
|
289
|
-
// discoverability). The announcement happens in addToast — the imperative
|
|
294
|
+
// Announce toasts through the persistent singleton live regions. They are
|
|
295
|
+
// mounted empty and only mutated afterwards, which screen readers announce
|
|
296
|
+
// (see useAnnounce.ts). The announcement happens in addToast — the imperative
|
|
290
297
|
// dispatch path invoked once per useToast() call from an event handler,
|
|
291
298
|
// never from render — so each toast is announced exactly once by
|
|
292
299
|
// construction, independent of the React render lifecycle (StrictMode
|
|
@@ -294,6 +301,12 @@ export function ToastViewport({
|
|
|
294
301
|
// re-renders never re-announce). It is client-only (addToast never runs
|
|
295
302
|
// during SSR), so it is SSR-safe.
|
|
296
303
|
const announce = useAnnounce();
|
|
304
|
+
// An open native modal hides the body-level channel above from assistive
|
|
305
|
+
// technology, so while the viewport is hosted in one, each card announces
|
|
306
|
+
// itself through its own live region instead. Outside a modal the cards
|
|
307
|
+
// carry none, so a card updated in place is announced once.
|
|
308
|
+
const hasModalOutlet = useSyncExternalStore(subscribeModalOutlets, hasActiveModalOutlet, hasNoModalOutlet);
|
|
309
|
+
const isModalHosted = isTopLayer && hasModalOutlet;
|
|
297
310
|
const addToast = useCallback(entry => {
|
|
298
311
|
const {
|
|
299
312
|
uniqueID,
|
|
@@ -326,7 +339,26 @@ export function ToastViewport({
|
|
|
326
339
|
if (overwritten && renderedToastsRef.current.includes(overwritten)) {
|
|
327
340
|
replacedRef.current.set(overwritten.id, overwritten);
|
|
328
341
|
}
|
|
329
|
-
|
|
342
|
+
// An overwrite of a toast that is not leaving keeps its row, so the card
|
|
343
|
+
// updates in place and focus inside it stays. A leaving namesake
|
|
344
|
+
// is replaced by a new row, which enters again.
|
|
345
|
+
const keepsRow = overwritten != null && !exitingIdsRef.current.has(overwritten.id);
|
|
346
|
+
const placed = keepsRow ? {
|
|
347
|
+
...entry,
|
|
348
|
+
rowKey: overwritten.rowKey ?? overwritten.id
|
|
349
|
+
} : entry;
|
|
350
|
+
if (keepsRow) {
|
|
351
|
+
// If the update removes the focused control, the commit hands focus
|
|
352
|
+
// off as a dismissal does.
|
|
353
|
+
const note = noteFocusWithin(viewportRef.current?.querySelector(`[data-toast-id="${overwritten.id}"]`));
|
|
354
|
+
if (note != null) {
|
|
355
|
+
overwriteFocusRef.current = {
|
|
356
|
+
id: placed.id,
|
|
357
|
+
note
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
const projected = overwritten ? committed.map(t => t === overwritten ? placed : t) : [...committed, placed];
|
|
330
362
|
// `maxVisible={0}` shows every toast (FR7): nothing leaves the window.
|
|
331
363
|
const firstVisible = maxVisible > 0 ? projected.length - maxVisible : 0;
|
|
332
364
|
const cutIds = new Set(projected.filter((t, i) => i < firstVisible && exitingIdsRef.current.has(t.id)).map(t => t.id));
|
|
@@ -349,7 +381,7 @@ export function ToastViewport({
|
|
|
349
381
|
}
|
|
350
382
|
}
|
|
351
383
|
}
|
|
352
|
-
pending.set(entry.id,
|
|
384
|
+
pending.set(entry.id, placed);
|
|
353
385
|
// An overwrite swaps a new entry, with a new id, into the replaced
|
|
354
386
|
// toast's place, so the old row leaves the DOM without ever being
|
|
355
387
|
// dismissed. Its settled id is dropped by the prune below, which covers
|
|
@@ -360,7 +392,7 @@ export function ToastViewport({
|
|
|
360
392
|
// replaced namesake as leaving since, which must not turn the
|
|
361
393
|
// overwrite into an append. An ignored collision already returned.
|
|
362
394
|
const kept = prev.filter(t => !cutIds.has(t.id));
|
|
363
|
-
return overwritten && kept.includes(overwritten) ? kept.map(t => t === overwritten ?
|
|
395
|
+
return overwritten && kept.includes(overwritten) ? kept.map(t => t === overwritten ? placed : t) : [...kept, placed];
|
|
364
396
|
});
|
|
365
397
|
}, [announce, maxVisible]);
|
|
366
398
|
const removeToast = useCallback((id, reason) => {
|
|
@@ -383,9 +415,15 @@ export function ToastViewport({
|
|
|
383
415
|
// focused before the user entered the viewport) rather than <body>.
|
|
384
416
|
const el = viewportRef.current;
|
|
385
417
|
const active = document.activeElement;
|
|
386
|
-
|
|
418
|
+
// A toast an overwrite replaced in place no longer owns its row: the
|
|
419
|
+
// replacement does, so dismissing the replaced toast leaves the row, and
|
|
420
|
+
// focus in it, to the replacement.
|
|
421
|
+
const rowKey = entry.rowKey ?? entry.id;
|
|
422
|
+
const isReplacedInPlace = !toastsRef.current.some(t => t.id === id) && toastsRef.current.some(t => t.rowKey === rowKey);
|
|
423
|
+
const dismissedNode = isReplacedInPlace ? null : el?.querySelector(`[data-toast-id="${id}"]`) ?? null;
|
|
387
424
|
if (dismissedNode && active instanceof Node && dismissedNode.contains(active)) {
|
|
388
425
|
focusHandoffIdRef.current = id;
|
|
426
|
+
dismissFocusNoteRef.current = noteFocusWithin(dismissedNode);
|
|
389
427
|
// Pick the toast to receive focus while the DOM is still intact: the
|
|
390
428
|
// nearest one after it, then before it, that shows once it is gone
|
|
391
429
|
// (FR10), else restore. The list may already run ahead of the render
|
|
@@ -441,6 +479,31 @@ export function ToastViewport({
|
|
|
441
479
|
setToasts(prev => prev.filter(t => t.id !== id));
|
|
442
480
|
}, []);
|
|
443
481
|
|
|
482
|
+
// Moves focus to a control in the target toast, else in another toast that
|
|
483
|
+
// shows (newest first), else back to the element focused before focus
|
|
484
|
+
// entered the viewport, so a handoff never drops focus to <body>.
|
|
485
|
+
const handOffFocus = useCallback((note, targetId) => {
|
|
486
|
+
const el = viewportRef.current;
|
|
487
|
+
const rowFor = id => el?.querySelector(`[data-toast-id="${id}"]`) ?? null;
|
|
488
|
+
const shownIds = toastsRef.current.slice(maxVisibleRef.current > 0 ? -maxVisibleRef.current : 0).map(t => t.id).reverse();
|
|
489
|
+
const candidates = targetId == null ? [] : [targetId, ...shownIds.filter(id => id !== targetId)];
|
|
490
|
+
let target = null;
|
|
491
|
+
for (const id of candidates) {
|
|
492
|
+
target = getFocusable(rowFor(id));
|
|
493
|
+
if (target != null) {
|
|
494
|
+
break;
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
const prev = prevFocusRef.current;
|
|
498
|
+
const isReturning = target == null && prev != null && prev.isConnected;
|
|
499
|
+
if (target == null) {
|
|
500
|
+
target = isReturning ? prev : el;
|
|
501
|
+
}
|
|
502
|
+
if (moveFocusLeftBehind(note, target) && isReturning) {
|
|
503
|
+
prevFocusRef.current = null;
|
|
504
|
+
}
|
|
505
|
+
}, [getFocusable]);
|
|
506
|
+
|
|
444
507
|
// After a dismissed toast unmounts, hand focus off so it never falls to
|
|
445
508
|
// <body>. Runs in a layout effect once the toast list no longer contains
|
|
446
509
|
// the dismissed toast.
|
|
@@ -456,25 +519,21 @@ export function ToastViewport({
|
|
|
456
519
|
}
|
|
457
520
|
focusHandoffIdRef.current = null;
|
|
458
521
|
pendingFocusRef.current = null;
|
|
459
|
-
const
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
const prev = prevFocusRef.current;
|
|
471
|
-
prevFocusRef.current = null;
|
|
472
|
-
if (prev && prev.isConnected) {
|
|
473
|
-
prev.focus();
|
|
474
|
-
} else if (el) {
|
|
475
|
-
el.focus();
|
|
522
|
+
const note = dismissFocusNoteRef.current;
|
|
523
|
+
dismissFocusNoteRef.current = null;
|
|
524
|
+
handOffFocus(note, target === 'restore' ? null : target);
|
|
525
|
+
}, [toasts, handOffFocus]);
|
|
526
|
+
|
|
527
|
+
// After an overwrite updated a row that held focus: focus stays on the same
|
|
528
|
+
// control, or, if the update removed it, moves as a dismissal hands it off.
|
|
529
|
+
useLayoutEffect(() => {
|
|
530
|
+
const overwrite = overwriteFocusRef.current;
|
|
531
|
+
if (overwrite == null) {
|
|
532
|
+
return;
|
|
476
533
|
}
|
|
477
|
-
|
|
534
|
+
overwriteFocusRef.current = null;
|
|
535
|
+
handOffFocus(overwrite.note, overwrite.id);
|
|
536
|
+
}, [toasts, handOffFocus]);
|
|
478
537
|
const findByUniqueID = useCallback(uid => {
|
|
479
538
|
return toastsRef.current.find(t => t.options.uniqueID === uid);
|
|
480
539
|
}, []);
|
|
@@ -663,8 +722,9 @@ export function ToastViewport({
|
|
|
663
722
|
isExiting: exitingIds.has(entry.id),
|
|
664
723
|
isReversed: isReversed,
|
|
665
724
|
onExited: handleExited,
|
|
666
|
-
onDismiss: removeToast
|
|
667
|
-
|
|
725
|
+
onDismiss: removeToast,
|
|
726
|
+
isLiveRegion: isModalHosted
|
|
727
|
+
}, entry.rowKey ?? entry.id))
|
|
668
728
|
})
|
|
669
729
|
});
|
|
670
730
|
return /*#__PURE__*/_jsxs(ToastContext, {
|
package/dist/Toast/types.d.ts
CHANGED
|
@@ -31,9 +31,10 @@ export interface ToastOptions {
|
|
|
31
31
|
/**
|
|
32
32
|
* Replaces the content of this toast's card with your own layout.
|
|
33
33
|
*
|
|
34
|
-
* Astryx keeps the card
|
|
35
|
-
* the
|
|
36
|
-
*
|
|
34
|
+
* Astryx keeps the card and its auto-hide behavior (inside a
|
|
35
|
+
* `ToastViewport` the viewport announces the toast, and while a modal hosts
|
|
36
|
+
* the viewport the card announces itself), then hands the
|
|
37
|
+
* renderer this toast's content, resolved settings and `dismiss` callback. The renderer owns every control inside its layout; call
|
|
37
38
|
* `dismiss` from the control that should close the toast. Astryx does not
|
|
38
39
|
* inject a fallback control into custom content.
|
|
39
40
|
*
|
|
@@ -85,5 +86,10 @@ export interface ToastEntry {
|
|
|
85
86
|
id: string;
|
|
86
87
|
options: ToastOptions;
|
|
87
88
|
createdAt: number;
|
|
89
|
+
/**
|
|
90
|
+
* The row's identity in the stack. A uniqueID overwrite keeps the replaced
|
|
91
|
+
* toast's, so the card updates in place and focus inside it stays.
|
|
92
|
+
*/
|
|
93
|
+
rowKey?: string;
|
|
88
94
|
}
|
|
89
95
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/Toast/types.ts"],"names":[],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
|
|
|
12
12
|
* - /apps/storybook/stories/Token.stories.tsx (storybook stories)
|
|
13
13
|
* - /packages/cli/assets/templates/blocks/components/Token/ (showcase blocks)
|
|
14
14
|
*/
|
|
15
|
-
import type
|
|
15
|
+
import { type ReactNode } from 'react';
|
|
16
16
|
import type { BaseProps } from '../BaseProps.js';
|
|
17
17
|
import type { TokenColorMap } from './index.js';
|
|
18
18
|
/**
|
|
@@ -95,7 +95,7 @@ export interface TokenProps extends BaseProps<HTMLElement> {
|
|
|
95
95
|
* <Token label="Link" href="/path" />
|
|
96
96
|
* ```
|
|
97
97
|
*/
|
|
98
|
-
export declare function Token({ label, size, color, icon, isDisabled, onRemove, onClick, href, description, endContent, isLabelHidden, xstyle, className, style, 'data-testid': testId, 'aria-labelledby': ariaLabelledBy, 'aria-describedby': ariaDescribedBy, ref, ...rest }: TokenProps): import("react").JSX.Element;
|
|
98
|
+
export declare function Token({ label, size, color, icon, isDisabled, onRemove, onClick, href, description, endContent, isLabelHidden, xstyle, className, style, 'data-testid': testId, 'aria-labelledby': ariaLabelledBy, 'aria-describedby': ariaDescribedBy, 'aria-haspopup': ariaHasPopup, 'aria-expanded': ariaExpanded, ref, ...rest }: TokenProps): import("react").JSX.Element;
|
|
99
99
|
export declare namespace Token {
|
|
100
100
|
var displayName: string;
|
|
101
101
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Token.d.ts","sourceRoot":"","sources":["../../src/Token/Token.tsx"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"Token.d.ts","sourceRoot":"","sources":["../../src/Token/Token.tsx"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAM,KAAK,SAAS,EAAC,MAAM,OAAO,CAAC;AAiB1C,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,cAAc,CAAC;AAK5C,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,SA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Ae,EAAE,YAAY,EAC7B,GAAG,EACH,GAAG,IAAI,EACR,EAAE,UAAU,+BA8QZ;yBApSe,KAAK"}
|
package/dist/Token/Token.js
CHANGED
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
* - /apps/storybook/stories/Token.stories.tsx (storybook stories)
|
|
17
17
|
* - /packages/cli/assets/templates/blocks/components/Token/ (showcase blocks)
|
|
18
18
|
*/
|
|
19
|
+
import { use } from 'react';
|
|
19
20
|
import * as stylex from '@stylexjs/stylex';
|
|
20
21
|
import "../theme/tokens.stylex.js";
|
|
21
22
|
import { colorVars, spacingVars, radiusVars, sizeVars, durationVars, easeVars, fontWeightVars, typeScaleVars } from "../theme/tokens.stylex.js";
|
|
@@ -29,6 +30,7 @@ import { focusOutlineProps } from "../utils/focusOutline.stylex.js";
|
|
|
29
30
|
import { interactionOverlayStyles } from "../utils/interactionOverlay.stylex.js";
|
|
30
31
|
import { usePressFeedback } from "../hooks/usePressFeedback.js";
|
|
31
32
|
import { disabledInteractionProps } from "../utils/disabledInteraction.js";
|
|
33
|
+
import { TokenNamingContext } from "./TokenNamingContext.js";
|
|
32
34
|
import { registerEnglishFallback, useComponentTranslator } from "../i18n/useComponentTranslator.js";
|
|
33
35
|
import english from "../i18n/generated-english/Token/Token.generated.js";
|
|
34
36
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
@@ -216,6 +218,8 @@ export function Token({
|
|
|
216
218
|
'data-testid': testId,
|
|
217
219
|
'aria-labelledby': ariaLabelledBy,
|
|
218
220
|
'aria-describedby': ariaDescribedBy,
|
|
221
|
+
'aria-haspopup': ariaHasPopup,
|
|
222
|
+
'aria-expanded': ariaExpanded,
|
|
219
223
|
ref,
|
|
220
224
|
...rest
|
|
221
225
|
}) {
|
|
@@ -230,6 +234,7 @@ export function Token({
|
|
|
230
234
|
onClick,
|
|
231
235
|
isDisabled
|
|
232
236
|
});
|
|
237
|
+
const naming = use(TokenNamingContext);
|
|
233
238
|
|
|
234
239
|
// When role is 'button' via context (no explicit onClick), treat as
|
|
235
240
|
// if onClick was provided — the popover attaches its own handler.
|
|
@@ -237,7 +242,7 @@ export function Token({
|
|
|
237
242
|
const removeButton = onRemove != null && /*#__PURE__*/_jsx("button", {
|
|
238
243
|
type: "button",
|
|
239
244
|
"aria-label": t('@astryx.token.remove', {
|
|
240
|
-
label
|
|
245
|
+
label: naming?.removeName ?? label
|
|
241
246
|
}),
|
|
242
247
|
onClick: e => {
|
|
243
248
|
e.stopPropagation();
|
|
@@ -268,12 +273,14 @@ export function Token({
|
|
|
268
273
|
}), endContent, removeButton]
|
|
269
274
|
});
|
|
270
275
|
|
|
271
|
-
// Naming inputs reach the element that owns the token's action:
|
|
272
|
-
// button of a clickable token, otherwise the root
|
|
276
|
+
// Naming and popup inputs reach the element that owns the token's action:
|
|
277
|
+
// the inner button of a clickable token, otherwise the root
|
|
273
278
|
// (architecture:public-component-api INV5).
|
|
274
279
|
const labellingProps = {
|
|
275
280
|
'aria-labelledby': ariaLabelledBy,
|
|
276
|
-
'aria-describedby': ariaDescribedBy
|
|
281
|
+
'aria-describedby': ariaDescribedBy,
|
|
282
|
+
'aria-haspopup': ariaHasPopup,
|
|
283
|
+
'aria-expanded': ariaExpanded
|
|
277
284
|
};
|
|
278
285
|
const sharedProps = {
|
|
279
286
|
'data-testid': testId,
|
|
@@ -398,6 +405,7 @@ export function Token({
|
|
|
398
405
|
children: [icon, /*#__PURE__*/_jsx("button", {
|
|
399
406
|
type: "button",
|
|
400
407
|
onClick: effectiveOnClick,
|
|
408
|
+
"aria-label": ariaLabelledBy == null ? naming?.actionName : undefined,
|
|
401
409
|
...labellingProps,
|
|
402
410
|
"aria-disabled": isDisabled || undefined,
|
|
403
411
|
...(isDisabled ? disabledInteractionProps() : null),
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Names for a Token whose visible text runs past its label. PowerSearch
|
|
3
|
+
* provides them: its tokens show the value as `endContent`.
|
|
4
|
+
*
|
|
5
|
+
* - `actionName` names a clickable token's inner button in place of `label`.
|
|
6
|
+
* - `removeName` names the remove button in place of `label`. The remove word
|
|
7
|
+
* still comes from the catalog, so each locale keeps its word order.
|
|
8
|
+
*/
|
|
9
|
+
export interface TokenNaming {
|
|
10
|
+
actionName?: string;
|
|
11
|
+
removeName?: string;
|
|
12
|
+
}
|
|
13
|
+
export declare const TokenNamingContext: import("react").Context<TokenNaming | null>;
|
|
14
|
+
//# sourceMappingURL=TokenNamingContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TokenNamingContext.d.ts","sourceRoot":"","sources":["../../src/Token/TokenNamingContext.ts"],"names":[],"mappings":"AAaA;;;;;;;GAOG;AACH,MAAM,WAAW,WAAW;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,eAAO,MAAM,kBAAkB,6CAA0C,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
'use client';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @file TokenNamingContext.ts
|
|
7
|
+
* @input Naming parts from a caller whose token value renders outside its label
|
|
8
|
+
* @output Internal context: the names of a token's action and remove button
|
|
9
|
+
* @position Internal to Core; not exported from the Token entry point
|
|
10
|
+
*/
|
|
11
|
+
import { createContext } from 'react';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Names for a Token whose visible text runs past its label. PowerSearch
|
|
15
|
+
* provides them: its tokens show the value as `endContent`.
|
|
16
|
+
*
|
|
17
|
+
* - `actionName` names a clickable token's inner button in place of `label`.
|
|
18
|
+
* - `removeName` names the remove button in place of `label`. The remove word
|
|
19
|
+
* still comes from the catalog, so each locale keeps its word order.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
export const TokenNamingContext = /*#__PURE__*/createContext(null);
|
|
23
|
+
TokenNamingContext.displayName = 'TokenNamingContext';
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @file useTooltip.tsx
|
|
3
3
|
* @input Uses useLayer, usePressPin, React hooks
|
|
4
|
-
* @output Exports useTooltip hook with stable trigger refs for hover/focus/tap tooltips
|
|
4
|
+
* @output Exports useTooltip hook with stable trigger refs for hover/focus/tap tooltips
|
|
5
|
+
* and imperative show() and hide() for an app-built toggle trigger,
|
|
5
6
|
* and the module-only useTooltipWithTriggerBehavior that InfoTip's press-to-pin uses
|
|
6
7
|
* @position Layer hook; builds on useLayer for tooltip behavior
|
|
7
8
|
*
|
|
@@ -133,6 +134,23 @@ export interface TooltipReturn {
|
|
|
133
134
|
* silent no-op.
|
|
134
135
|
*/
|
|
135
136
|
renderTooltip: (children: ReactNode, props?: Omit<ContextRenderProps, 'positioning'>) => ReactNode;
|
|
137
|
+
/**
|
|
138
|
+
* Opens the tooltip now and keeps it open until `hide()`, Escape, a press
|
|
139
|
+
* outside, or focus leaving its trigger, as a pinned tooltip does. Its text
|
|
140
|
+
* is announced once. Reports through `onShow`. Under a controlled `isOpen`,
|
|
141
|
+
* it calls `onShow` and does not change `isOpen`. Does nothing while
|
|
142
|
+
* `isEnabled` is false.
|
|
143
|
+
*
|
|
144
|
+
* Use `show()` and `hide()` to build a toggle-style trigger: your own button
|
|
145
|
+
* calls them, sets `aria-describedby` and `aria-controls` to `describedBy`
|
|
146
|
+
* and `aria-expanded` (true while shown), and keeps its own accessible name.
|
|
147
|
+
*/
|
|
148
|
+
show: () => void;
|
|
149
|
+
/**
|
|
150
|
+
* Closes the tooltip now. Reports through `onHide`. Under a controlled
|
|
151
|
+
* `isOpen`, it calls `onHide` and does not change `isOpen`.
|
|
152
|
+
*/
|
|
153
|
+
hide: () => void;
|
|
136
154
|
}
|
|
137
155
|
/**
|
|
138
156
|
* Hook for tooltip behavior with hover/focus triggers.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTooltip.d.ts","sourceRoot":"","sources":["../../src/Tooltip/useTooltip.tsx"],"names":[],"mappings":"AAIA
|
|
1
|
+
{"version":3,"file":"useTooltip.d.ts","sourceRoot":"","sources":["../../src/Tooltip/useTooltip.tsx"],"names":[],"mappings":"AAIA;;;;;;;;;;GAUG;AAEH,OAAO,EAKL,KAAK,SAAS,EACd,KAAK,WAAW,EACjB,MAAM,OAAO,CAAC;AAGf,OAAO,EAEL,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACnB,KAAK,cAAc,EACpB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,0BAA0B,CAAC;AAKhE,OAAO,EAAc,KAAK,oBAAoB,EAAC,MAAM,sBAAsB,CAAC;AA0C5E;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG,MAAM,GAAG,QAAQ,GAAG,OAAO,CAAC;AAE9D;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG,iBAAiB,CAAC;AAEpD,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH,SAAS,CAAC,EAAE,cAAc,CAAC;IAE3B;;;OAGG;IACH,SAAS,CAAC,EAAE,cAAc,CAAC;IAE3B;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;;;;;;OAQG;IACH,YAAY,CAAC,EAAE,mBAAmB,CAAC;IAEnC;;;;;;;;;OASG;IACH,YAAY,CAAC,EAAE,mBAAmB,CAAC;IAEnC;;;;;OAKG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IAEpB;;;;;;;;;;OAUG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IAEjB;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IAExB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;IAEpB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;CACrB;AAED,MAAM,WAAW,aAAa;IAC5B;;;OAGG;IACH,GAAG,EAAE,WAAW,CAAC,WAAW,CAAC,CAAC;IAE9B;;;OAGG;IACH,WAAW,EAAE,WAAW,CAAC,WAAW,CAAC,CAAC;IAEtC;;;;OAIG;IACH,cAAc,EAAE,WAAW,CAAC,WAAW,CAAC,CAAC;IAEzC;;;OAGG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;;OAGG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;;;;;;OAOG;IACH,aAAa,EAAE,CACb,QAAQ,EAAE,SAAS,EACnB,KAAK,CAAC,EAAE,IAAI,CAAC,kBAAkB,EAAE,aAAa,CAAC,KAC5C,SAAS,CAAC;IAEf;;;;;;;;;;OAUG;IACH,IAAI,EAAE,MAAM,IAAI,CAAC;IAEjB;;;OAGG;IACH,IAAI,EAAE,MAAM,IAAI,CAAC;CAClB;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,wBAAgB,UAAU,CAAC,OAAO,GAAE,cAAmB,GAAG,aAAa,CAOtE;AAED;;;GAGG;AACH,MAAM,WAAW,iCAAkC,SAAQ,cAAc;IACvE;;;;;;;;;;;;OAYG;IACH,eAAe,CAAC,EAAE,oBAAoB,CAAC;CACxC;AAED;;;GAGG;AACH,wBAAgB,6BAA6B,CAC3C,OAAO,GAAE,iCAAsC,GAC9C,aAAa,CA2df"}
|
|
@@ -5,14 +5,16 @@
|
|
|
5
5
|
/**
|
|
6
6
|
* @file useTooltip.tsx
|
|
7
7
|
* @input Uses useLayer, usePressPin, React hooks
|
|
8
|
-
* @output Exports useTooltip hook with stable trigger refs for hover/focus/tap tooltips
|
|
8
|
+
* @output Exports useTooltip hook with stable trigger refs for hover/focus/tap tooltips
|
|
9
|
+
* and imperative show() and hide() for an app-built toggle trigger,
|
|
9
10
|
* and the module-only useTooltipWithTriggerBehavior that InfoTip's press-to-pin uses
|
|
10
11
|
* @position Layer hook; builds on useLayer for tooltip behavior
|
|
11
12
|
*
|
|
12
13
|
* SYNC: When modified, update:
|
|
13
14
|
* - /packages/core/src/Tooltip/index.ts
|
|
14
15
|
*/
|
|
15
|
-
import { useCallback, useEffect, useRef } from 'react';
|
|
16
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
17
|
+
import { createTriggerFocusGate } from "../utils/triggerFocus.js";
|
|
16
18
|
import * as stylex from '@stylexjs/stylex';
|
|
17
19
|
import { useLayerInternal } from "../Layer/useLayer.js";
|
|
18
20
|
import { useAnnounceRenderedText } from "../hooks/useAnnounceRenderedText.js";
|
|
@@ -52,28 +54,6 @@ const styles = {
|
|
|
52
54
|
* Touch trigger behavior for tooltips
|
|
53
55
|
*/
|
|
54
56
|
|
|
55
|
-
/**
|
|
56
|
-
* Check if an element is naturally focusable
|
|
57
|
-
*/
|
|
58
|
-
function isFocusable(element) {
|
|
59
|
-
// Elements with explicit tabindex
|
|
60
|
-
if (element.hasAttribute('tabindex')) {
|
|
61
|
-
return element.tabIndex >= 0;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// Naturally focusable elements
|
|
65
|
-
const focusableTags = ['A', 'BUTTON', 'INPUT', 'SELECT', 'TEXTAREA'];
|
|
66
|
-
if (focusableTags.includes(element.tagName)) {
|
|
67
|
-
return !element.disabled;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// Elements with contenteditable
|
|
71
|
-
if (element.isContentEditable) {
|
|
72
|
-
return true;
|
|
73
|
-
}
|
|
74
|
-
return false;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
57
|
/**
|
|
78
58
|
* Hook for tooltip behavior with hover/focus triggers.
|
|
79
59
|
*
|
|
@@ -187,6 +167,9 @@ export function useTooltipWithTriggerBehavior(options = {}) {
|
|
|
187
167
|
isHeldOpen: isPressHeldOpen,
|
|
188
168
|
attach: attachPressPin,
|
|
189
169
|
unpin: unpinPress,
|
|
170
|
+
hold: holdPress,
|
|
171
|
+
release: releasePress,
|
|
172
|
+
isAppHeld,
|
|
190
173
|
isPinShown,
|
|
191
174
|
touch: {
|
|
192
175
|
isTouchPointerRef,
|
|
@@ -289,25 +272,11 @@ export function useTooltipWithTriggerBehavior(options = {}) {
|
|
|
289
272
|
scheduleHide();
|
|
290
273
|
}, [isTouchPointerRef, layerId, scheduleHide]);
|
|
291
274
|
|
|
292
|
-
// Under `auto`, whether focus counts is decided when it arrives,
|
|
293
|
-
//
|
|
294
|
-
|
|
295
|
-
// by definition; focus inside it counts only while the trigger is
|
|
296
|
-
// focusable too, so a plain wrapper still ignores its children's focus.
|
|
297
|
-
const isFocusForTrigger = useCallback(e => {
|
|
298
|
-
if (focusTrigger === 'always') {
|
|
299
|
-
return true;
|
|
300
|
-
}
|
|
301
|
-
const triggerEl = e.currentTarget;
|
|
302
|
-
return triggerEl != null && (e.target === triggerEl || isFocusable(triggerEl));
|
|
303
|
-
}, [focusTrigger]);
|
|
304
|
-
|
|
305
|
-
// Whether the trigger's current focus counted when it arrived, so its blur
|
|
306
|
-
// hides the tooltip even if the trigger has since left the tab order.
|
|
307
|
-
const focusCountedRef = useRef(false);
|
|
275
|
+
// Under `auto`, whether focus counts is decided when it arrives, and a
|
|
276
|
+
// focus that counted still hides on blur (utils/triggerFocus.ts).
|
|
277
|
+
const [focusGate] = useState(createTriggerFocusGate);
|
|
308
278
|
const handleFocusIn = useCallback(e => {
|
|
309
|
-
|
|
310
|
-
if (!isEnabled || !focusCountedRef.current) {
|
|
279
|
+
if (!focusGate.focusIn(e, focusTrigger) || !isEnabled) {
|
|
311
280
|
return;
|
|
312
281
|
}
|
|
313
282
|
// A tap focuses the trigger it activates, and `:focus-visible` does not
|
|
@@ -326,18 +295,17 @@ export function useTooltipWithTriggerBehavior(options = {}) {
|
|
|
326
295
|
}
|
|
327
296
|
clearTimeouts();
|
|
328
297
|
showLayer();
|
|
329
|
-
}, [
|
|
298
|
+
}, [focusGate, focusTrigger, isEnabled, isTouchInteraction, clearTimeouts, showLayer]);
|
|
330
299
|
|
|
331
300
|
// A pinned tooltip's focus-leave close is the pin's own: it listens on the
|
|
332
301
|
// trigger whatever `focusTrigger` is. This schedules the unpinned hide,
|
|
333
302
|
// which a held tooltip skips.
|
|
334
303
|
const handleFocusOut = useCallback(e => {
|
|
335
|
-
if (!
|
|
304
|
+
if (!focusGate.focusOut(e, focusTrigger)) {
|
|
336
305
|
return;
|
|
337
306
|
}
|
|
338
|
-
focusCountedRef.current = false;
|
|
339
307
|
scheduleHide();
|
|
340
|
-
}, [
|
|
308
|
+
}, [focusGate, focusTrigger, scheduleHide]);
|
|
341
309
|
|
|
342
310
|
// Pressing the trigger hides its own tooltip: once the control is activated
|
|
343
311
|
// the hint has served its purpose, and a tooltip lingering over a
|
|
@@ -347,9 +315,10 @@ export function useTooltipWithTriggerBehavior(options = {}) {
|
|
|
347
315
|
// A touch press is a different gesture (it may be the only way to open the
|
|
348
316
|
// tooltip at all), so the touch path answers it first.
|
|
349
317
|
const handlePointerDown = useCallback(event => {
|
|
350
|
-
// A
|
|
351
|
-
//
|
|
352
|
-
|
|
318
|
+
// A toggle trigger's press pins or closes through its click. The app's
|
|
319
|
+
// hide() closes a held tooltip. Neither path hides here or waits for a
|
|
320
|
+
// tap verdict.
|
|
321
|
+
if (isToggleTrigger(triggerRef.current) || isAppHeld()) {
|
|
353
322
|
return;
|
|
354
323
|
}
|
|
355
324
|
if (handleTouchPointerDown(event)) {
|
|
@@ -360,7 +329,7 @@ export function useTooltipWithTriggerBehavior(options = {}) {
|
|
|
360
329
|
}
|
|
361
330
|
clearTimeouts();
|
|
362
331
|
hideLayer();
|
|
363
|
-
}, [isToggleTrigger, handleTouchPointerDown, isOpen, clearTimeouts, hideLayer]);
|
|
332
|
+
}, [isToggleTrigger, isAppHeld, handleTouchPointerDown, isOpen, clearTimeouts, hideLayer]);
|
|
364
333
|
|
|
365
334
|
// Interaction ref that handles event listeners only
|
|
366
335
|
const interactionRef = useCallback(el => {
|
|
@@ -384,7 +353,7 @@ export function useTooltipWithTriggerBehavior(options = {}) {
|
|
|
384
353
|
el.addEventListener('pointerdown', handlePointerDown);
|
|
385
354
|
|
|
386
355
|
// Focus listeners unless focus never opens the tooltip; `auto` decides
|
|
387
|
-
// per event (
|
|
356
|
+
// per event (utils/triggerFocus.ts).
|
|
388
357
|
if (focusTrigger !== 'never') {
|
|
389
358
|
el.addEventListener('focusin', handleFocusIn);
|
|
390
359
|
el.addEventListener('focusout', handleFocusOut);
|
|
@@ -425,9 +394,11 @@ export function useTooltipWithTriggerBehavior(options = {}) {
|
|
|
425
394
|
showLayer();
|
|
426
395
|
} else {
|
|
427
396
|
clearTimeouts();
|
|
397
|
+
// A pin or app hold ends when the consumer closes the tooltip.
|
|
398
|
+
unpinPress();
|
|
428
399
|
hideLayer();
|
|
429
400
|
}
|
|
430
|
-
}, [isOpen, clearTimeouts, showLayer, hideLayer]);
|
|
401
|
+
}, [isOpen, clearTimeouts, showLayer, hideLayer, unpinPress]);
|
|
431
402
|
|
|
432
403
|
// Dismiss on Escape (WCAG 1.4.13 — dismissible) through the shared layer
|
|
433
404
|
// stack. A visible tip is the top-most layer, so it takes the press and
|
|
@@ -507,12 +478,22 @@ export function useTooltipWithTriggerBehavior(options = {}) {
|
|
|
507
478
|
children: children
|
|
508
479
|
}), renderProps);
|
|
509
480
|
}, [renderLayer, placement, alignment, popoverXstyle, cancelHide, scheduleHide, contentRefs]);
|
|
481
|
+
const show = useCallback(() => {
|
|
482
|
+
clearTimeouts();
|
|
483
|
+
holdPress();
|
|
484
|
+
}, [clearTimeouts, holdPress]);
|
|
485
|
+
const hide = useCallback(() => {
|
|
486
|
+
clearTimeouts();
|
|
487
|
+
releasePress();
|
|
488
|
+
}, [clearTimeouts, releasePress]);
|
|
510
489
|
return {
|
|
511
490
|
ref,
|
|
512
491
|
positionRef: layerRef,
|
|
513
492
|
interactionRef,
|
|
514
493
|
anchorId: layerAnchorId,
|
|
515
494
|
describedBy: layerId,
|
|
516
|
-
renderTooltip
|
|
495
|
+
renderTooltip,
|
|
496
|
+
show,
|
|
497
|
+
hide
|
|
517
498
|
};
|
|
518
499
|
}
|
|
@@ -31,7 +31,8 @@ export interface TypeaheadItemProps<T extends SearchableItem = SearchableItem> e
|
|
|
31
31
|
*/
|
|
32
32
|
isDisabled?: boolean;
|
|
33
33
|
/**
|
|
34
|
-
*
|
|
34
|
+
* This prop has no effect. Set `item.auxiliaryData.group` on search-source
|
|
35
|
+
* items to group results in Typeahead or BaseTypeahead.
|
|
35
36
|
*/
|
|
36
37
|
group?: string;
|
|
37
38
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TypeaheadItem.d.ts","sourceRoot":"","sources":["../../src/Typeahead/TypeaheadItem.tsx"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,EAAC,KAAK,SAAS,EAAC,MAAM,OAAO,CAAC;AAQ5C,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,cAAc,CAAC;AAQ5C,MAAM,WAAW,kBAAkB,CACjC,CAAC,SAAS,cAAc,GAAG,cAAc,CACzC,SAAQ,SAAS,CAAC,cAAc,CAAC;IACjC,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;IAChC;;OAEG;IACH,IAAI,EAAE,CAAC,CAAC;IAER;;OAEG;IACH,IAAI,CAAC,EAAE,SAAS,CAAC;IAEjB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;;OAGG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IAErB
|
|
1
|
+
{"version":3,"file":"TypeaheadItem.d.ts","sourceRoot":"","sources":["../../src/Typeahead/TypeaheadItem.tsx"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,EAAC,KAAK,SAAS,EAAC,MAAM,OAAO,CAAC;AAQ5C,OAAO,KA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