@astryxdesign/core 0.7.6-canary.786c16e → 0.7.6-canary.8d0a847
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/Item/Item.d.ts.map +1 -1
- package/dist/Item/Item.js +19 -6
- package/dist/NavMenu/NavHeadingMenuItem.d.ts.map +1 -1
- package/dist/NavMenu/NavHeadingMenuItem.js +5 -29
- package/dist/SideNav/SideNavItem.d.ts +2 -2
- package/dist/SideNav/SideNavItem.d.ts.map +1 -1
- package/dist/SideNav/SideNavItem.js +18 -7
- package/dist/TreeList/TreeListItem.d.ts.map +1 -1
- package/dist/TreeList/TreeListItem.js +27 -4
- package/dist/utils/useFocusAcrossSwap.d.ts +19 -0
- package/dist/utils/useFocusAcrossSwap.d.ts.map +1 -0
- package/dist/utils/useFocusAcrossSwap.js +41 -0
- package/package.json +4 -4
- package/src/Chat/ChatComposer.spec.md +75 -59
- package/src/Item/Item.test.tsx +60 -0
- package/src/Item/Item.tsx +14 -7
- package/src/NavMenu/NavHeadingMenuItem.tsx +5 -39
- package/src/Resizable/Resizable.spec.md +144 -124
- package/src/SideNav/SideNav.test.tsx +124 -4
- package/src/SideNav/SideNavItem.spec.md +14 -24
- package/src/SideNav/SideNavItem.tsx +27 -10
- package/src/TreeList/TreeList.test.tsx +26 -0
- package/src/TreeList/TreeListItem.tsx +26 -4
- package/src/utils/useFocusAcrossSwap.ts +55 -0
package/dist/Item/Item.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Item.d.ts","sourceRoot":"","sources":["../../src/Item/Item.tsx"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,EAOL,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AAUf,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"Item.d.ts","sourceRoot":"","sources":["../../src/Item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AAC;CACxB;AAiQD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,IAAI,CAAC,EACnB,EAAE,EAAE,SAAiB,EACrB,MAAM,EACN,YAAY,EACZ,KAAK,EACL,WAAW,EACX,UAAU,EACV,KAAgB,EAChB,OAAoB,EACpB,UAAU,EACV,gBAAgB,EAChB,MAAkB,EAClB,OAAO,EACP,cAAc,EACd,IAAI,EACJ,MAAM,EAAE,eAAe,EACvB,GAAG,EAAE,YAAY,EACjB,aAAqB,EACrB,UAAkB,EAClB,UAAkB,EAClB,YAAY,EACZ,aAAwB,EACxB,MAAM,EACN,SAAS,EACT,KAAK,EACL,GAAG,EACH,IAAI,EACJ,GAAG,SAAS,EACb,EAAE,SAAS,+BA+VX;yBA3Xe,IAAI"}
|
package/dist/Item/Item.js
CHANGED
|
@@ -34,6 +34,7 @@ import "../theme/tokens.stylex.js";
|
|
|
34
34
|
import { colorVars, radiusVars, spacingVars, durationVars, easeVars, typeScaleVars } from "../theme/tokens.stylex.js";
|
|
35
35
|
import { isRenderable } from "../utils/isRenderable.js";
|
|
36
36
|
import { mergeProps } from "../utils/mergeProps.js";
|
|
37
|
+
import { useFocusAcrossSwap } from "../utils/useFocusAcrossSwap.js";
|
|
37
38
|
import { ItemDescriptionContext } from "./ItemDescriptionContext.js";
|
|
38
39
|
import { ItemMarkerColumnsContext } from "./ItemMarkerColumnsContext.js";
|
|
39
40
|
import { useMergedRefs } from "../hooks/useMergedRefs.js";
|
|
@@ -274,6 +275,13 @@ export function Item({
|
|
|
274
275
|
const pressable = usePressFeedback();
|
|
275
276
|
const columnMarker = use(ItemMarkerColumnsContext);
|
|
276
277
|
const LinkComponent = useLinkComponent();
|
|
278
|
+
// A disabled row's anchor has no destination, so no activation path (a
|
|
279
|
+
// screen reader's click, Enter, a link context menu) can navigate
|
|
280
|
+
// (spec:AST-085 FR2). Like a disabled Link, it keeps the link role and skips
|
|
281
|
+
// the router link component, which may require a live href. The element type
|
|
282
|
+
// then changes with `isDisabled`, so focus follows the swap (FR4).
|
|
283
|
+
const RowAnchor = isDisabled ? 'a' : LinkComponent;
|
|
284
|
+
const anchorRef = useFocusAcrossSwap();
|
|
277
285
|
|
|
278
286
|
// Delegation mode: the row is an enlarged click/tap target for a nested
|
|
279
287
|
// control (e.g. a checkbox) that owns the keyboard access and action. The
|
|
@@ -399,12 +407,17 @@ export function Item({
|
|
|
399
407
|
}
|
|
400
408
|
}[!!isInline << 1 | !!isDisabled << 0],
|
|
401
409
|
children: labelAndDescription
|
|
402
|
-
}) : href != null && !isLinkRoot ? /*#__PURE__*/_jsx(
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
410
|
+
}) : href != null && !isLinkRoot ? /*#__PURE__*/_jsx(RowAnchor, {
|
|
411
|
+
ref: anchorRef,
|
|
412
|
+
...(isDisabled ? {
|
|
413
|
+
role: 'link',
|
|
414
|
+
'aria-disabled': true,
|
|
415
|
+
tabIndex: -1
|
|
416
|
+
} : {
|
|
417
|
+
href,
|
|
418
|
+
target,
|
|
419
|
+
rel
|
|
420
|
+
}),
|
|
408
421
|
...{
|
|
409
422
|
0: {
|
|
410
423
|
className: "xmper1u x16khyan x1heor9g x78zum5 xdt5ytf x98rzlu xeuugli x1yc453h x1hl2dhg x1a2a7pz"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NavHeadingMenuItem.d.ts","sourceRoot":"","sources":["../../src/NavMenu/NavHeadingMenuItem.tsx"],"names":[],"mappings":"AAIA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"NavHeadingMenuItem.d.ts","sourceRoot":"","sources":["../../src/NavMenu/NavHeadingMenuItem.tsx"],"names":[],"mappings":"AAIA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,EAAc,KAAK,SAAS,EAAC,MAAM,OAAO,CAAC;AAEzD,OAAO,EAAiB,KAAK,QAAQ,EAAC,MAAM,SAAS,CAAC;AAWtD,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,cAAc,CAAC;AA+D5C,MAAM,WAAW,uBAAwB,SAAQ,IAAI,CACnD,SAAS,CAAC,WAAW,CAAC,EACtB,SAAS,CACV;IACC,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IAC7B,wCAAwC;IACxC,IAAI,CAAC,EAAE,SAAS,GAAG,QAAQ,CAAC;IAC5B,0BAA0B;IAC1B,KAAK,EAAE,SAAS,CAAC;IACjB,4DAA4D;IAC5D,WAAW,CAAC,EAAE,SAAS,CAAC;IACxB,sEAAsE;IACtE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,0CAA0C;IAC1C,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,mDAAmD;IACnD,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,kBAAkB,CAAC,EACjC,GAAG,EACH,IAAI,EACJ,KAAK,EACL,WAAW,EACX,IAAI,EACJ,OAAO,EACP,UAAkB,EAClB,MAAM,EACN,SAAS,EACT,KAAK,EACL,aAAa,EAAE,MAAM,EACrB,GAAG,SAAS,EACb,EAAE,uBAAuB,qBAqEzB;yBAlFe,kBAAkB"}
|
|
@@ -11,13 +11,14 @@
|
|
|
11
11
|
* SYNC: When modified, update:
|
|
12
12
|
* - /packages/core/src/NavMenu/index.ts
|
|
13
13
|
*/
|
|
14
|
-
import React, { useCallback
|
|
14
|
+
import React, { useCallback } from 'react';
|
|
15
15
|
import * as stylex from '@stylexjs/stylex';
|
|
16
16
|
import { renderIconSlot } from "../Icon/index.js";
|
|
17
17
|
import { Text } from "../Text/index.js";
|
|
18
18
|
import "../theme/tokens.stylex.js";
|
|
19
19
|
import { colorVars, spacingVars, typographyVars, typeScaleVars, radiusVars } from "../theme/tokens.stylex.js";
|
|
20
|
-
import { mergeProps
|
|
20
|
+
import { mergeProps } from "../utils/mergeProps.js";
|
|
21
|
+
import { useFocusAcrossSwap } from "../utils/useFocusAcrossSwap.js";
|
|
21
22
|
import { useNavHeadingMenuContext } from "./NavMenuContext.js";
|
|
22
23
|
import { useLinkComponent } from "../Link/useLinkComponent.js";
|
|
23
24
|
import { themeProps } from "../utils/themeProps.js";
|
|
@@ -114,33 +115,8 @@ export function NavHeadingMenuItem({
|
|
|
114
115
|
const Element = href ? isDisabled ? 'a' : LinkComponent : 'div';
|
|
115
116
|
|
|
116
117
|
// The element type above changes when `isDisabled` flips, so React replaces
|
|
117
|
-
// the row
|
|
118
|
-
|
|
119
|
-
// `activeElement` is still readable there. Only a different node replacing a
|
|
120
|
-
// removed one takes focus, and only if focus has fallen to the page: React
|
|
121
|
-
// also detaches and re-attaches the same node (for example when an <Activity>
|
|
122
|
-
// boundary hides and reveals the row), and neither case may pull focus back
|
|
123
|
-
// after the person has moved elsewhere.
|
|
124
|
-
const focusedNodeRef = useRef(null);
|
|
125
|
-
const itemRef = useCallback(node => {
|
|
126
|
-
if (node === null) {
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
const outgoing = focusedNodeRef.current;
|
|
130
|
-
focusedNodeRef.current = null;
|
|
131
|
-
// Focus only follows the swap when it has fallen to the page. If the
|
|
132
|
-
// person moved focus elsewhere in the meantime (for example while an
|
|
133
|
-
// <Activity> boundary kept the row hidden), leave it alone.
|
|
134
|
-
const focusFell = document.activeElement === null || document.activeElement === document.body;
|
|
135
|
-
if (outgoing !== null && outgoing !== node && !outgoing.isConnected && focusFell) {
|
|
136
|
-
node.focus();
|
|
137
|
-
}
|
|
138
|
-
const release = mergeRefs(ref)(node);
|
|
139
|
-
return () => {
|
|
140
|
-
focusedNodeRef.current = document.activeElement === node ? node : null;
|
|
141
|
-
release?.();
|
|
142
|
-
};
|
|
143
|
-
}, [ref]);
|
|
118
|
+
// the row; focus follows to the replacement (spec:AST-085 FR4).
|
|
119
|
+
const itemRef = useFocusAcrossSwap(ref);
|
|
144
120
|
return /*#__PURE__*/_jsxs(Element, {
|
|
145
121
|
...restProps,
|
|
146
122
|
ref: itemRef,
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
* provided and fall back to `label` when it is missing or blank. Their label
|
|
10
10
|
* tooltip binds to the interactive control through a callback ref, so hover,
|
|
11
11
|
* keyboard focus, and `aria-describedby` follow the control from the first
|
|
12
|
-
* collapsed render. A disabled control takes
|
|
13
|
-
*
|
|
12
|
+
* collapsed render. A disabled control takes no pointer, so its row listens
|
|
13
|
+
* for the tooltip instead, while the control keeps focus and the description.
|
|
14
14
|
*
|
|
15
15
|
* Collapsed items with children open their submenu flyout through
|
|
16
16
|
* `useMenuHover`, the shared hover-intent hook (same one `SideNavHeading` and
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SideNavItem.d.ts","sourceRoot":"","sources":["../../src/SideNav/SideNavItem.tsx"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAAO,EAOL,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AAYf,OAAO,EAAuB,KAAK,QAAQ,EAAC,MAAM,SAAS,CAAC;AAE5D,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,eAAe,CAAC;AAIrD,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,cAAc,CAAC;AAE5C,OAAO,EAAgB,KAAK,WAAW,EAAC,MAAM,iCAAiC,CAAC;
|
|
1
|
+
{"version":3,"file":"SideNavItem.d.ts","sourceRoot":"","sources":["../../src/SideNav/SideNavItem.tsx"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAAO,EAOL,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AAYf,OAAO,EAAuB,KAAK,QAAQ,EAAC,MAAM,SAAS,CAAC;AAE5D,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,eAAe,CAAC;AAIrD,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,c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AAkB,EAClB,IAAI,EACJ,OAAO,EACP,UAAU,EACV,OAAO,EACP,QAAQ,EACR,WAAW,EAAE,eAAe,EAC5B,IAAW,EACX,aAAa,EAAE,MAAM,EACrB,GAAG,EACH,MAAM,EACN,GAAG,IAAI,EACR,EAAE,gBAAgB,sCAiclB;yBAnde,WAAW"}
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
* provided and fall back to `label` when it is missing or blank. Their label
|
|
14
14
|
* tooltip binds to the interactive control through a callback ref, so hover,
|
|
15
15
|
* keyboard focus, and `aria-describedby` follow the control from the first
|
|
16
|
-
* collapsed render. A disabled control takes
|
|
17
|
-
*
|
|
16
|
+
* collapsed render. A disabled control takes no pointer, so its row listens
|
|
17
|
+
* for the tooltip instead, while the control keeps focus and the description.
|
|
18
18
|
*
|
|
19
19
|
* Collapsed items with children open their submenu flyout through
|
|
20
20
|
* `useMenuHover`, the shared hover-intent hook (same one `SideNavHeading` and
|
|
@@ -52,6 +52,7 @@ import { useSideNavCollapse, SideNavCollapseContext } from "./SideNavCollapseCon
|
|
|
52
52
|
import { useSideNavRenderMode } from "./SideNavRenderContext.js";
|
|
53
53
|
import { useAppShellMobile } from "../AppShell/AppShellMobileContext.js";
|
|
54
54
|
import { themeProps } from "../utils/themeProps.js";
|
|
55
|
+
import { disabledInteractionProps } from "../utils/disabledInteraction.js";
|
|
55
56
|
import { useTranslator } from "../i18n/index.js";
|
|
56
57
|
import { useMergedRefs } from "../hooks/useMergedRefs.js";
|
|
57
58
|
// =============================================================================
|
|
@@ -207,6 +208,8 @@ const EXPANDED_COLLAPSE_STATE = {
|
|
|
207
208
|
/**
|
|
208
209
|
* Renders `<a>` (via LinkComponent) when `href` is set, otherwise `<button>`.
|
|
209
210
|
* Centralizes the link-vs-button decision used across all SideNavItem paths.
|
|
211
|
+
* A disabled item is a `<button>` that keeps its tab stop and exposes
|
|
212
|
+
* `aria-disabled`, but is inert (spec:AST-085 FR1, FR2).
|
|
210
213
|
*/
|
|
211
214
|
function NavItemElement({
|
|
212
215
|
href,
|
|
@@ -231,8 +234,11 @@ function NavItemElement({
|
|
|
231
234
|
ref: ref,
|
|
232
235
|
type: "button",
|
|
233
236
|
onClick: onClick,
|
|
234
|
-
disabled: isDisabled,
|
|
235
237
|
...rest,
|
|
238
|
+
...(isDisabled ? {
|
|
239
|
+
'aria-disabled': true,
|
|
240
|
+
...disabledInteractionProps(rest.onKeyDown)
|
|
241
|
+
} : null),
|
|
236
242
|
children: children
|
|
237
243
|
});
|
|
238
244
|
}
|
|
@@ -335,6 +341,10 @@ export function SideNavItem({
|
|
|
335
341
|
const isRailLeaf = isCollapsed && !hasChildren;
|
|
336
342
|
const railTooltip = useTooltip({
|
|
337
343
|
placement: 'end',
|
|
344
|
+
// A disabled leaf's row is the trigger (see the collapsed path). It is not
|
|
345
|
+
// focusable itself, so `auto` would never hear the focus that bubbles up
|
|
346
|
+
// from its control.
|
|
347
|
+
focusTrigger: 'always',
|
|
338
348
|
isEnabled: isRailLeaf,
|
|
339
349
|
isOpen: isRailLeaf ? undefined : false
|
|
340
350
|
});
|
|
@@ -477,12 +487,14 @@ export function SideNavItem({
|
|
|
477
487
|
|
|
478
488
|
// Items without children: icon-only link or button, its label in a
|
|
479
489
|
// tooltip. The control is the trigger, so the element that takes focus is
|
|
480
|
-
// the one described. A disabled control takes
|
|
481
|
-
// (`navItemStyles.disabled`)
|
|
490
|
+
// the one described. A disabled control takes no pointer
|
|
491
|
+
// (`navItemStyles.disabled`), so its row listens for the tooltip instead;
|
|
492
|
+
// the control still takes focus (focusin reaches the row) and stays the
|
|
493
|
+
// element described (spec:AST-085 FR5).
|
|
482
494
|
const isRowTrigger = isDisabled;
|
|
483
495
|
const collapsedAriaProps = {
|
|
484
496
|
'aria-current': isSelected ? 'page' : undefined,
|
|
485
|
-
'aria-describedby':
|
|
497
|
+
'aria-describedby': joinIds(rest['aria-describedby'], railTooltip.describedBy),
|
|
486
498
|
'aria-disabled': isDisabled || undefined,
|
|
487
499
|
'aria-label': collapsedAccessibleLabel,
|
|
488
500
|
'data-testid': testId
|
|
@@ -500,7 +512,6 @@ export function SideNavItem({
|
|
|
500
512
|
});
|
|
501
513
|
return /*#__PURE__*/_jsxs("div", {
|
|
502
514
|
ref: isRowTrigger ? railTooltip.ref : undefined,
|
|
503
|
-
"aria-describedby": isRowTrigger ? railTooltip.describedBy : undefined,
|
|
504
515
|
...stylex.props(styles.root, xstyle),
|
|
505
516
|
children: [collapsedElement, railTooltip.renderTooltip(label)]
|
|
506
517
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeListItem.d.ts","sourceRoot":"","sources":["../../src/TreeList/TreeListItem.tsx"],"names":[],"mappings":"AAIA;;;;;;;;;;GAUG;AAEH,OAAO,EAAyB,KAAK,SAAS,EAAC,MAAM,OAAO,CAAC;AAC7D,OAAO,KAAK,MAAM,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"TreeListItem.d.ts","sourceRoot":"","sources":["../../src/TreeList/TreeListItem.tsx"],"names":[],"mappings":"AAIA;;;;;;;;;;GAUG;AAEH,OAAO,EAAyB,KAAK,SAAS,EAAC,MAAM,OAAO,CAAC;AAC7D,OAAO,KAAK,MAAM,MAAM,kBAAkB,CAAC;AAqB3C,OAAO,KAAK,EAAC,eAAe,EAAE,eAAe,EAAC,MAAM,iBAAiB,CAAC;AA0RtE,MAAM,WAAW,yBAAyB;IACxC,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,KAAK,CAAC,SAAS,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC/B,UAAU,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC7B,OAAO,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,UAAU,KAAK,IAAI,CAAC;IACxC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAA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+22,8 @@ import { interactionOverlayStyles } from "../utils/interactionOverlay.stylex.js"
|
|
|
22
22
|
import { usePressFeedback } from "../hooks/usePressFeedback.js";
|
|
23
23
|
import { hasInteractiveAncestor, useClickableContainer } from "../hooks/useClickableContainer.js";
|
|
24
24
|
import { Icon } from "../Icon/index.js";
|
|
25
|
-
import { mergeProps } from "../utils/
|
|
25
|
+
import { mergeProps } from "../utils/mergeProps.js";
|
|
26
|
+
import { useFocusAcrossSwap } from "../utils/useFocusAcrossSwap.js";
|
|
26
27
|
import { useLinkComponent } from "../Link/useLinkComponent.js";
|
|
27
28
|
import { TreeListBranches } from "./TreeListBranches.js";
|
|
28
29
|
import { themeProps } from "../utils/themeProps.js";
|
|
@@ -150,6 +151,8 @@ const descriptionSizeStyles = {
|
|
|
150
151
|
// Component
|
|
151
152
|
// =============================================================================
|
|
152
153
|
|
|
154
|
+
/** A plain anchor, for a disabled item whose link has no destination. */
|
|
155
|
+
const DisabledAnchor = 'a';
|
|
153
156
|
export function TreeListItem({
|
|
154
157
|
id,
|
|
155
158
|
label,
|
|
@@ -185,6 +188,10 @@ export function TreeListItem({
|
|
|
185
188
|
const descriptionId = useId();
|
|
186
189
|
const LinkComponent = useLinkComponent();
|
|
187
190
|
const linkRef = useRef(null);
|
|
191
|
+
// Disabling the item swaps the router link for a plain anchor, so React
|
|
192
|
+
// replaces it; focus on the inner link (after a pointer click) follows the
|
|
193
|
+
// swap instead of falling to the page (spec:AST-085 FR4).
|
|
194
|
+
const anchorRef = useFocusAcrossSwap(linkRef);
|
|
188
195
|
const isInteractive = onClick != null || href != null;
|
|
189
196
|
const handleToggle = useMemo(() => hasChildren && onToggle != null ? e => {
|
|
190
197
|
e.stopPropagation();
|
|
@@ -352,11 +359,27 @@ export function TreeListItem({
|
|
|
352
359
|
className: "x2lah0s x78zum5 x6s0dn4"
|
|
353
360
|
},
|
|
354
361
|
children: startContent
|
|
355
|
-
}), href != null
|
|
356
|
-
|
|
362
|
+
}), href != null && isDisabled ?
|
|
363
|
+
/*#__PURE__*/
|
|
364
|
+
// A disabled item's anchor has no destination, so neither the row's
|
|
365
|
+
// forwarded activation nor a screen reader's click can navigate
|
|
366
|
+
// (spec:AST-085 FR2). Like a disabled Link, it keeps the link role and
|
|
367
|
+
// skips the router link component.
|
|
368
|
+
_jsx(DisabledAnchor, {
|
|
369
|
+
ref: anchorRef,
|
|
370
|
+
role: "link",
|
|
371
|
+
"aria-disabled": true,
|
|
372
|
+
"aria-labelledby": labelId,
|
|
373
|
+
"aria-describedby": description != null ? descriptionId : undefined,
|
|
374
|
+
tabIndex: -1,
|
|
375
|
+
...{
|
|
376
|
+
className: "xmper1u x16khyan xln7xf2 x1heor9g x78zum5 xdt5ytf x98rzlu xeuugli x1yc453h x1hl2dhg x1a2a7pz"
|
|
377
|
+
},
|
|
378
|
+
children: labelAndDescription
|
|
379
|
+
}) : href != null ? /*#__PURE__*/_jsx(LinkComponent, {
|
|
380
|
+
ref: anchorRef,
|
|
357
381
|
href: href,
|
|
358
382
|
target: target,
|
|
359
|
-
"aria-disabled": isDisabled || undefined,
|
|
360
383
|
"aria-labelledby": labelId,
|
|
361
384
|
"aria-describedby": description != null ? descriptionId : undefined
|
|
362
385
|
// Roving tabindex lives on the treeitem row; inner action is not a
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file useFocusAcrossSwap.ts
|
|
3
|
+
* @input An optional forwarded ref
|
|
4
|
+
* @output A callback ref that carries focus to a replacement element
|
|
5
|
+
* @position Internal hook for a component whose element type changes with a
|
|
6
|
+
* prop (a link row that renders a plain anchor while disabled). React
|
|
7
|
+
* replaces the element, so focus would fall to the page; spec:AST-085 FR4
|
|
8
|
+
* keeps it on the row.
|
|
9
|
+
*
|
|
10
|
+
* The ref cleanup runs before the old node is removed, so `activeElement` is
|
|
11
|
+
* still readable there. Only a different node replacing a removed one takes
|
|
12
|
+
* focus, and only if focus has fallen to the page: React also detaches and
|
|
13
|
+
* re-attaches the same node (for example when an <Activity> boundary hides and
|
|
14
|
+
* reveals it), and neither case may pull focus back after the person has moved
|
|
15
|
+
* elsewhere.
|
|
16
|
+
*/
|
|
17
|
+
import { type Ref } from 'react';
|
|
18
|
+
export declare function useFocusAcrossSwap<T extends HTMLElement>(ref?: Ref<T>): (node: T | null) => (() => void) | undefined;
|
|
19
|
+
//# sourceMappingURL=useFocusAcrossSwap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFocusAcrossSwap.d.ts","sourceRoot":"","sources":["../../src/utils/useFocusAcrossSwap.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAsB,KAAK,GAAG,EAAC,MAAM,OAAO,CAAC;AAGpD,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,WAAW,EACtD,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,GACX,CAAC,IAAI,EAAE,CAAC,GAAG,IAAI,KAAK,CAAC,MAAM,IAAI,CAAC,GAAG,SAAS,CA4B9C"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
'use client';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @file useFocusAcrossSwap.ts
|
|
7
|
+
* @input An optional forwarded ref
|
|
8
|
+
* @output A callback ref that carries focus to a replacement element
|
|
9
|
+
* @position Internal hook for a component whose element type changes with a
|
|
10
|
+
* prop (a link row that renders a plain anchor while disabled). React
|
|
11
|
+
* replaces the element, so focus would fall to the page; spec:AST-085 FR4
|
|
12
|
+
* keeps it on the row.
|
|
13
|
+
*
|
|
14
|
+
* The ref cleanup runs before the old node is removed, so `activeElement` is
|
|
15
|
+
* still readable there. Only a different node replacing a removed one takes
|
|
16
|
+
* focus, and only if focus has fallen to the page: React also detaches and
|
|
17
|
+
* re-attaches the same node (for example when an <Activity> boundary hides and
|
|
18
|
+
* reveals it), and neither case may pull focus back after the person has moved
|
|
19
|
+
* elsewhere.
|
|
20
|
+
*/
|
|
21
|
+
import { useCallback, useRef } from 'react';
|
|
22
|
+
import { mergeRefs } from "./mergeRefs.js";
|
|
23
|
+
export function useFocusAcrossSwap(ref) {
|
|
24
|
+
const focusedNodeRef = useRef(null);
|
|
25
|
+
return useCallback(node => {
|
|
26
|
+
if (node === null) {
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
const outgoing = focusedNodeRef.current;
|
|
30
|
+
focusedNodeRef.current = null;
|
|
31
|
+
const focusFell = document.activeElement === null || document.activeElement === document.body;
|
|
32
|
+
if (outgoing !== null && outgoing !== node && !outgoing.isConnected && focusFell) {
|
|
33
|
+
node.focus();
|
|
34
|
+
}
|
|
35
|
+
const release = mergeRefs(ref)(node);
|
|
36
|
+
return () => {
|
|
37
|
+
focusedNodeRef.current = document.activeElement === node ? node : null;
|
|
38
|
+
release?.();
|
|
39
|
+
};
|
|
40
|
+
}, [ref]);
|
|
41
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astryxdesign/core",
|
|
3
|
-
"version": "0.7.6-canary.
|
|
3
|
+
"version": "0.7.6-canary.8d0a847",
|
|
4
4
|
"displayName": "Astryx Core",
|
|
5
5
|
"description": "The component library. Accessible, themeable React components with built-in spacing, dark mode, and StyleX styling.",
|
|
6
6
|
"author": "Meta Open Source",
|
|
@@ -847,9 +847,9 @@
|
|
|
847
847
|
"react-dom": ">=19.0.0"
|
|
848
848
|
},
|
|
849
849
|
"devDependencies": {
|
|
850
|
-
"@astryxdesign/a11y-spec": "0.7.6-canary.
|
|
851
|
-
"@astryxdesign/cli": "0.7.6-canary.
|
|
852
|
-
"@astryxdesign/interaction-harness": "0.7.6-canary.
|
|
850
|
+
"@astryxdesign/a11y-spec": "0.7.6-canary.8d0a847",
|
|
851
|
+
"@astryxdesign/cli": "0.7.6-canary.8d0a847",
|
|
852
|
+
"@astryxdesign/interaction-harness": "0.7.6-canary.8d0a847",
|
|
853
853
|
"@babel/cli": "^7.29.7",
|
|
854
854
|
"@babel/core": "^7.29.7",
|
|
855
855
|
"@babel/preset-react": "^7.29.7",
|