@primer/react 38.46.0-rc.18db27ff8 → 38.46.0-rc.3e370923f

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 (36) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/ActionList/LinkItem.js +97 -30
  3. package/dist/Breadcrumbs/{Breadcrumbs-16d81430.css → Breadcrumbs-6c9aadcf.css} +2 -2
  4. package/dist/Breadcrumbs/Breadcrumbs-6c9aadcf.css.map +1 -0
  5. package/dist/Breadcrumbs/Breadcrumbs.js +403 -391
  6. package/dist/Breadcrumbs/Breadcrumbs.module.css.js +1 -1
  7. package/dist/Card/Card-0e84ee3c.css +2 -0
  8. package/dist/Card/Card-0e84ee3c.css.map +1 -0
  9. package/dist/Card/Card.d.ts +13 -3
  10. package/dist/Card/Card.js +286 -161
  11. package/dist/Card/Card.module.css.js +2 -1
  12. package/dist/Card/index.d.ts +13 -3
  13. package/dist/Card/index.js +3 -1
  14. package/dist/ProgressBar/ProgressBar-3d1db6c7.css +2 -0
  15. package/dist/ProgressBar/ProgressBar-3d1db6c7.css.map +1 -0
  16. package/dist/ProgressBar/ProgressBar.module.css.js +1 -1
  17. package/dist/Skeleton/skeleton-bdbe6bf2.css +2 -0
  18. package/dist/Skeleton/skeleton-bdbe6bf2.css.map +1 -0
  19. package/dist/Skeleton/skeleton.module.css.js +1 -1
  20. package/dist/TooltipV2/Tooltip.js +55 -51
  21. package/dist/TreeView/TreeView.js +29 -15
  22. package/dist/TreeView/useTreeRovingTabIndex.js +155 -0
  23. package/dist/experimental/index.d.ts +2 -2
  24. package/dist/hooks/useOnEscapePress.d.ts +2 -0
  25. package/dist/hooks/useOnEscapePress.js +11 -4
  26. package/dist/hooks/useOnOutsideClick.js +2 -1
  27. package/dist/index.js +1 -1
  28. package/generated/components.json +82 -3
  29. package/package.json +8 -8
  30. package/dist/Breadcrumbs/Breadcrumbs-16d81430.css.map +0 -1
  31. package/dist/Card/Card-59b77d05.css +0 -2
  32. package/dist/Card/Card-59b77d05.css.map +0 -1
  33. package/dist/ProgressBar/ProgressBar-e403d83d.css +0 -2
  34. package/dist/ProgressBar/ProgressBar-e403d83d.css.map +0 -1
  35. package/dist/Skeleton/skeleton-27888827.css +0 -2
  36. package/dist/Skeleton/skeleton-27888827.css.map +0 -1
