@primer/react 0.0.0-20260623191445 → 0.0.0-20260623192517

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/CHANGELOG.md CHANGED
@@ -1,6 +1,14 @@
1
1
  # @primer/react
2
2
 
3
- ## 0.0.0-20260623191445
3
+ ## 0.0.0-20260623192517
4
+
5
+ ### Minor Changes
6
+
7
+ - [#8031](https://github.com/primer/react/pull/8031) [`10048b5`](https://github.com/primer/react/commit/10048b5d5e02dfc7bdb595683b43d2d26cb82ccd) Thanks [@janmaarten-a11y](https://github.com/janmaarten-a11y)! - Add a `NavList.Heading` slot that names the navigation region. It renders an `h2`
8
+ by default (configurable to `h3` via `as`), supports a `visuallyHidden` variant,
9
+ labels the `nav` landmark via `aria-labelledby`, and makes `NavList.Group`
10
+ headings default to one level deeper (`h3`, or `h4` under an `h3` heading) for a
11
+ correct heading hierarchy.
4
12
 
5
13
  ### Patch Changes
6
14
 
@@ -14,8 +22,6 @@
14
22
 
15
23
  - [#8021](https://github.com/primer/react/pull/8021) [`6131a94`](https://github.com/primer/react/commit/6131a9424b5bd5bb98b7ae05771d8187fe2f58cd) Thanks [@mattcosta7](https://github.com/mattcosta7)! - TextInput: Improve typing performance by deriving the character counter in render instead of in effects, removing extra re-renders on each keystroke.
16
24
 
17
- - [#8037](https://github.com/primer/react/pull/8037) [`7749e0d`](https://github.com/primer/react/commit/7749e0da6eaf7baec66a106846e8159880cd434f) Thanks [@liuliu-dev](https://github.com/liuliu-dev)! - Fix `UnderlineNav` not re-rendering when child tabs are added, removed, or reordered.
18
-
19
25
  ## 38.29.0
20
26
 
21
27
  ### Minor Changes
@@ -0,0 +1,2 @@
1
+ .prc-NavList-Heading--JQMj{margin-block-end:var(--base-size-8,.5rem);margin-inline-start:calc(var(--control-medium-paddingInline-condensed,.5rem) + var(--base-size-8,.5rem))}.prc-NavList-GroupHeading-mN50z>a{color:var(--fgColor-default,#1f2328);text-decoration:inherit}.prc-NavList-GroupHeading-mN50z>a:hover{-webkit-text-decoration:underline;text-decoration:underline}
2
+ /*# sourceMappingURL=NavList-b50d982b.css.map */
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/NavList/NavList.module.css.js"],"names":[],"mappings":"AAAA,2BACE,yCAAoC,CAEpC,wGACF,CAEA,kCACE,oCAA6B,CAC7B,uBACF,CAEA,wCACE,iCAA0B,CAA1B,yBACF","file":"NavList-b50d982b.css","sourcesContent":[".Heading {\n margin-block-end: var(--base-size-8);\n /* stylelint-disable-next-line primer/spacing */\n margin-inline-start: calc(var(--control-medium-paddingInline-condensed) + var(--base-size-8));\n}\n\n.GroupHeading > a {\n color: var(--fgColor-default);\n text-decoration: inherit;\n}\n\n.GroupHeading > a:hover {\n text-decoration: underline;\n}\n"]}
@@ -3,9 +3,17 @@ import type { ForwardRefComponent as PolymorphicForwardRefComponent } from '../u
3
3
  import React from 'react';
4
4
  import type { ActionListTrailingActionProps, ActionListDividerProps, ActionListLeadingVisualProps, ActionListTrailingVisualProps, ActionListGroupHeadingProps } from '../ActionList';
5
5
  import { type PolymorphicProps } from '../utils/modern-polymorphic';
6
+ import type { FCWithSlotMarker } from '../utils/types/Slots';
7
+ type NavListHeadingLevels = 'h2' | 'h3';
6
8
  export type NavListProps = {
7
9
  children: React.ReactNode;
8
10
  } & React.ComponentProps<'nav'>;
11
+ export type NavListHeadingProps = {
12
+ /** Semantic heading level for the NavList. Also sets the default level for child group headings, which render one level deeper. */
13
+ as?: NavListHeadingLevels;
14
+ /** Visually hide the heading while keeping it available to assistive technology. */
15
+ visuallyHidden?: boolean;
16
+ } & React.ComponentPropsWithoutRef<'h2'>;
9
17
  export type NavListItemProps<As extends React.ElementType = React.ElementType> = PolymorphicProps<As, 'a', {
10
18
  children: React.ReactNode;
11
19
  defaultOpen?: boolean;
@@ -40,7 +48,8 @@ export type NavListGroupExpandProps = {
40
48
  export declare const GroupExpand: React.ForwardRefExoticComponent<NavListGroupExpandProps & React.RefAttributes<HTMLButtonElement>>;
41
49
  export type NavListGroupHeadingProps = ActionListGroupHeadingProps;
42
50
  export declare const NavList: React.ForwardRefExoticComponent<Omit<NavListProps, "ref"> & React.RefAttributes<HTMLElement>> & {
43
- Description: import("..").FCWithSlotMarker<React.PropsWithChildren<import("..").ActionListDescriptionProps>>;
51
+ Description: FCWithSlotMarker<React.PropsWithChildren<import("..").ActionListDescriptionProps>>;
52
+ Heading: FCWithSlotMarker<NavListHeadingProps>;
44
53
  Item: (<As extends React.ElementType = "a">(props: import("../utils/modern-polymorphic").DistributiveOmit<React.ComponentPropsWithRef<React.ElementType extends As ? "a" : As> & {
45
54
  children: React.ReactNode;
46
55
  defaultOpen?: boolean;
@@ -53,10 +62,10 @@ export declare const NavList: React.ForwardRefExoticComponent<Omit<NavListProps,
53
62
  displayName: string;
54
63
  };
55
64
  SubNav: PolymorphicForwardRefComponent<"ul", NavListSubNavProps>;
56
- LeadingVisual: import("..").FCWithSlotMarker<React.PropsWithChildren<import("../ActionList/Visuals").VisualProps>>;
57
- TrailingVisual: import("..").FCWithSlotMarker<React.PropsWithChildren<import("../ActionList/Visuals").VisualProps>>;
65
+ LeadingVisual: FCWithSlotMarker<React.PropsWithChildren<import("../ActionList/Visuals").VisualProps>>;
66
+ TrailingVisual: FCWithSlotMarker<React.PropsWithChildren<import("../ActionList/Visuals").VisualProps>>;
58
67
  TrailingAction: PolymorphicForwardRefComponent<"a" | "button", ActionListTrailingActionProps>;
59
- Divider: import("..").FCWithSlotMarker<React.PropsWithChildren<ActionListDividerProps>>;
68
+ Divider: FCWithSlotMarker<React.PropsWithChildren<ActionListDividerProps>>;
60
69
  Group: React.FC<NavListGroupProps>;
61
70
  GroupExpand: React.ForwardRefExoticComponent<NavListGroupExpandProps & React.RefAttributes<HTMLButtonElement>>;
62
71
  GroupHeading: React.FC<ActionListGroupHeadingProps>;
@@ -1 +1 @@
1
- {"version":3,"file":"NavList.d.ts","sourceRoot":"","sources":["../../src/NavList/NavList.tsx"],"names":[],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AmB,GAAG,sBAAsB,CAAA;AAQxD,MAAM,MAAM,0BAA0B,GAAG,6BAA6B,CAAA;AAStE,MAAM,MAAM,iBAAiB,GAAG,KAAK,CAAC,cAAc,CAAC,aAAa,CAAC,GAAG;IACpE,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;IACzB,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAAA;AAyBD,KAAK,SAAS,GAAG;IACf,IAAI,EAAE,MAAM,CAAA;IACZ,cAAc,CAAC,EAAE,IAAI,GAAG,MAAM,CAAA;IAC9B,aAAa,CAAC,EAAE,IAAI,CAAA;IACpB,cAAc,CAAC,EAAE,6BAA6B,CAAA;IAC9C,0BAA0B,CAAC,EAAE,MAAM,CAAA;CACpC,GAAG,IAAI,CAAC,gBAAgB,EAAE,UAAU,CAAC,CAAA;AAEtC,MAAM,MAAM,uBAAuB,GAAG;IACpC,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,SAAS,EAAE,CAAA;IAClB,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,SAAS,KAAK,KAAK,CAAC,SAAS,CAAA;CAClD,CAAA;AAED,eAAO,MAAM,WAAW,mGAgFvB,CAAA;AAKD,MAAM,MAAM,wBAAwB,GAAG,2BAA2B,CAAA;AAuBlE,eAAO,MAAM,OAAO;;;YAnXjB,EAAE,SAAS,KAAK,CAAC,WAAW;kBATjB,KAAK,CAAC,SAAS;sBACX,OAAO;eACd,MAAM;yBACI,MAAM,GAAG,MAAM,GAAG,UAAU,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO;uBAC7E,MAAM;;;;;;;;;;;;;;CAoYvB,CAAA"}
@@ -12,65 +12,210 @@ import navListClasses from './NavList.module.css.js';
12
12
  import { flushSync } from 'react-dom';
13
13
  import { useSlots } from '../hooks/useSlots.js';
14
14
  import { fixedForwardRef } from '../utils/modern-polymorphic.js';
15
- import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
15
+ import visuallyHiddenClasses from '../_VisuallyHidden.module.css.js';
16
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
17
+ import Heading$1 from '../Heading/Heading.js';
18
+
19
+ // Publishes the resolved numeric level of a NavList.Heading (e.g. 2 for an h2) so
20
+ // NavList.Group/NavList.GroupHeading can default to one level deeper. `null` when
21
+ // there is no NavList.Heading, in which case groups keep their historical h3 default.
22
+ const NavListHeadingLevelContext = /*#__PURE__*/React.createContext(null);
23
+ function headingTagToLevel(as) {
24
+ return Number.parseInt(as.slice(1), 10);
25
+ }
26
+ function levelToHeadingTag(level) {
27
+ // Clamp to h4 so group headings never go deeper than the supported hierarchy.
28
+ const clamped = Math.min(Math.max(level, 1), 4);
29
+ return `h${clamped}`;
30
+ }
31
+
32
+ // ----------------------------------------------------------------------------
33
+ // NavList
16
34
 
17
35
  const Root = /*#__PURE__*/React.forwardRef((t0, ref) => {
18
- const $ = c(10);
36
+ var _heading$props$id, _ariaLabelledby;
37
+ const $ = c(24);
38
+ let ariaLabel;
39
+ let ariaLabelledby;
19
40
  let children;
20
41
  let props;
21
42
  if ($[0] !== t0) {
22
43
  ({
23
44
  children,
45
+ "aria-label": ariaLabel,
46
+ "aria-labelledby": ariaLabelledby,
24
47
  ...props
25
48
  } = t0);
26
49
  $[0] = t0;
27
- $[1] = children;
28
- $[2] = props;
50
+ $[1] = ariaLabel;
51
+ $[2] = ariaLabelledby;
52
+ $[3] = children;
53
+ $[4] = props;
29
54
  } else {
30
- children = $[1];
31
- props = $[2];
55
+ ariaLabel = $[1];
56
+ ariaLabelledby = $[2];
57
+ children = $[3];
58
+ props = $[4];
32
59
  }
33
60
  let t1;
34
- if ($[3] === Symbol.for("react.memo_cache_sentinel")) {
61
+ if ($[5] === Symbol.for("react.memo_cache_sentinel")) {
35
62
  t1 = {
36
- container: "NavList"
63
+ heading: Heading
37
64
  };
38
- $[3] = t1;
65
+ $[5] = t1;
39
66
  } else {
40
- t1 = $[3];
67
+ t1 = $[5];
41
68
  }
69
+ const [slots, childrenWithoutHeading] = useSlots(children, t1);
70
+ const fallbackHeadingId = useId();
71
+ const heading = slots.heading;
72
+ const headingId = heading ? (_heading$props$id = heading.props.id) !== null && _heading$props$id !== void 0 ? _heading$props$id : fallbackHeadingId : undefined;
42
73
  let t2;
43
- if ($[4] !== children) {
44
- t2 = /*#__PURE__*/jsx(ActionListContainerContext.Provider, {
45
- value: t1,
74
+ if ($[6] !== heading) {
75
+ var _heading$props$as;
76
+ t2 = heading ? headingTagToLevel((_heading$props$as = heading.props.as) !== null && _heading$props$as !== void 0 ? _heading$props$as : "h2") : null;
77
+ $[6] = heading;
78
+ $[7] = t2;
79
+ } else {
80
+ t2 = $[7];
81
+ }
82
+ const headingLevel = t2;
83
+ const navLabelledby = (_ariaLabelledby = ariaLabelledby) !== null && _ariaLabelledby !== void 0 ? _ariaLabelledby : ariaLabel ? undefined : headingId;
84
+ let t3;
85
+ if ($[8] !== heading || $[9] !== headingId) {
86
+ t3 = heading ? /*#__PURE__*/React.cloneElement(heading, {
87
+ id: headingId
88
+ }) : null;
89
+ $[8] = heading;
90
+ $[9] = headingId;
91
+ $[10] = t3;
92
+ } else {
93
+ t3 = $[10];
94
+ }
95
+ let t4;
96
+ if ($[11] === Symbol.for("react.memo_cache_sentinel")) {
97
+ t4 = {
98
+ container: "NavList"
99
+ };
100
+ $[11] = t4;
101
+ } else {
102
+ t4 = $[11];
103
+ }
104
+ let t5;
105
+ if ($[12] !== childrenWithoutHeading) {
106
+ t5 = /*#__PURE__*/jsx(ActionListContainerContext.Provider, {
107
+ value: t4,
46
108
  children: /*#__PURE__*/jsx(ActionList, {
47
- children: children
109
+ children: childrenWithoutHeading
48
110
  })
49
111
  });
50
- $[4] = children;
51
- $[5] = t2;
112
+ $[12] = childrenWithoutHeading;
113
+ $[13] = t5;
52
114
  } else {
53
- t2 = $[5];
115
+ t5 = $[13];
54
116
  }
55
- let t3;
56
- if ($[6] !== props || $[7] !== ref || $[8] !== t2) {
57
- t3 = /*#__PURE__*/jsx("nav", {
117
+ let t6;
118
+ if ($[14] !== headingLevel || $[15] !== t3 || $[16] !== t5) {
119
+ t6 = /*#__PURE__*/jsxs(NavListHeadingLevelContext.Provider, {
120
+ value: headingLevel,
121
+ children: [t3, t5]
122
+ });
123
+ $[14] = headingLevel;
124
+ $[15] = t3;
125
+ $[16] = t5;
126
+ $[17] = t6;
127
+ } else {
128
+ t6 = $[17];
129
+ }
130
+ let t7;
131
+ if ($[18] !== ariaLabel || $[19] !== navLabelledby || $[20] !== props || $[21] !== ref || $[22] !== t6) {
132
+ t7 = /*#__PURE__*/jsx("nav", {
58
133
  ...props,
134
+ "aria-label": ariaLabel,
135
+ "aria-labelledby": navLabelledby,
59
136
  ref: ref,
60
137
  "data-component": "NavList",
61
- children: t2
138
+ children: t6
62
139
  });
63
- $[6] = props;
64
- $[7] = ref;
65
- $[8] = t2;
66
- $[9] = t3;
140
+ $[18] = ariaLabel;
141
+ $[19] = navLabelledby;
142
+ $[20] = props;
143
+ $[21] = ref;
144
+ $[22] = t6;
145
+ $[23] = t7;
67
146
  } else {
68
- t3 = $[9];
147
+ t7 = $[23];
69
148
  }
70
- return t3;
149
+ return t7;
71
150
  });
72
151
  Root.displayName = 'NavList';
73
152
 
153
+ // ----------------------------------------------------------------------------
154
+ // NavList.Heading
155
+
156
+ const Heading = t0 => {
157
+ const $ = c(14);
158
+ let children;
159
+ let className;
160
+ let props;
161
+ let t1;
162
+ let t2;
163
+ if ($[0] !== t0) {
164
+ ({
165
+ as: t1,
166
+ visuallyHidden: t2,
167
+ className,
168
+ children,
169
+ ...props
170
+ } = t0);
171
+ $[0] = t0;
172
+ $[1] = children;
173
+ $[2] = className;
174
+ $[3] = props;
175
+ $[4] = t1;
176
+ $[5] = t2;
177
+ } else {
178
+ children = $[1];
179
+ className = $[2];
180
+ props = $[3];
181
+ t1 = $[4];
182
+ t2 = $[5];
183
+ }
184
+ const as = t1 === undefined ? "h2" : t1;
185
+ const visuallyHidden = t2 === undefined ? false : t2;
186
+ const t3 = visuallyHidden ? visuallyHiddenClasses.InternalVisuallyHidden : navListClasses.Heading;
187
+ let t4;
188
+ if ($[6] !== className || $[7] !== t3) {
189
+ t4 = clsx(t3, className);
190
+ $[6] = className;
191
+ $[7] = t3;
192
+ $[8] = t4;
193
+ } else {
194
+ t4 = $[8];
195
+ }
196
+ let t5;
197
+ if ($[9] !== as || $[10] !== children || $[11] !== props || $[12] !== t4) {
198
+ t5 = /*#__PURE__*/jsx(Heading$1, {
199
+ as: as,
200
+ variant: "small",
201
+ className: t4,
202
+ "data-component": "NavList.Heading",
203
+ ...props,
204
+ children: children
205
+ });
206
+ $[9] = as;
207
+ $[10] = children;
208
+ $[11] = props;
209
+ $[12] = t4;
210
+ $[13] = t5;
211
+ } else {
212
+ t5 = $[13];
213
+ }
214
+ return t5;
215
+ };
216
+ Heading.displayName = 'NavList.Heading';
217
+ Heading.__SLOT__ = Symbol('NavList.Heading');
218
+
74
219
  // ----------------------------------------------------------------------------
75
220
  // NavList.Item
76
221
 
@@ -398,7 +543,7 @@ TrailingAction.displayName = 'NavList.TrailingAction';
398
543
  // NavList.Group
399
544
 
400
545
  const Group = t0 => {
401
- const $ = c(11);
546
+ const $ = c(14);
402
547
  let children;
403
548
  let props;
404
549
  let title;
@@ -417,41 +562,52 @@ const Group = t0 => {
417
562
  props = $[2];
418
563
  title = $[3];
419
564
  }
565
+ const headingLevel = React.useContext(NavListHeadingLevelContext);
420
566
  let t1;
421
- if ($[4] === Symbol.for("react.memo_cache_sentinel")) {
422
- t1 = /*#__PURE__*/jsx(ActionList.Divider, {});
423
- $[4] = t1;
567
+ if ($[4] !== headingLevel) {
568
+ t1 = headingLevel ? levelToHeadingTag(headingLevel + 1) : "h3";
569
+ $[4] = headingLevel;
570
+ $[5] = t1;
424
571
  } else {
425
- t1 = $[4];
572
+ t1 = $[5];
426
573
  }
574
+ const groupHeadingAs = t1;
427
575
  let t2;
428
- if ($[5] !== title) {
429
- t2 = title ? /*#__PURE__*/jsx(ActionList.GroupHeading, {
430
- as: "h3",
431
- "data-component": "ActionList.GroupHeading",
432
- children: title
433
- }) : null;
434
- $[5] = title;
576
+ if ($[6] === Symbol.for("react.memo_cache_sentinel")) {
577
+ t2 = /*#__PURE__*/jsx(ActionList.Divider, {});
435
578
  $[6] = t2;
436
579
  } else {
437
580
  t2 = $[6];
438
581
  }
439
582
  let t3;
440
- if ($[7] !== children || $[8] !== props || $[9] !== t2) {
441
- t3 = /*#__PURE__*/jsxs(Fragment, {
442
- children: [t1, /*#__PURE__*/jsxs(ActionList.Group, {
583
+ if ($[7] !== groupHeadingAs || $[8] !== title) {
584
+ t3 = title ? /*#__PURE__*/jsx(ActionList.GroupHeading, {
585
+ as: groupHeadingAs,
586
+ "data-component": "ActionList.GroupHeading",
587
+ children: title
588
+ }) : null;
589
+ $[7] = groupHeadingAs;
590
+ $[8] = title;
591
+ $[9] = t3;
592
+ } else {
593
+ t3 = $[9];
594
+ }
595
+ let t4;
596
+ if ($[10] !== children || $[11] !== props || $[12] !== t3) {
597
+ t4 = /*#__PURE__*/jsxs(Fragment, {
598
+ children: [t2, /*#__PURE__*/jsxs(ActionList.Group, {
443
599
  ...props,
444
- children: [t2, children]
600
+ children: [t3, children]
445
601
  })]
446
602
  });
447
- $[7] = children;
448
- $[8] = props;
449
- $[9] = t2;
450
- $[10] = t3;
603
+ $[10] = children;
604
+ $[11] = props;
605
+ $[12] = t3;
606
+ $[13] = t4;
451
607
  } else {
452
- t3 = $[10];
608
+ t4 = $[13];
453
609
  }
454
- return t3;
610
+ return t4;
455
611
  };
456
612
  // ----------------------------------------------------------------------------
457
613
  // NavList.GroupExpand
@@ -593,49 +749,60 @@ const GroupExpand = /*#__PURE__*/React.forwardRef((t0, forwardedRef) => {
593
749
  * It was primarily added to allow links in group headings.
594
750
  */
595
751
  const GroupHeading = t0 => {
596
- const $ = c(10);
752
+ const $ = c(13);
753
+ let as;
597
754
  let className;
598
755
  let rest;
599
- let t1;
600
756
  if ($[0] !== t0) {
601
757
  ({
602
- as: t1,
758
+ as,
603
759
  className,
604
760
  ...rest
605
761
  } = t0);
606
762
  $[0] = t0;
607
- $[1] = className;
608
- $[2] = rest;
609
- $[3] = t1;
763
+ $[1] = as;
764
+ $[2] = className;
765
+ $[3] = rest;
766
+ } else {
767
+ as = $[1];
768
+ className = $[2];
769
+ rest = $[3];
770
+ }
771
+ const headingLevel = React.useContext(NavListHeadingLevelContext);
772
+ let t1;
773
+ if ($[4] !== as || $[5] !== headingLevel) {
774
+ var _as;
775
+ t1 = (_as = as) !== null && _as !== void 0 ? _as : headingLevel ? levelToHeadingTag(headingLevel + 1) : "h3";
776
+ $[4] = as;
777
+ $[5] = headingLevel;
778
+ $[6] = t1;
610
779
  } else {
611
- className = $[1];
612
- rest = $[2];
613
- t1 = $[3];
780
+ t1 = $[6];
614
781
  }
615
- const as = t1 === undefined ? "h3" : t1;
782
+ const resolvedAs = t1;
616
783
  let t2;
617
- if ($[4] !== className) {
784
+ if ($[7] !== className) {
618
785
  t2 = clsx(navListClasses.GroupHeading, className);
619
- $[4] = className;
620
- $[5] = t2;
786
+ $[7] = className;
787
+ $[8] = t2;
621
788
  } else {
622
- t2 = $[5];
789
+ t2 = $[8];
623
790
  }
624
791
  let t3;
625
- if ($[6] !== as || $[7] !== rest || $[8] !== t2) {
792
+ if ($[9] !== resolvedAs || $[10] !== rest || $[11] !== t2) {
626
793
  t3 = /*#__PURE__*/jsx(ActionList.GroupHeading, {
627
- as: as,
794
+ as: resolvedAs,
628
795
  className: t2,
629
796
  "data-component": "NavList.GroupHeading",
630
797
  headingWrapElement: "li",
631
798
  ...rest
632
799
  });
633
- $[6] = as;
634
- $[7] = rest;
635
- $[8] = t2;
636
- $[9] = t3;
800
+ $[9] = resolvedAs;
801
+ $[10] = rest;
802
+ $[11] = t2;
803
+ $[12] = t3;
637
804
  } else {
638
- t3 = $[9];
805
+ t3 = $[12];
639
806
  }
640
807
  return t3;
641
808
  };
@@ -645,6 +812,7 @@ const GroupHeading = t0 => {
645
812
 
646
813
  const NavList = Object.assign(Root, {
647
814
  Description: ActionList.Description,
815
+ Heading,
648
816
  Item,
649
817
  SubNav,
650
818
  LeadingVisual,
@@ -1,5 +1,5 @@
1
- import './NavList-5dc067e3.css';
1
+ import './NavList-b50d982b.css';
2
2
 
3
- var navListClasses = {"GroupHeading":"prc-NavList-GroupHeading-mN50z"};
3
+ var navListClasses = {"Heading":"prc-NavList-Heading--JQMj","GroupHeading":"prc-NavList-GroupHeading-mN50z"};
4
4
 
5
5
  export { navListClasses as default };
@@ -1 +1 @@
1
- {"version":3,"file":"UnderlineNav.d.ts","sourceRoot":"","sources":["../../src/UnderlineNav/UnderlineNav.tsx"],"names":[],"mappings":"AACA,OAAO,KAAkD,MAAM,OAAO,CAAA;AAqBtE,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;IACzB,YAAY,CAAC,EAAE,KAAK,CAAC,cAAc,CAAC,YAAY,CAAC,CAAA;IACjD,EAAE,CAAC,EAAE,KAAK,CAAC,WAAW,CAAA;IACtB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB;;OAEG;IACH,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAAA;CAC5B,CAAA;AAGD,eAAO,MAAM,cAAc,KAAK,CAAA;AAsGhC,eAAO,MAAM,YAAY,mFA6UxB,CAAA"}
1
+ {"version":3,"file":"UnderlineNav.d.ts","sourceRoot":"","sources":["../../src/UnderlineNav/UnderlineNav.tsx"],"names":[],"mappings":"AACA,OAAO,KAAkD,MAAM,OAAO,CAAA;AAqBtE,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;IACzB,YAAY,CAAC,EAAE,KAAK,CAAC,cAAc,CAAC,YAAY,CAAC,CAAA;IACjD,EAAE,CAAC,EAAE,KAAK,CAAC,WAAW,CAAA;IACtB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB;;OAEG;IACH,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAAA;CAC5B,CAAA;AAGD,eAAO,MAAM,cAAc,KAAK,CAAA;AAsGhC,eAAO,MAAM,YAAY,mFA0SxB,CAAA"}
@@ -130,80 +130,31 @@ const UnderlineNav = /*#__PURE__*/forwardRef(({
130
130
  const disclosureWidgetId = useId();
131
131
  const [isWidgetOpen, setIsWidgetOpen] = useState(false);
132
132
  const [iconsVisible, setIconsVisible] = useState(true);
133
- // Width measurements are stored keyed by item text so that adding/removing/reordering
134
- // children does not produce stale or out-of-order entries (as the previous append-only
135
- // arrays did). See https://github.com/github/primer/issues/6389.
136
- const [childWidthMap, setChildWidthMap] = useState({});
137
- const [noIconChildWidthMap, setNoIconChildWidthMap] = useState({});
133
+ const [childWidthArray, setChildWidthArray] = useState([]);
134
+ const [noIconChildWidthArray, setNoIconChildWidthArray] = useState([]);
138
135
  // Track whether the initial overflow calculation is complete to prevent CLS
139
136
  const [isOverflowMeasured, setIsOverflowMeasured] = useState(false);
140
137
  const validChildren = getValidChildren(children);
141
138
 
142
- // Build ordered width arrays from the current children so order always matches
143
- // `validChildren`, even after items are added, removed, or reordered.
144
- const childWidthArray = validChildren.map(child => {
145
- var _childWidthMap$text;
146
- const text = child.props.children;
147
- return {
148
- text,
149
- width: (_childWidthMap$text = childWidthMap[text]) !== null && _childWidthMap$text !== void 0 ? _childWidthMap$text : 0
150
- };
151
- });
152
- const noIconChildWidthArray = validChildren.map(child => {
153
- var _noIconChildWidthMap$;
154
- const text = child.props.children;
155
- return {
156
- text,
157
- width: (_noIconChildWidthMap$ = noIconChildWidthMap[text]) !== null && _noIconChildWidthMap$ !== void 0 ? _noIconChildWidthMap$ : 0
158
- };
159
- });
160
-
161
139
  // Responsive props object manages which items are in the list and which items are in the menu.
162
140
  const [responsiveProps, setResponsiveProps] = useState({
163
141
  items: validChildren,
164
142
  menuItems: []
165
143
  });
166
144
 
167
- // The ordered signature drives `useResizeObserver` deps below so it re-fires whenever
168
- // children are added, removed, or reordered.
169
- const childrenSignature = validChildren.map(child => {
170
- var _child$key;
171
- return String((_child$key = child.key) !== null && _child$key !== void 0 ? _child$key : '');
172
- }).join('|');
173
-
174
- // `childrenChanged` only tracks membership (set of keys), not order. This is intentional
175
- // because `swapMenuItemWithListItem` legitimately reorders `responsiveProps.items` (to keep
176
- // the selected item visible), and we don't want that to be treated as a stale-children
177
- // situation. We only need to fall back to rendering `validChildren` directly when a child
178
- // was actually added or removed (so a new item isn't missed and a removed item isn't kept).
179
- const responsiveKeys = new Set();
180
- for (const item of responsiveProps.items) {
181
- var _item$key;
182
- responsiveKeys.add(String((_item$key = item.key) !== null && _item$key !== void 0 ? _item$key : ''));
183
- }
184
- for (const item of responsiveProps.menuItems) {
185
- var _item$key2;
186
- responsiveKeys.add(String((_item$key2 = item.key) !== null && _item$key2 !== void 0 ? _item$key2 : ''));
187
- }
188
- const validKeys = validChildren.map(child => {
189
- var _child$key2;
190
- return String((_child$key2 = child.key) !== null && _child$key2 !== void 0 ? _child$key2 : '');
191
- });
192
- const childrenChanged = validKeys.length !== responsiveKeys.size || validKeys.some(key => !responsiveKeys.has(key));
193
-
194
145
  // Make sure to have the fresh props data for list items when children are changed (keeping aria-current up-to-date)
195
- const listItems = childrenChanged ? validChildren : responsiveProps.items.map(item => {
146
+ const listItems = responsiveProps.items.map(item => {
196
147
  var _validChildren$find;
197
148
  return (_validChildren$find = validChildren.find(child => child.key === item.key)) !== null && _validChildren$find !== void 0 ? _validChildren$find : item;
198
149
  });
199
150
 
200
151
  // Make sure to have the fresh props data for menu items when children are changed (keeping aria-current up-to-date)
201
- const menuItems = childrenChanged ? [] : responsiveProps.menuItems.map(menuItem => {
152
+ const menuItems = responsiveProps.menuItems.map(menuItem => {
202
153
  var _validChildren$find2;
203
154
  return (_validChildren$find2 = validChildren.find(child => child.key === menuItem.key)) !== null && _validChildren$find2 !== void 0 ? _validChildren$find2 : menuItem;
204
155
  });
205
156
  // This is the case where the viewport is too narrow to show any list item with the more menu. In this case, we only show the dropdown
206
- const onlyMenuVisible = !childrenChanged && responsiveProps.items.length === 0;
157
+ const onlyMenuVisible = responsiveProps.items.length === 0;
207
158
  useDevOnlyEffect(() => {
208
159
  // Address illegal state where there are multiple items that have `aria-current='page'` attribute
209
160
  const activeElements = validChildren.filter(child => {
@@ -261,15 +212,15 @@ const UnderlineNav = /*#__PURE__*/forwardRef(({
261
212
  }
262
213
  }, []);
263
214
  const setChildrenWidth = useCallback(size => {
264
- setChildWidthMap(prev => prev[size.text] === size.width ? prev : {
265
- ...prev,
266
- [size.text]: size.width
215
+ setChildWidthArray(arr => {
216
+ const newArr = [...arr, size];
217
+ return newArr;
267
218
  });
268
219
  }, []);
269
220
  const setNoIconChildrenWidth = useCallback(size => {
270
- setNoIconChildWidthMap(prev => prev[size.text] === size.width ? prev : {
271
- ...prev,
272
- [size.text]: size.width
221
+ setNoIconChildWidthArray(arr => {
222
+ const newArr = [...arr, size];
223
+ return newArr;
273
224
  });
274
225
  }, []);
275
226
  const closeOverlay = React.useCallback(() => {
@@ -297,17 +248,12 @@ const UnderlineNav = /*#__PURE__*/forwardRef(({
297
248
  containerRef,
298
249
  ignoreClickRefs: [moreMenuBtnRef]
299
250
  });
300
-
301
- // The resize observer fires when the nav element resizes, and re-observes (firing the
302
- // callback again with current size) whenever its deps change. Passing `childrenSignature`
303
- // ensures the overflow calculation re-runs when child tabs are added, removed, or
304
- // reordered. See https://github.com/github/primer/issues/6389.
305
251
  useResizeObserver(resizeObserverEntries => {
306
252
  var _moreMenuRef$current$, _moreMenuRef$current;
307
253
  const navWidth = resizeObserverEntries[0].contentRect.width;
308
254
  const moreMenuWidth = (_moreMenuRef$current$ = (_moreMenuRef$current = moreMenuRef.current) === null || _moreMenuRef$current === void 0 ? void 0 : _moreMenuRef$current.getBoundingClientRect().width) !== null && _moreMenuRef$current$ !== void 0 ? _moreMenuRef$current$ : 0;
309
255
  navWidth !== 0 && overflowEffect(navWidth, moreMenuWidth, validChildren, childWidthArray, noIconChildWidthArray, updateListAndMenu);
310
- }, navRef, [childrenSignature]);
256
+ }, navRef);
311
257
 
312
258
  // Compute menuInlineStyles if needed
313
259
  let menuInlineStyles = {
@@ -4169,6 +4169,46 @@
4169
4169
  }
4170
4170
  ],
4171
4171
  "subcomponents": [
4172
+ {
4173
+ "name": "NavList.Heading",
4174
+ "props": [
4175
+ {
4176
+ "name": "as",
4177
+ "type": "'h2' | 'h3'",
4178
+ "defaultValue": "\"h2\"",
4179
+ "required": false,
4180
+ "description": "Semantic heading level for the NavList. Also sets the default level for child group headings, which render one level deeper (h3 under an h2, h4 under an h3). Constrained to h2/h3 so the hierarchy stays shallow."
4181
+ },
4182
+ {
4183
+ "name": "visuallyHidden",
4184
+ "type": "boolean",
4185
+ "defaultValue": "false",
4186
+ "required": false,
4187
+ "description": "Visually hide the heading while keeping it available to assistive technology and as the accessible name for the `nav` landmark."
4188
+ },
4189
+ {
4190
+ "name": "children",
4191
+ "type": "ReactNode",
4192
+ "required": true,
4193
+ "description": "The text rendered as the NavList's heading."
4194
+ },
4195
+ {
4196
+ "name": "id",
4197
+ "type": "string",
4198
+ "description": "Custom id for the heading element. When set, it is used as the `aria-labelledby` target that names the `nav` landmark; otherwise a generated id is used."
4199
+ },
4200
+ {
4201
+ "name": "className",
4202
+ "type": "string",
4203
+ "description": "Custom CSS class name."
4204
+ },
4205
+ {
4206
+ "name": "style",
4207
+ "type": "React.CSSProperties",
4208
+ "description": "Custom CSS styles."
4209
+ }
4210
+ ]
4211
+ },
4172
4212
  {
4173
4213
  "name": "NavList.Item",
4174
4214
  "props": [
@@ -4315,10 +4355,9 @@
4315
4355
  },
4316
4356
  {
4317
4357
  "name": "as",
4318
- "description": "Heading level for the group heading. Sets the semantic heading tag.",
4358
+ "description": "Heading level for the group heading. Sets the semantic heading tag. Defaults to one level below a `NavList.Heading` (h3 under an h2, h4 under an h3), or `h3` when there is no `NavList.Heading`.",
4319
4359
  "required": false,
4320
- "type": "'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6'",
4321
- "defaultValue": "\"h3\""
4360
+ "type": "'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6'"
4322
4361
  }
4323
4362
  ]
4324
4363
  },
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@primer/react",
3
3
  "type": "module",
4
- "version": "0.0.0-20260623191445",
4
+ "version": "0.0.0-20260623192517",
5
5
  "description": "An implementation of GitHub's Primer Design System using React",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.js",
@@ -1,2 +0,0 @@
1
- .prc-NavList-GroupHeading-mN50z>a{color:var(--fgColor-default,#1f2328);text-decoration:inherit}.prc-NavList-GroupHeading-mN50z>a:hover{-webkit-text-decoration:underline;text-decoration:underline}
2
- /*# sourceMappingURL=NavList-5dc067e3.css.map */
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/NavList/NavList.module.css.js"],"names":[],"mappings":"AAAA,kCACE,oCAA6B,CAC7B,uBACF,CAEA,wCACE,iCAA0B,CAA1B,yBACF","file":"NavList-5dc067e3.css","sourcesContent":[".GroupHeading > a {\n color: var(--fgColor-default);\n text-decoration: inherit;\n}\n\n.GroupHeading > a:hover {\n text-decoration: underline;\n}\n"]}