@@ -0,0 +1,2 @@
1
+ @keyframes prc-ProgressBar-shimmer-hIHBF{0%{transform:translateX(0)}to{transform:translateX(66.66667%)}}.prc-ProgressBar-ProgressBarItem-mDIlB{--progress-width: ;--progress-bg: ;background-color:var(--progress-bg);width:var(--progress-width)}@media (prefers-reduced-motion:no-preference){.prc-ProgressBar-ProgressBarItem-mDIlB[data-animated=true]{background-color:transparent;isolation:isolate;overflow:hidden;position:relative}.prc-ProgressBar-ProgressBarItem-mDIlB[data-animated=true]:before{animation-duration:1s;animation-iteration-count:infinite;animation-name:prc-ProgressBar-shimmer-hIHBF;background-color:var(--progress-bg);bottom:0;content:"";left:-200%;mask-image:linear-gradient(75deg,#000 30%,rgba(0,0,0,.65) 80%);mask-size:66.66667% 100%;position:absolute;top:0;width:300%;z-index:-1}}.prc-ProgressBar-ProgressBarContainer-tCYE2{background-color:var(--progressBar-track-bgColor,#d1d9e0);border-radius:var(--borderRadius-small,.1875rem);display:flex;gap:2px;outline:solid 1px var(--progressBar-track-borderColor,#ffffff00);outline-offset:-1px;overflow:hidden}.prc-ProgressBar-ProgressBarContainer-tCYE2:where([data-progress-display=inline]){display:inline-flex}.prc-ProgressBar-ProgressBarContainer-tCYE2:where([data-progress-bar-size=default]){height:8px}.prc-ProgressBar-ProgressBarContainer-tCYE2:where([data-progress-bar-size=small]){height:5px}.prc-ProgressBar-ProgressBarContainer-tCYE2:where([data-progress-bar-size=large]){height:10px}@media (forced-colors:active){:root{--progress-bg:LinkText;--progressBar-track-bgColor:CanvasText}.prc-ProgressBar-ProgressBarContainer-tCYE2,.prc-ProgressBar-ProgressBarItem-mDIlB{forced-color-adjust:none}}
2
+ /*# sourceMappingURL=ProgressBar-3d1db6c7.css.map */
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/ProgressBar/ProgressBar.module.css.js"],"names":[],"mappings":"AACA,yCACE,GACE,uBACF,CAEA,GACE,+BACF,CACF,CAEA,uCAEE,kBAAkB,CAClB,eAAe,CAIf,mCAAoC,CAFpC,2BA8BF,CA1BE,8CACE,2DAIE,4BAA6B,CAC7B,iBAAkB,CAHlB,eAAgB,CADhB,iBAsBF,CAhBE,kEAaE,qBAAsB,CACtB,kCAAmC,CAFnC,4CAAuB,CAHvB,mCAAoC,CANpC,QAAS,CAIT,UAAW,CAHX,UAAW,CAMX,8DAAoE,CACpE,wBAA8B,CAV9B,iBAAkB,CAClB,KAAM,CAIN,UAAW,CADX,UAUF,CAEJ,CAGF,4CAGE,yDAAkD,CAClD,gDAAwC,CAHxC,YAAa,CAIb,OAAQ,CACR,gEAAuD,CACvD,mBAAoB,CALpB,eAsBF,CAfE,kFACE,mBACF,CAEA,oFACE,UACF,CAEA,kFACE,UACF,CAEA,kFACE,WACF,CAGF,8BACE,MACE,sBAAuB,CACvB,sCACF,CAEA,mFAEE,wBACF,CACF","file":"ProgressBar-3d1db6c7.css","sourcesContent":["/* See Skeleton/skeleton.module.css: a masked layer moved with `transform` so the compositor can run the shimmer */\n@keyframes shimmer {\n from {\n transform: translateX(0);\n }\n\n to {\n transform: translateX(calc(200% / 3));\n }\n}\n\n.ProgressBarItem {\n /* these are passed from the component */\n --progress-width: ;\n --progress-bg: ;\n\n width: var(--progress-width);\n /* stylelint-disable-next-line primer/colors */\n background-color: var(--progress-bg);\n\n @media (prefers-reduced-motion: no-preference) {\n &[data-animated='true'] {\n position: relative;\n overflow: hidden;\n /* The shimmer layer paints the background so the mask can move with it */\n background-color: transparent;\n isolation: isolate;\n\n &::before {\n position: absolute;\n top: 0;\n bottom: 0;\n left: -200%;\n z-index: -1;\n width: 300%;\n content: '';\n /* stylelint-disable-next-line primer/colors */\n background-color: var(--progress-bg);\n mask-image: linear-gradient(75deg, #000 30%, rgb(0, 0, 0, 0.65) 80%);\n mask-size: calc(200% / 3) 100%;\n animation-name: shimmer;\n animation-duration: 1s;\n animation-iteration-count: infinite;\n }\n }\n }\n}\n\n.ProgressBarContainer {\n display: flex;\n overflow: hidden;\n background-color: var(--progressBar-track-bgColor);\n border-radius: var(--borderRadius-small);\n gap: 2px;\n outline: solid 1px var(--progressBar-track-borderColor);\n outline-offset: -1px;\n\n &:where([data-progress-display='inline']) {\n display: inline-flex;\n }\n\n &:where([data-progress-bar-size='default']) {\n height: 8px;\n }\n\n &:where([data-progress-bar-size='small']) {\n height: 5px;\n }\n\n &:where([data-progress-bar-size='large']) {\n height: 10px;\n }\n}\n\n@media (forced-colors: active) {\n :root {\n --progress-bg: LinkText;\n --progressBar-track-bgColor: CanvasText;\n }\n\n .ProgressBarContainer,\n .ProgressBarItem {\n forced-color-adjust: none;\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- import "./ProgressBar-e403d83d.css";
1
+ import "./ProgressBar-3d1db6c7.css";
2
2
  //#region src/ProgressBar/ProgressBar.module.css.js
3
3
  var ProgressBar_module_css_default = {
4
4
  "ProgressBarItem": "prc-ProgressBar-ProgressBarItem-mDIlB",
@@ -0,0 +1,2 @@
1
+ @keyframes prc-Skeleton-shimmer-mE-VG{0%{transform:translateX(0)}to{transform:translateX(66.66667%)}}.prc-Skeleton-skeleton-Hkezl{background-color:var(--skeletonLoader-bgColor,#818b981a)}@media (prefers-reduced-motion:no-preference){.prc-Skeleton-skeleton-Hkezl{background-color:transparent;isolation:isolate;overflow:hidden;position:relative}.prc-Skeleton-skeleton-Hkezl:before{animation:prc-Skeleton-shimmer-mE-VG;animation-duration:var(--base-duration-1000,[ object Object ]);animation-iteration-count:infinite;background-color:var(--skeletonLoader-bgColor,#818b981a);bottom:0;content:"";left:-200%;mask-image:linear-gradient(75deg,#000 30%,rgba(0,0,0,.65) 80%);mask-size:66.66667% 100%;position:absolute;top:0;width:300%;z-index:-1}}@media (forced-colors:active){.prc-Skeleton-skeleton-Hkezl{outline:1px solid transparent;outline-offset:-1px}}
2
+ /*# sourceMappingURL=skeleton-bdbe6bf2.css.map */
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/Skeleton/skeleton.module.css.js"],"names":[],"mappings":"AAKA,sCACE,GACE,uBACF,CAEA,GACE,+BACF,CACF,CAGA,6BACE,wDA8BF,CA5BE,8CAHF,6BAOI,4BAA6B,CAC7B,iBAAkB,CAHlB,eAAgB,CADhB,iBA2BJ,CArBI,oCAWE,oCAAkB,CAClB,8DAA6C,CAC7C,kCAAmC,CALnC,wDAA+C,CAL/C,QAAS,CAIT,UAAW,CAHX,UAAW,CAKX,8DAAoE,CACpE,wBAA8B,CAT9B,iBAAkB,CAClB,KAAM,CAIN,UAAW,CADX,UASF,CACF,CAEA,8BA3BF,6BA4BI,6BAA8B,CAC9B,mBAEJ,CADE","file":"skeleton-bdbe6bf2.css","sourcesContent":["/*\n * The shimmer moves a masked layer with `transform` instead of animating `mask-position`, so the compositor can run it\n * without a style recalc and repaint on every frame. The layer is 3x the box width and its mask tile is 2x the box\n * width (the previous `mask-size: 200%`), so translating it by one tile reproduces the previous mask positions exactly.\n */\n@keyframes shimmer {\n from {\n transform: translateX(0);\n }\n\n to {\n transform: translateX(calc(200% / 3));\n }\n}\n\n/* stylelint-disable-next-line selector-class-pattern -- Shared utility, not a component class. */\n.skeleton {\n background-color: var(--skeletonLoader-bgColor);\n\n @media (prefers-reduced-motion: no-preference) {\n position: relative;\n overflow: hidden;\n /* The shimmer layer paints the background so the mask can move with it */\n background-color: transparent;\n isolation: isolate;\n\n &::before {\n position: absolute;\n top: 0;\n bottom: 0;\n left: -200%;\n z-index: -1;\n width: 300%;\n content: '';\n background-color: var(--skeletonLoader-bgColor);\n mask-image: linear-gradient(75deg, #000 30%, rgb(0, 0, 0, 0.65) 80%);\n mask-size: calc(200% / 3) 100%;\n animation: shimmer;\n animation-duration: var(--base-duration-1000);\n animation-iteration-count: infinite;\n }\n }\n\n @media (forced-colors: active) {\n outline: 1px solid transparent;\n outline-offset: -1px;\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- import "./skeleton-27888827.css";
1
+ import "./skeleton-bdbe6bf2.css";
2
2
  //#region src/Skeleton/skeleton.module.css.js
3
3
  var skeleton_module_css_default = {
4
4
  "skeleton": "prc-Skeleton-skeleton-Hkezl",
@@ -82,7 +82,7 @@ const isInteractive = (element) => {
82
82
  };
83
83
  const emptyKeybindingHints = [];
84
84
  const Tooltip = /*#__PURE__*/ React.forwardRef((t0, forwardedRef) => {
85
- const $ = c(58);
85
+ const $ = c(60);
86
86
  let children;
87
87
  let className;
88
88
  let id;
@@ -240,33 +240,37 @@ const Tooltip = /*#__PURE__*/ React.forwardRef((t0, forwardedRef) => {
240
240
  } else t10 = $[26];
241
241
  useEffect(t9, t10);
242
242
  let t11;
243
- if ($[27] !== closeTooltip || $[28] !== isPopoverOpen) {
243
+ if ($[27] !== _privateDisableTooltip || $[28] !== closeTooltip || $[29] !== isPopoverOpen) {
244
244
  t11 = (event) => {
245
245
  if (isPopoverOpen) {
246
- event.stopImmediatePropagation();
247
- event.preventDefault();
246
+ if (!_privateDisableTooltip) {
247
+ event.stopImmediatePropagation();
248
+ event.preventDefault();
249
+ }
248
250
  closeTooltip();
249
251
  }
250
252
  };
251
- $[27] = closeTooltip;
252
- $[28] = isPopoverOpen;
253
- $[29] = t11;
254
- } else t11 = $[29];
253
+ $[27] = _privateDisableTooltip;
254
+ $[28] = closeTooltip;
255
+ $[29] = isPopoverOpen;
256
+ $[30] = t11;
257
+ } else t11 = $[30];
255
258
  let t12;
256
- if ($[30] !== isPopoverOpen) {
257
- t12 = [isPopoverOpen];
258
- $[30] = isPopoverOpen;
259
- $[31] = t12;
260
- } else t12 = $[31];
259
+ if ($[31] !== _privateDisableTooltip || $[32] !== isPopoverOpen) {
260
+ t12 = [isPopoverOpen, _privateDisableTooltip];
261
+ $[31] = _privateDisableTooltip;
262
+ $[32] = isPopoverOpen;
263
+ $[33] = t12;
264
+ } else t12 = $[33];
261
265
  useOnEscapePress(t11, t12);
262
266
  const platform = usePlatform();
263
267
  const hasAriaLabel_0 = "aria-label" in rest;
264
268
  let t13;
265
- if ($[32] !== keybindingHint) {
269
+ if ($[34] !== keybindingHint) {
266
270
  t13 = Array.isArray(keybindingHint) ? keybindingHint : [keybindingHint];
267
- $[32] = keybindingHint;
268
- $[33] = t13;
269
- } else t13 = $[33];
271
+ $[34] = keybindingHint;
272
+ $[35] = t13;
273
+ } else t13 = $[35];
270
274
  const keybindingHints = t13;
271
275
  if (isFragmentTrigger) return child;
272
276
  const t14 = TooltipContext;
@@ -313,15 +317,15 @@ const Tooltip = /*#__PURE__*/ React.forwardRef((t0, forwardedRef) => {
313
317
  }
314
318
  });
315
319
  let t17;
316
- if ($[34] !== className) {
320
+ if ($[36] !== className) {
317
321
  t17 = clsx(className, Tooltip_module_css_default.Tooltip);
318
- $[34] = className;
319
- $[35] = t17;
320
- } else t17 = $[35];
322
+ $[36] = className;
323
+ $[37] = t17;
324
+ } else t17 = $[37];
321
325
  const t18 = type === "description" ? "tooltip" : void 0;
322
326
  const t19 = hasAriaLabel_0 || keybindingHints.length === 0 ? tooltipId : void 0;
323
327
  let t20;
324
- if ($[36] !== hasAriaLabel_0 || $[37] !== keybindingHints || $[38] !== platform || $[39] !== text || $[40] !== tooltipId) {
328
+ if ($[38] !== hasAriaLabel_0 || $[39] !== keybindingHints || $[40] !== platform || $[41] !== text || $[42] !== tooltipId) {
325
329
  t20 = keybindingHints.length > 0 ? /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsxs("span", {
326
330
  id: hasAriaLabel_0 ? void 0 : tooltipId,
327
331
  children: [text, /* @__PURE__ */ jsxs(VisuallyHidden, { children: [
@@ -335,15 +339,15 @@ const Tooltip = /*#__PURE__*/ React.forwardRef((t0, forwardedRef) => {
335
339
  "data-component": "Tooltip.KeybindingHintContainer",
336
340
  children: keybindingHints.map(_temp4)
337
341
  })] }) : text;
338
- $[36] = hasAriaLabel_0;
339
- $[37] = keybindingHints;
340
- $[38] = platform;
341
- $[39] = text;
342
- $[40] = tooltipId;
343
- $[41] = t20;
344
- } else t20 = $[41];
342
+ $[38] = hasAriaLabel_0;
343
+ $[39] = keybindingHints;
344
+ $[40] = platform;
345
+ $[41] = text;
346
+ $[42] = tooltipId;
347
+ $[43] = t20;
348
+ } else t20 = $[43];
345
349
  let t21;
346
- if ($[42] !== calculatedDirection || $[43] !== closeTooltip || $[44] !== openTooltip || $[45] !== rest || $[46] !== t17 || $[47] !== t18 || $[48] !== t19 || $[49] !== t20) {
350
+ if ($[44] !== calculatedDirection || $[45] !== closeTooltip || $[46] !== openTooltip || $[47] !== rest || $[48] !== t17 || $[49] !== t18 || $[50] !== t19 || $[51] !== t20) {
347
351
  t21 = /* @__PURE__ */ jsx("span", {
348
352
  className: t17,
349
353
  ref: tooltipElRef,
@@ -357,34 +361,34 @@ const Tooltip = /*#__PURE__*/ React.forwardRef((t0, forwardedRef) => {
357
361
  id: t19,
358
362
  children: t20
359
363
  });
360
- $[42] = calculatedDirection;
361
- $[43] = closeTooltip;
362
- $[44] = openTooltip;
363
- $[45] = rest;
364
- $[46] = t17;
365
- $[47] = t18;
366
- $[48] = t19;
367
- $[49] = t20;
368
- $[50] = t21;
369
- } else t21 = $[50];
364
+ $[44] = calculatedDirection;
365
+ $[45] = closeTooltip;
366
+ $[46] = openTooltip;
367
+ $[47] = rest;
368
+ $[48] = t17;
369
+ $[49] = t18;
370
+ $[50] = t19;
371
+ $[51] = t20;
372
+ $[52] = t21;
373
+ } else t21 = $[52];
370
374
  let t22;
371
- if ($[51] !== t15 || $[52] !== t21) {
375
+ if ($[53] !== t15 || $[54] !== t21) {
372
376
  t22 = /* @__PURE__ */ jsxs(Fragment$1, { children: [t15, t21] });
373
- $[51] = t15;
374
- $[52] = t21;
375
- $[53] = t22;
376
- } else t22 = $[53];
377
+ $[53] = t15;
378
+ $[54] = t21;
379
+ $[55] = t22;
380
+ } else t22 = $[55];
377
381
  let t23;
378
- if ($[54] !== t14.Provider || $[55] !== t22 || $[56] !== value) {
382
+ if ($[56] !== t14.Provider || $[57] !== t22 || $[58] !== value) {
379
383
  t23 = /* @__PURE__ */ jsx(t14.Provider, {
380
384
  value,
381
385
  children: t22
382
386
  });
383
- $[54] = t14.Provider;
384
- $[55] = t22;
385
- $[56] = value;
386
- $[57] = t23;
387
- } else t23 = $[57];
387
+ $[56] = t14.Provider;
388
+ $[57] = t22;
389
+ $[58] = value;
390
+ $[59] = t23;
391
+ } else t23 = $[59];
388
392
  return t23;
389
393
  });
390
394
  Tooltip.__SLOT__ = Symbol("Tooltip");
@@ -18,7 +18,8 @@ import { ActionList } from "../ActionList/index.js";
18
18
  import TreeView_module_css_default from "./TreeView.module.css.js";
19
19
  import { useControllableState } from "../hooks/useControllableState.js";
20
20
  import { getAccessibleName } from "./shared.js";
21
- import { getFirstChildElement, useRovingTabIndex } from "./useRovingTabIndex.js";
21
+ import { getFirstChildElement } from "./useRovingTabIndex.js";
22
+ import { useTreeRovingTabIndex } from "./useTreeRovingTabIndex.js";
22
23
  import { useTypeahead } from "./useTypeahead.js";
23
24
  import { SkeletonAvatar } from "../SkeletonAvatar/SkeletonAvatar.js";
24
25
  import { SkeletonText } from "../SkeletonText/SkeletonText.js";
@@ -28,9 +29,11 @@ import { clsx } from "clsx";
28
29
  import { ChevronDownIcon, ChevronRightIcon, FileDirectoryFillIcon, FileDirectoryOpenFillIcon } from "@primer/octicons-react";
29
30
  //#region src/TreeView/TreeView.tsx
30
31
  const RootContext = /*#__PURE__*/ React.createContext({
32
+ isWithinTree: false,
31
33
  announceUpdate: () => {},
32
34
  expandedStateCache: { current: /* @__PURE__ */ new Map() },
33
- scrollElementIntoView: () => {}
35
+ scrollElementIntoView: () => {},
36
+ trailingActionShortcutText: ""
34
37
  });
35
38
  const ItemContext = /*#__PURE__*/ React.createContext({
36
39
  itemId: "",
@@ -41,7 +44,9 @@ const ItemContext = /*#__PURE__*/ React.createContext({
41
44
  setIsExpanded: () => {},
42
45
  leadingVisualId: "",
43
46
  trailingVisualId: "",
44
- trailingActionId: ""
47
+ trailingActionId: "",
48
+ subTreeAriaLabel: void 0,
49
+ subTreeAriaLabelledBy: void 0
45
50
  });
46
51
  const LoadingPlaceholderContext = /*#__PURE__*/ React.createContext(false);
47
52
  const TOGGLE_ICON_SIZE = 12;
@@ -64,7 +69,7 @@ const Root = ({ "aria-label": ariaLabel, "aria-labelledby": ariaLabelledby, chil
64
69
  document.removeEventListener("mouseup", onMouseUp);
65
70
  };
66
71
  }, []);
67
- useRovingTabIndex({
72
+ useTreeRovingTabIndex({
68
73
  containerRef,
69
74
  mouseDownRef
70
75
  });
@@ -94,11 +99,15 @@ const Root = ({ "aria-label": ariaLabel, "aria-labelledby": ariaLabelledby, chil
94
99
  }, []);
95
100
  const expandedStateCache = React.useRef(null);
96
101
  if (expandedStateCache.current === null) expandedStateCache.current = /* @__PURE__ */ new Map();
102
+ const platform = usePlatform();
103
+ const trailingActionShortcutText = React.useMemo(() => getTrailingActionShortcutText(platform), [platform]);
97
104
  return /* @__PURE__ */ jsx(RootContext.Provider, {
98
105
  value: {
106
+ isWithinTree: true,
99
107
  announceUpdate,
100
108
  expandedStateCache,
101
- scrollElementIntoView
109
+ scrollElementIntoView,
110
+ trailingActionShortcutText
102
111
  },
103
112
  children: /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(VisuallyHidden, { children: /* @__PURE__ */ jsx(AriaStatus, {
104
113
  announceOnShow: true,
@@ -126,7 +135,7 @@ const ItemImpl = fixedForwardRef(({ id: itemId, containIntrinsicSize, current: i
126
135
  leadingVisual: LeadingVisual,
127
136
  trailingVisual: TrailingVisual
128
137
  });
129
- const { expandedStateCache, scrollElementIntoView } = React.useContext(RootContext);
138
+ const { isWithinTree, expandedStateCache, scrollElementIntoView, trailingActionShortcutText } = React.useContext(RootContext);
130
139
  const labelId = useId$1();
131
140
  const leadingVisualId = useId$1();
132
141
  const trailingVisualId = useId$1();
@@ -146,7 +155,7 @@ const ItemImpl = fixedForwardRef(({ id: itemId, containIntrinsicSize, current: i
146
155
  const [isSubTreeEmpty, setIsSubTreeEmpty] = React.useState(!hasSubTree);
147
156
  const [actionCommandPressed, setActionCommandPressed] = React.useState(false);
148
157
  const [isFocused, setIsFocused] = React.useState(false);
149
- const platform = usePlatform();
158
+ const [initialTabIndex] = React.useState(!isWithinTree || isCurrentItem ? 0 : -1);
150
159
  const setIsExpandedWithCache = React.useCallback((newIsExpanded) => {
151
160
  var _expandedStateCache$c3;
152
161
  setIsExpanded(newIsExpanded);
@@ -200,12 +209,11 @@ const ItemImpl = fixedForwardRef(({ id: itemId, containIntrinsicSize, current: i
200
209
  activateActionsDialog
201
210
  ]);
202
211
  const ariaDescribedByIds = [slots.leadingVisual ? leadingVisualId : null, slots.trailingVisual ? trailingVisualId : null].filter(Boolean);
203
- const trailingActionShortcutText = `Press (${getAccessibleKeybindingHintString(`Shift+${platform === "apple" ? "Meta" : "Control"}+U`, platform)}) for more actions.`;
204
212
  const itemElement = /* @__PURE__ */ jsxs(ItemElement, {
205
213
  ...restProps,
206
214
  className: clsx("PRIVATE_TreeView-item", className, TreeView_module_css_default.TreeViewItem),
207
215
  ref,
208
- tabIndex: 0,
216
+ tabIndex: initialTabIndex,
209
217
  id: itemId,
210
218
  role: "treeitem",
211
219
  "aria-label": secondaryActions ? ariaLabel ? `${ariaLabel}. ${trailingActionShortcutText}` : void 0 : ariaLabel,
@@ -288,7 +296,9 @@ const ItemImpl = fixedForwardRef(({ id: itemId, containIntrinsicSize, current: i
288
296
  setIsExpanded: setIsExpandedWithCache,
289
297
  leadingVisualId,
290
298
  trailingVisualId,
291
- trailingActionId
299
+ trailingActionId,
300
+ subTreeAriaLabel: ariaLabel,
301
+ subTreeAriaLabelledBy: ariaLabel ? void 0 : ariaLabelledby || labelId
292
302
  },
293
303
  children: isPolymorphic ? /* @__PURE__ */ jsx("li", {
294
304
  role: "none",
@@ -297,6 +307,9 @@ const ItemImpl = fixedForwardRef(({ id: itemId, containIntrinsicSize, current: i
297
307
  });
298
308
  });
299
309
  const Item = Object.assign(ItemImpl, { displayName: "TreeView.Item" });
310
+ function getTrailingActionShortcutText(platform) {
311
+ return `Press (${getAccessibleKeybindingHintString(`Shift+${platform === "apple" ? "Meta" : "Control"}+U`, platform)}) for more actions.`;
312
+ }
300
313
  /** Lines to indicate the depth of an item in a TreeView */
301
314
  const LevelIndicatorLines = ({ level }) => {
302
315
  return /* @__PURE__ */ jsx("div", {
@@ -309,11 +322,10 @@ const LevelIndicatorLines = ({ level }) => {
309
322
  };
310
323
  const SubTree = ({ count, state, children, "aria-label": ariaLabel }) => {
311
324
  const { announceUpdate } = React.useContext(RootContext);
312
- const { itemId, isExpanded, isSubTreeEmpty, setIsSubTreeEmpty } = React.useContext(ItemContext);
325
+ const { itemId, isExpanded, isSubTreeEmpty, setIsSubTreeEmpty, subTreeAriaLabel, subTreeAriaLabelledBy } = React.useContext(ItemContext);
313
326
  const loadingItemRef = React.useRef(null);
314
327
  const ref = React.useRef(null);
315
328
  const [loadingFocused, setLoadingFocused] = React.useState(false);
316
- const [subTreeLabel, setSubTreeLabel] = React.useState("");
317
329
  const previousState = usePreviousValue(state);
318
330
  const { safeSetTimeout } = useSafeTimeout();
319
331
  React.useEffect(() => {
@@ -328,10 +340,11 @@ const SubTree = ({ count, state, children, "aria-label": ariaLabel }) => {
328
340
  children
329
341
  ]);
330
342
  React.useEffect(() => {
343
+ const isDoneLoading = previousState === "loading" && state === "done";
344
+ if (!isDoneLoading && state !== "loading") return;
331
345
  const parentElement = document.getElementById(itemId);
332
346
  if (!parentElement) return;
333
- setSubTreeLabel(getAccessibleName(parentElement));
334
- if (previousState === "loading" && state === "done") {
347
+ if (isDoneLoading) {
335
348
  var _ref$current;
336
349
  const parentName = getAccessibleName(parentElement);
337
350
  if ((_ref$current = ref.current) !== null && _ref$current !== void 0 && _ref$current.childElementCount) announceUpdate(`${parentName} content loaded`);
@@ -385,7 +398,8 @@ const SubTree = ({ count, state, children, "aria-label": ariaLabel }) => {
385
398
  margin: 0
386
399
  },
387
400
  ref,
388
- "aria-label": ariaLabel || subTreeLabel,
401
+ "aria-label": ariaLabel || subTreeAriaLabel,
402
+ "aria-labelledby": ariaLabel || subTreeAriaLabel ? void 0 : subTreeAriaLabelledBy,
389
403
  children: [state === "loading" ? /* @__PURE__ */ jsx(LoadingItem, {
390
404
  ref: loadingItemRef,
391
405
  count
@@ -0,0 +1,155 @@
1
+ import { c } from "../utils/react-compiler-runtime.js";
2
+ import { getNextFocusableElement } from "./useRovingTabIndex.js";
3
+ import { useEffect } from "react";
4
+ import { isEditableElement } from "@primer/behaviors/utils";
5
+ //#region src/TreeView/useTreeRovingTabIndex.ts
6
+ const TREE_ITEM = "[role=\"treeitem\"]";
7
+ const CURRENT_TREE_ITEM = `${TREE_ITEM}[aria-current]:not([aria-current="false"])`;
8
+ const TABBABLE_TREE_ITEM = `${TREE_ITEM}[tabindex="0"]`;
9
+ const NESTED_TABBABLE = [
10
+ "a[href]",
11
+ "area[href]",
12
+ "button",
13
+ "input:not([type=\"hidden\"])",
14
+ "select",
15
+ "textarea",
16
+ "iframe",
17
+ "summary",
18
+ "audio[controls]",
19
+ "video[controls]",
20
+ "[contenteditable]:not([contenteditable=\"false\"])",
21
+ "[tabindex]"
22
+ ].map((selector) => `${selector}:not(${TREE_ITEM}):not([tabindex="-1"])`).join(",");
23
+ const NAVIGATION_KEYS = /* @__PURE__ */ new Set([
24
+ "ArrowUp",
25
+ "ArrowDown",
26
+ "ArrowLeft",
27
+ "ArrowRight",
28
+ "Home",
29
+ "End",
30
+ "PageUp",
31
+ "PageDown",
32
+ "Backspace"
33
+ ]);
34
+ /**
35
+ * Roving tabindex and arrow key navigation for `TreeView`.
36
+ *
37
+ * Items render `tabIndex={-1}` (or `0` for the item that is current when it mounts), so this hook
38
+ * only has to pick one tab stop, keep it in sync with focus, and take nested controls out of the
39
+ * tab order. It doesn't rewrite every treeitem on mount, which is what made `useFocusZone`
40
+ * expensive for large trees.
41
+ */
42
+ function useTreeRovingTabIndex(t0) {
43
+ const $ = c(5);
44
+ const { containerRef, mouseDownRef, preventScroll: t1 } = t0;
45
+ const preventScroll = t1 === void 0 ? true : t1;
46
+ let t2;
47
+ let t3;
48
+ if ($[0] !== containerRef || $[1] !== mouseDownRef || $[2] !== preventScroll) {
49
+ t2 = () => {
50
+ const root = containerRef.current;
51
+ if (!root) return;
52
+ const container = root;
53
+ let tabStop = null;
54
+ const setTabStop = function setTabStop(element) {
55
+ var _tabStop;
56
+ if (element === tabStop) return;
57
+ (_tabStop = tabStop) === null || _tabStop === void 0 || _tabStop.setAttribute("tabindex", "-1");
58
+ element === null || element === void 0 || element.setAttribute("tabindex", "0");
59
+ tabStop = element;
60
+ };
61
+ const getPreferredItem = function getPreferredItem(t4) {
62
+ var _ref, _container$querySelec;
63
+ const candidate = t4 === void 0 ? null : t4;
64
+ return (_ref = (_container$querySelec = container.querySelector(CURRENT_TREE_ITEM)) !== null && _container$querySelec !== void 0 ? _container$querySelec : candidate) !== null && _ref !== void 0 ? _ref : container.querySelector(TREE_ITEM);
65
+ };
66
+ const removeElementFromTabOrder = function removeElementFromTabOrder(element_0) {
67
+ if (element_0.matches(NESTED_TABBABLE) || element_0 !== tabStop && element_0.matches(TABBABLE_TREE_ITEM)) element_0.setAttribute("tabindex", "-1");
68
+ };
69
+ const removeFromTabOrder = function removeFromTabOrder(root_0) {
70
+ removeElementFromTabOrder(root_0);
71
+ for (const element_1 of root_0.querySelectorAll(NESTED_TABBABLE)) element_1.setAttribute("tabindex", "-1");
72
+ for (const element_2 of root_0.querySelectorAll(TABBABLE_TREE_ITEM)) if (element_2 !== tabStop) element_2.setAttribute("tabindex", "-1");
73
+ };
74
+ const activeElement = document.activeElement;
75
+ setTabStop(getPreferredItem(activeElement instanceof HTMLElement && container.contains(activeElement) && activeElement.getAttribute("role") === "treeitem" ? activeElement : null));
76
+ removeFromTabOrder(container);
77
+ const observer = new MutationObserver((mutations) => {
78
+ for (const mutation of mutations) {
79
+ if (mutation.type === "attributes") {
80
+ if (mutation.target instanceof Element) removeElementFromTabOrder(mutation.target);
81
+ continue;
82
+ }
83
+ for (const node of mutation.addedNodes) if (node instanceof Element) removeFromTabOrder(node);
84
+ }
85
+ if (!tabStop || !container.contains(tabStop)) {
86
+ tabStop = null;
87
+ setTabStop(getPreferredItem());
88
+ }
89
+ });
90
+ observer.observe(container, {
91
+ childList: true,
92
+ subtree: true,
93
+ attributeFilter: [
94
+ "href",
95
+ "tabindex",
96
+ "contenteditable",
97
+ "controls"
98
+ ]
99
+ });
100
+ const onFocusIn = function onFocusIn(event) {
101
+ const target = event.target;
102
+ if (!(target instanceof HTMLElement)) return;
103
+ const isTreeItem = target.getAttribute("role") === "treeitem";
104
+ const from = event.relatedTarget;
105
+ if (from instanceof Element && !container.contains(from) && !(mouseDownRef !== null && mouseDownRef !== void 0 && mouseDownRef.current)) {
106
+ const preferred = getPreferredItem(isTreeItem ? target : null);
107
+ if (preferred && preferred !== target) {
108
+ preferred.focus({ preventScroll });
109
+ return;
110
+ }
111
+ }
112
+ if (isTreeItem) setTabStop(target);
113
+ };
114
+ const onKeyDown = function onKeyDown(event_0) {
115
+ var _getNextFocusableElem;
116
+ if (event_0.defaultPrevented || !NAVIGATION_KEYS.has(event_0.key)) return;
117
+ if ((event_0.key === "ArrowLeft" || event_0.key === "ArrowRight") && (event_0.altKey || event_0.metaKey)) return;
118
+ const from_0 = document.activeElement;
119
+ if (!(from_0 instanceof HTMLElement)) return;
120
+ try {
121
+ if (from_0.closest("dialog:modal")) return;
122
+ } catch {}
123
+ if (from_0.getAttribute("role") !== "treeitem") {
124
+ if (!isEditableElement(from_0)) event_0.preventDefault();
125
+ return;
126
+ }
127
+ ((_getNextFocusableElem = getNextFocusableElement(from_0, event_0)) !== null && _getNextFocusableElem !== void 0 ? _getNextFocusableElem : from_0).focus({ preventScroll });
128
+ event_0.preventDefault();
129
+ };
130
+ container.addEventListener("focusin", onFocusIn);
131
+ container.addEventListener("keydown", onKeyDown);
132
+ return () => {
133
+ observer.disconnect();
134
+ container.removeEventListener("focusin", onFocusIn);
135
+ container.removeEventListener("keydown", onKeyDown);
136
+ };
137
+ };
138
+ t3 = [
139
+ containerRef,
140
+ mouseDownRef,
141
+ preventScroll
142
+ ];
143
+ $[0] = containerRef;
144
+ $[1] = mouseDownRef;
145
+ $[2] = preventScroll;
146
+ $[3] = t2;
147
+ $[4] = t3;
148
+ } else {
149
+ t2 = $[3];
150
+ t3 = $[4];
151
+ }
152
+ useEffect(t2, t3);
153
+ }
154
+ //#endregion
155
+ export { useTreeRovingTabIndex };
@@ -25,7 +25,7 @@ import { ActionsProps, PageHeader, PageHeaderProps, TitleProps } from "../PageHe
25
25
  import { SkeletonBox, SkeletonBoxProps } from "../Skeleton/SkeletonBox.js";
26
26
  import { BlankslateProps } from "../Blankslate/Blankslate.js";
27
27
  import { Blankslate as BlankslateContainer } from "../Blankslate/index.js";
28
- import { CardActionProps as ActionProps, CardDescriptionProps as DescriptionProps, CardHeadingProps as HeadingProps, CardIconProps as IconProps, CardImageProps as ImageProps, CardMetadataProps as MetadataProps, CardProps } from "../Card/Card.js";
28
+ import { CardActionProps as ActionProps, CardButtonProps as ButtonProps, CardDescriptionProps as DescriptionProps, CardHeadingProps as HeadingProps, CardIconProps as IconProps, CardImageProps as ImageProps, CardLinkProps as LinkProps, CardMetadataProps as MetadataProps, CardProps } from "../Card/Card.js";
29
29
  import { Card } from "../Card/index.js";
30
30
  import { TableBulkActionsProps } from "../DataTable/TableBulkActions.js";
31
31
  import { DataTable, DataTableBulkActionsContext, DataTableProps } from "../DataTable/DataTable.js";
@@ -52,4 +52,4 @@ import { useTabPanel } from "./Tabs/useTabPanel.js";
52
52
  import { TopicTagProps } from "../TopicTag/TopicTag.js";
53
53
  import { TopicTagGroupProps } from "../TopicTag/TopicTagGroup.js";
54
54
  import { TopicTag } from "../TopicTag/index.js";
55
- export { ActionBar, type ActionBarButtonProps, type ActionBarMenuItemProps, type ActionBarMenuProps, type ActionBarProps, Announce, type AnnounceProps, AriaAlert, type AriaAlertProps, AriaStatus, type AriaStatusProps, BlankslateContainer as Blankslate, type BlankslateProps, ButtonBase, type ButtonBaseProps, Card, type ActionProps as CardActionProps, type DescriptionProps as CardDescriptionProps, type HeadingProps as CardHeadingProps, type IconProps as CardIconProps, type ImageProps as CardImageProps, type MetadataProps as CardMetadataProps, type CardProps, type CellAlignment, type Column, type ColumnWidth, DataTable, type DataTableBulkActionsContext, type DataTableData, type DataTableProps, type DataTableRowGroup, type DataTableRowId, DefaultFeatureFlags, Dialog, type DialogButtonProps, type DialogHeaderProps, type DialogHeight, type DialogProps, type DialogWidth, FeatureFlags, type FeatureFlagsProps, FilteredActionList, type FilteredActionListInputProps, FilteredActionListLoadingTypes, type FilteredActionListProps, Hidden, type HiddenProps, InlineMessage, type InlineMessageProps, IssueLabel, type IssueLabelProps, KeybindingHint, type KeybindingHintProps, NavList, type NavListDividerProps, type NavListGroupProps, type NavListItemProps, type NavListLeadingVisualProps, type NavListProps, type NavListSubNavProps, type NavListTrailingVisualProps, type ObjectPaths, PageHeader, type ActionsProps as PageHeaderActionsProps, type PageHeaderProps, type TitleProps as PageHeaderTitleProps, ScrollableRegion, type ScrollableRegionProps, SelectPanel, type SelectPanelMessageProps, type SelectPanelProps, type SelectPanelSecondaryActionProps, SkeletonAvatar, type SkeletonAvatarProps, SkeletonBox, type SkeletonBoxProps, SkeletonText, type SkeletonTextProps, SlotConfig, Stack, type StackItemProps, type StackProps, type TabListProps, type TabPanelProps, type TabProps, Table, type TableActionsProps, type TableBodyProps, type TableBulkActionsProps, type TableCellProps, type TableContainerProps, type TableGroupProps, type TableHeadProps, type TableHeaderProps, type TableProps, type TableRowProps, type TableRowSelectionProps, type TableSelectionHeaderProps, type TableSubtitleProps, type TableTitleProps, Tabs, type TabsProps, type TitleProps, Tooltip, type TooltipProps, TopicTag, type TopicTagGroupProps, type TopicTagProps, _default as UnderlinePanels, type PanelProps as UnderlinePanelsPanelProps, type UnderlinePanelsProps, type TabProps$1 as UnderlinePanelsTabProps, type UniqueRow, createColumnHelper, getAccessibleKeybindingHintString, useFeatureFlag, useOverflow, useSlots, useTab, useTabList, useTabPanel };
55
+ export { ActionBar, type ActionBarButtonProps, type ActionBarMenuItemProps, type ActionBarMenuProps, type ActionBarProps, Announce, type AnnounceProps, AriaAlert, type AriaAlertProps, AriaStatus, type AriaStatusProps, BlankslateContainer as Blankslate, type BlankslateProps, ButtonBase, type ButtonBaseProps, Card, type ActionProps as CardActionProps, type ButtonProps as CardButtonProps, type DescriptionProps as CardDescriptionProps, type HeadingProps as CardHeadingProps, type IconProps as CardIconProps, type ImageProps as CardImageProps, type LinkProps as CardLinkProps, type MetadataProps as CardMetadataProps, type CardProps, type CellAlignment, type Column, type ColumnWidth, DataTable, type DataTableBulkActionsContext, type DataTableData, type DataTableProps, type DataTableRowGroup, type DataTableRowId, DefaultFeatureFlags, Dialog, type DialogButtonProps, type DialogHeaderProps, type DialogHeight, type DialogProps, type DialogWidth, FeatureFlags, type FeatureFlagsProps, FilteredActionList, type FilteredActionListInputProps, FilteredActionListLoadingTypes, type FilteredActionListProps, Hidden, type HiddenProps, InlineMessage, type InlineMessageProps, IssueLabel, type IssueLabelProps, KeybindingHint, type KeybindingHintProps, NavList, type NavListDividerProps, type NavListGroupProps, type NavListItemProps, type NavListLeadingVisualProps, type NavListProps, type NavListSubNavProps, type NavListTrailingVisualProps, type ObjectPaths, PageHeader, type ActionsProps as PageHeaderActionsProps, type PageHeaderProps, type TitleProps as PageHeaderTitleProps, ScrollableRegion, type ScrollableRegionProps, SelectPanel, type SelectPanelMessageProps, type SelectPanelProps, type SelectPanelSecondaryActionProps, SkeletonAvatar, type SkeletonAvatarProps, SkeletonBox, type SkeletonBoxProps, SkeletonText, type SkeletonTextProps, SlotConfig, Stack, type StackItemProps, type StackProps, type TabListProps, type TabPanelProps, type TabProps, Table, type TableActionsProps, type TableBodyProps, type TableBulkActionsProps, type TableCellProps, type TableContainerProps, type TableGroupProps, type TableHeadProps, type TableHeaderProps, type TableProps, type TableRowProps, type TableRowSelectionProps, type TableSelectionHeaderProps, type TableSubtitleProps, type TableTitleProps, Tabs, type TabsProps, type TitleProps, Tooltip, type TooltipProps, TopicTag, type TopicTagGroupProps, type TopicTagProps, _default as UnderlinePanels, type PanelProps as UnderlinePanelsPanelProps, type UnderlinePanelsProps, type TabProps$1 as UnderlinePanelsTabProps, type UniqueRow, createColumnHelper, getAccessibleKeybindingHintString, useFeatureFlag, useOverflow, useSlots, useTab, useTabList, useTabPanel };
@@ -12,6 +12,8 @@
12
12
  * callback. Each callback has the chance to call `.preventDefault()` on the
13
13
  * event to prevent further callbacks.
14
14
  *
15
+ * Callback changes do not re-register the document listener.
16
+ *
15
17
  * @param callback {(e: KeyboardEvent) => void} The callback that gets executed
16
18
  * when the Escape key is pressed. The KeyboardEvent generated by the Escape
17
19
  * keypress is passed as the only argument.
@@ -1,4 +1,5 @@
1
- import { useCallback, useEffect, useMemo } from "react";
1
+ import { useEffectCallback } from "../internal/hooks/useEffectCallback.js";
2
+ import { useCallback, useEffect, useState } from "react";
2
3
  //#region src/hooks/useOnEscapePress.ts
3
4
  /**
4
5
  * Calls all handlers in reverse order
@@ -31,6 +32,8 @@ let handlerId = 0;
31
32
  * callback. Each callback has the chance to call `.preventDefault()` on the
32
33
  * event to prevent further callbacks.
33
34
  *
35
+ * Callback changes do not re-register the document listener.
36
+ *
34
37
  * @param callback {(e: KeyboardEvent) => void} The callback that gets executed
35
38
  * when the Escape key is pressed. The KeyboardEvent generated by the Escape
36
39
  * keypress is passed as the only argument.
@@ -41,10 +44,14 @@ let handlerId = 0;
41
44
  */
42
45
  const useOnEscapePress = (onEscape, callbackDependencies = [onEscape]) => {
43
46
  const escapeCallback = useCallback(onEscape, callbackDependencies);
44
- const handler = useCallback((event) => {
47
+ const handler = useEffectCallback((event) => {
45
48
  if (event.key === "Escape") escapeCallback(event);
46
- }, [escapeCallback]);
47
- const id = useMemo(() => handlerId++, []);
49
+ });
50
+ const [id] = useState(() => {
51
+ const id = handlerId;
52
+ handlerId += 1;
53
+ return id;
54
+ });
48
55
  useEffect(() => {
49
56
  if (Object.keys(registry).length === 0) document.addEventListener("keydown", handleEscape);
50
57
  register(id, handler);
@@ -1,4 +1,5 @@
1
1
  import { c } from "../utils/react-compiler-runtime.js";
2
+ import { useEffectCallback } from "../internal/hooks/useEffectCallback.js";
2
3
  import { useEffect, useState } from "react";
3
4
  //#region src/hooks/useOnOutsideClick.tsx
4
5
  const stopPropagation = true;
@@ -40,7 +41,7 @@ const useOnOutsideClick = (t0) => {
40
41
  $[2] = onClickOutside;
41
42
  $[3] = t1;
42
43
  } else t1 = $[3];
43
- const handler = t1;
44
+ const handler = useEffectCallback(t1);
44
45
  let t2;
45
46
  let t3;
46
47
  if ($[4] !== handler || $[5] !== id_0) {
package/dist/index.js CHANGED
@@ -59,7 +59,6 @@ import Avatar from "./Avatar/Avatar.js";
59
59
  import AvatarStack from "./AvatarStack/AvatarStack.js";
60
60
  import { Banner } from "./Banner/index.js";
61
61
  import BranchName_default from "./BranchName/BranchName.js";
62
- import Details from "./Details/Details.js";
63
62
  import Breadcrumbs_default, { Breadcrumb } from "./Breadcrumbs/Breadcrumbs.js";
64
63
  import ButtonGroup from "./ButtonGroup/ButtonGroup.js";
65
64
  import { Stack } from "./Stack/index.js";
@@ -74,6 +73,7 @@ import Textarea from "./Textarea/Textarea.js";
74
73
  import FormControl_default from "./FormControl/FormControl.js";
75
74
  import CheckboxGroup_default from "./CheckboxGroup/CheckboxGroup.js";
76
75
  import CircleBadge_default from "./CircleBadge/CircleBadge.js";
76
+ import Details from "./Details/Details.js";
77
77
  import Flash from "./Flash/Flash.js";
78
78
  import Header_default from "./Header/Header.js";
79
79
  import Label_default from "./Label/index.js";