@primer/react 0.0.0-20260602214102 → 0.0.0-20260603152335

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 (43) hide show
  1. package/CHANGELOG.md +3 -5
  2. package/dist/Autocomplete/AutocompleteInput.d.ts.map +1 -1
  3. package/dist/Autocomplete/AutocompleteInput.js +2 -14
  4. package/dist/Dialog/Dialog.d.ts +0 -1
  5. package/dist/Dialog/Dialog.d.ts.map +1 -1
  6. package/dist/Dialog/Dialog.js +2 -16
  7. package/dist/UnderlineNav/UnderlineNav-263b4e8f.css +2 -0
  8. package/dist/UnderlineNav/UnderlineNav-263b4e8f.css.map +1 -0
  9. package/dist/UnderlineNav/UnderlineNav.d.ts +0 -2
  10. package/dist/UnderlineNav/UnderlineNav.d.ts.map +1 -1
  11. package/dist/UnderlineNav/UnderlineNav.js +86 -331
  12. package/dist/UnderlineNav/UnderlineNav.module.css.js +2 -2
  13. package/dist/UnderlineNav/UnderlineNavContext.d.ts +1 -11
  14. package/dist/UnderlineNav/UnderlineNavContext.d.ts.map +1 -1
  15. package/dist/UnderlineNav/UnderlineNavContext.js +1 -4
  16. package/dist/UnderlineNav/UnderlineNavItem-402cd41c.css +2 -0
  17. package/dist/UnderlineNav/UnderlineNavItem-402cd41c.css.map +1 -0
  18. package/dist/UnderlineNav/UnderlineNavItem.d.ts +6 -0
  19. package/dist/UnderlineNav/UnderlineNavItem.d.ts.map +1 -1
  20. package/dist/UnderlineNav/UnderlineNavItem.js +36 -39
  21. package/dist/UnderlineNav/UnderlineNavItem.module.css.js +1 -1
  22. package/dist/experimental/UnderlinePanels/UnderlinePanels-162f9aed.css +2 -0
  23. package/dist/experimental/UnderlinePanels/UnderlinePanels-162f9aed.css.map +1 -0
  24. package/dist/experimental/UnderlinePanels/UnderlinePanels.module.css.js +1 -1
  25. package/dist/internal/components/UnderlineTabbedInterface-1745a3d6.css +2 -0
  26. package/dist/internal/components/UnderlineTabbedInterface-1745a3d6.css.map +1 -0
  27. package/dist/internal/components/UnderlineTabbedInterface.d.ts +0 -1
  28. package/dist/internal/components/UnderlineTabbedInterface.d.ts.map +1 -1
  29. package/dist/internal/components/UnderlineTabbedInterface.js +66 -60
  30. package/dist/internal/components/UnderlineTabbedInterface.module.css.js +1 -1
  31. package/generated/components.json +2 -2
  32. package/package.json +1 -1
  33. package/dist/UnderlineNav/UnderlineNav-4344d9b0.css +0 -2
  34. package/dist/UnderlineNav/UnderlineNav-4344d9b0.css.map +0 -1
  35. package/dist/UnderlineNav/UnderlineNavItem-b65e8fd3.css +0 -2
  36. package/dist/UnderlineNav/UnderlineNavItem-b65e8fd3.css.map +0 -1
  37. package/dist/UnderlineNav/styles.d.ts +0 -16
  38. package/dist/UnderlineNav/styles.d.ts.map +0 -1
  39. package/dist/UnderlineNav/styles.js +0 -19
  40. package/dist/experimental/UnderlinePanels/UnderlinePanels-e4b325b9.css +0 -2
  41. package/dist/experimental/UnderlinePanels/UnderlinePanels-e4b325b9.css.map +0 -1
  42. package/dist/internal/components/UnderlineTabbedInterface-4197ee28.css +0 -2
  43. package/dist/internal/components/UnderlineTabbedInterface-4197ee28.css.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @primer/react
2
2
 
3
- ## 0.0.0-20260602214102
3
+ ## 0.0.0-20260603152335
4
4
 
5
5
  ### Minor Changes
6
6
 
@@ -8,11 +8,9 @@
8
8
 
9
9
  - [#7906](https://github.com/primer/react/pull/7906) [`adc5299`](https://github.com/primer/react/commit/adc5299f3d98519119fb9547e50dd2985fc96174) Thanks [@jonrohan](https://github.com/jonrohan)! - Text: Add `whiteSpace` prop to control the CSS `white-space` property
10
10
 
11
- ### Patch Changes
12
-
13
- - [#7918](https://github.com/primer/react/pull/7918) [`f2aaf29`](https://github.com/primer/react/commit/f2aaf29eaf3ad33c77d0c1ec25645c9f6bf1ad3a) Thanks [@jonrohan](https://github.com/jonrohan)! - Autocomplete: Keep the typed text instead of restoring the full inline suggestion when the input loses focus, matching the behavior of pressing Escape
11
+ - [#7622](https://github.com/primer/react/pull/7622) [`4d8d5e6`](https://github.com/primer/react/commit/4d8d5e6b9b0b1d394d19154369f9c37eabe7cb87) Thanks [@copilot-swe-agent](https://github.com/apps/copilot-swe-agent)! - Refactors `UnderlineNav` overflow handling to use CSS-based overflow detection instead of JavaScript width measurements, eliminating layout shift (CLS) issues and improving performance. The overflow menu is now implemented with `ActionMenu`, and item registration uses a descendant registry instead of the `React.Children` API. Consumer-facing changes: items can now be wrapped in fragments or wrapper components; the current item may appear in the overflow menu when the viewport is narrow; and the overflow menu button is right-aligned.
14
12
 
15
- - [#7915](https://github.com/primer/react/pull/7915) [`f58e448`](https://github.com/primer/react/commit/f58e448961df15e28b4a69950de84d478e2664af) Thanks [@jonrohan](https://github.com/jonrohan)! - Dialog: Fix `Escape` key not closing the dialog on the first keypress when the close button is focused
13
+ ### Patch Changes
16
14
 
17
15
  - Fake entry to force publishing
18
16
 
@@ -1 +1 @@
1
- {"version":3,"file":"AutocompleteInput.d.ts","sourceRoot":"","sources":["../../src/Autocomplete/AutocompleteInput.tsx"],"names":[],"mappings":"AACA,OAAO,KAAqD,MAAM,OAAO,CAAA;AACzE,OAAO,KAAK,EAAC,mBAAmB,IAAI,8BAA8B,EAAC,MAAM,sBAAsB,CAAA;AAE/F,OAAO,SAAS,MAAM,cAAc,CAAA;AAEpC,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,gBAAgB,CAAA;AAGlD,KAAK,8BAA8B,GAAG;IAEpC,EAAE,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC,CAAA;IAEtD;;;OAGG;IACH,WAAW,CAAC,EAAE,OAAO,CAAA;CACtB,CAAA;AAID,QAAA,MAAM,iBAAiB,EA2KlB,8BAA8B,CAAC,OAAO,SAAS,EAAE,8BAA8B,CAAC,CAAA;AAIrF,MAAM,MAAM,sBAAsB,GAAG,cAAc,CAAC,OAAO,iBAAiB,CAAC,CAAA;AAC7E,eAAe,iBAAiB,CAAA"}
1
+ {"version":3,"file":"AutocompleteInput.d.ts","sourceRoot":"","sources":["../../src/Autocomplete/AutocompleteInput.tsx"],"names":[],"mappings":"AACA,OAAO,KAAqD,MAAM,OAAO,CAAA;AACzE,OAAO,KAAK,EAAC,mBAAmB,IAAI,8BAA8B,EAAC,MAAM,sBAAsB,CAAA;AAE/F,OAAO,SAAS,MAAM,cAAc,CAAA;AAEpC,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,gBAAgB,CAAA;AAGlD,KAAK,8BAA8B,GAAG;IAEpC,EAAE,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC,CAAA;IAEtD;;;OAGG;IACH,WAAW,CAAC,EAAE,OAAO,CAAA;CACtB,CAAA;AAID,QAAA,MAAM,iBAAiB,EAyJlB,8BAA8B,CAAC,OAAO,SAAS,EAAE,8BAA8B,CAAC,CAAA;AAIrF,MAAM,MAAM,sBAAsB,GAAG,cAAc,CAAC,OAAO,iBAAiB,CAAC,CAAA;AAC7E,eAAe,iBAAiB,CAAA"}
@@ -56,17 +56,9 @@ const AutocompleteInput = /*#__PURE__*/React.forwardRef(({
56
56
  safeSetTimeout(() => {
57
57
  if (document.activeElement !== inputRef.current) {
58
58
  setShowMenu(false);
59
-
60
- // Reset the input's value to the text the user actually typed rather than leaving the
61
- // inline autocomplete suggestion in place. This keeps the blur behavior consistent with
62
- // pressing Escape, so deleting characters off a selection and then clicking away does not
63
- // silently restore the full suggestion. See https://github.com/primer/react/issues/4275
64
- if (inputRef.current && autocompleteSuggestion && inputRef.current.value !== inputValue) {
65
- inputRef.current.value = inputValue;
66
- }
67
59
  }
68
60
  }, 0);
69
- }, [onBlur, setShowMenu, inputRef, safeSetTimeout, autocompleteSuggestion, inputValue]);
61
+ }, [onBlur, setShowMenu, inputRef, safeSetTimeout]);
70
62
  const handleInputChange = event => {
71
63
  onChange && onChange(event);
72
64
  setInputValue(event.currentTarget.value);
@@ -118,11 +110,7 @@ const AutocompleteInput = /*#__PURE__*/React.forwardRef(({
118
110
  // TODO: fix bug where this function prevents `onChange` from being triggered if the highlighted item text
119
111
  // is the same as what I'm typing
120
112
  // e.g.: typing 'tw' highlights 'two', but when I 'two', the text input change does not get triggered
121
- // Only apply the inline autocomplete suggestion while the input is focused. Without this guard,
122
- // the suggestion can be re-applied to the DOM after the input is blurred, which would restore
123
- // the full suggestion the user was editing away from. See https://github.com/primer/react/issues/4275
124
- const isInputFocused = document.activeElement === inputRef.current;
125
- if (isInputFocused && highlightRemainingText && autocompleteSuggestion && (inputValue || isMenuDirectlyActivated)) {
113
+ if (highlightRemainingText && autocompleteSuggestion && (inputValue || isMenuDirectlyActivated)) {
126
114
  inputRef.current.value = autocompleteSuggestion;
127
115
  if (autocompleteSuggestion.toLowerCase().indexOf(inputValue.toLowerCase()) === 0) {
128
116
  inputRef.current.setSelectionRange(inputValue.length, autocompleteSuggestion.length);
@@ -170,7 +170,6 @@ export declare const Dialog: React.ForwardRefExoticComponent<DialogProps & {
170
170
  }>>;
171
171
  CloseButton: React.FC<React.PropsWithChildren<{
172
172
  onClose: () => void;
173
- onKeyDown?: React.KeyboardEventHandler;
174
173
  }>>;
175
174
  };
176
175
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"Dialog.d.ts","sourceRoot":"","sources":["../../src/Dialog/Dialog.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAA2C,KAAK,aAAa,EAAsB,MAAM,OAAO,CAAA;AAC9G,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,WAAW,CAAA;AAU1C,OAAO,KAAK,EAAC,eAAe,EAAC,MAAM,6BAA6B,CAAA;AAChE,OAAO,KAAK,EAAC,mBAAmB,IAAI,8BAA8B,EAAC,MAAM,sBAAsB,CAAA;AAgB/F;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GAAG,IAA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;;;;;;;iBA1EuC,iBAAiB,EAAE;;;iBAoCf,MAAM,IAAI;;CA8CtE,CAAA"}
@@ -36,17 +36,6 @@ const DefaultHeader = ({
36
36
  const onCloseClick = useCallback(() => {
37
37
  onClose('close-button');
38
38
  }, [onClose]);
39
- const onCloseKeyDown = useCallback(event => {
40
- if (event.key === 'Escape') {
41
- // When the close button is focused its tooltip is open, and the
42
- // tooltip's own Escape handler (registered on `document`) would
43
- // otherwise swallow this keypress. Handle Escape here and stop it from
44
- // reaching the document-level handler so the dialog closes on the first
45
- // press while keeping the tooltip fully functional.
46
- event.stopPropagation();
47
- onClose('escape');
48
- }
49
- }, [onClose]);
50
39
  return /*#__PURE__*/jsx(Dialog.Header, {
51
40
  children: /*#__PURE__*/jsxs("div", {
52
41
  className: classes.HeaderInner,
@@ -60,8 +49,7 @@ const DefaultHeader = ({
60
49
  children: subtitle
61
50
  })]
62
51
  }), /*#__PURE__*/jsx(Dialog.CloseButton, {
63
- onClose: onCloseClick,
64
- onKeyDown: onCloseKeyDown
52
+ onClose: onCloseClick
65
53
  })]
66
54
  })
67
55
  });
@@ -360,14 +348,12 @@ const Buttons = ({
360
348
  });
361
349
  };
362
350
  const CloseButton = ({
363
- onClose,
364
- onKeyDown
351
+ onClose
365
352
  }) => {
366
353
  return /*#__PURE__*/jsx(IconButton, {
367
354
  icon: XIcon,
368
355
  "aria-label": "Close",
369
356
  onClick: onClose,
370
- onKeyDown: onKeyDown,
371
357
  variant: "invisible",
372
358
  "data-component": "Dialog.CloseButton"
373
359
  });
@@ -0,0 +1,2 @@
1
+ .prc-UnderlineNav-UnderlineWrapper-GWONT{animation:prc-UnderlineNav-detect-overflow-6HuSH linear;animation-timeline:scroll(self block);--UnderlineNav_moreButton-visibility:hidden;--UnderlineNav_icons-display:inline}.prc-UnderlineNav-UnderlineWrapper-GWONT[data-hide-icons=true]{--UnderlineNav_icons-display:none}.prc-UnderlineNav-UnderlineWrapper-GWONT[data-has-overflow=true]{--UnderlineNav_moreButton-visibility:visible}@keyframes prc-UnderlineNav-detect-overflow-6HuSH{0%,to{--UnderlineNav_moreButton-visibility:visible;--UnderlineNav_icons-display:none}}.prc-UnderlineNav-ItemsList-oj8gN [data-component=icon]{display:var(--UnderlineNav_icons-display)}.prc-UnderlineNav-MoreButtonContainer-Dnrq6{align-items:center;display:flex;visibility:var(--UnderlineNav_moreButton-visibility)}.prc-UnderlineNav-OverflowMenuItem-7SG7M [aria-current]{position:relative}:is(.prc-UnderlineNav-OverflowMenuItem-7SG7M [aria-current]) .prc-UnderlineNav-OverflowMenuItemLabel-F80v6{font-weight:var(--base-text-weight-semibold,600)}:is(.prc-UnderlineNav-OverflowMenuItem-7SG7M [aria-current]):after{background:var(--underlineNav-borderColor-active,#fd8c73);content:"";inset:var(--base-size-2,.125rem) auto var(--base-size-2,.125rem) 0;position:absolute;width:var(--base-size-2,.125rem)}.prc-UnderlineNav-MoreButtonDivider-dN0a-{border-left:var(--borderWidth-thin,.0625rem) solid var(--borderColor-muted,#d1d9e0b3);display:inline-block;height:var(--base-size-24,1.5rem);margin-inline:var(--base-size-4,.25rem);width:0}.prc-UnderlineNav-MoreButton-Y8soj{font-weight:var(--base-text-weight-normal,400);margin:0;position:relative}.prc-UnderlineNav-MoreButton-Y8soj>[data-component=trailingVisual]{margin-left:0}.prc-UnderlineNav-MoreButton-Y8soj[data-current=true]{font-weight:var(--base-text-weight-semibold,600)}.prc-UnderlineNav-MoreButton-Y8soj[data-current=true]:after{background-color:var(--underlineNav-borderColor-active,var(--color-primer-border-active,#fd8c73));content:"";height:2px;inset:auto 0 0;margin-bottom:calc(var(--base-size-8,.5rem)*-1);pointer-events:none;position:absolute}@media (forced-colors:active){.prc-UnderlineNav-MoreButton-Y8soj[data-current=true]:after{background-color:LinkText}}
2
+ /*# sourceMappingURL=UnderlineNav-263b4e8f.css.map */
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/UnderlineNav/UnderlineNav.module.css.js"],"names":[],"mappings":"AAAA,yCAIE,uDAAiC,CACjC,qCAAsC,CAEtC,2CAA4C,CAC5C,mCASF,CAPE,+DACE,iCACF,CAEA,iEACE,4CACF,CAGF,kDACE,MAEE,4CAA6C,CAC7C,iCACF,CACF,CAEA,wDACE,yCACF,CAEA,4CAGE,kBAAmB,CAFnB,YAAa,CACb,oDAEF,CAEA,wDACE,iBAcF,CAZE,2GACE,gDACF,CAEA,mEAME,yDAAkD,CALlD,UAAW,CAGX,kEAAmD,CADnD,iBAAkB,CADlB,gCAKF,CAGF,0CAEE,qFAAmE,CADnE,oBAAqB,CAIrB,iCAA2B,CAD3B,uCAAiC,CADjC,OAGF,CAEA,mCAEE,8CAA2C,CAD3C,QAAS,CAET,iBA2BF,CAzBE,mEACE,aACF,CAIA,sDACE,gDAiBF,CAfE,4DAQE,iGAAoG,CAFpG,UAAW,CAFX,UAAW,CAFX,cAAe,CACf,+CAA4C,CAE5C,mBAAoB,CAJpB,iBAaF,CAJE,8BAVF,4DAYI,yBAEJ,CADE","file":"UnderlineNav-263b4e8f.css","sourcesContent":[".UnderlineWrapper {\n /* Progressive enhancement: Detect overflow using scroll-based animations.\n The idiomatic way would be a scroll-state container query but browser support\n is slightly better for animations. */\n animation: detect-overflow linear;\n animation-timeline: scroll(self block);\n\n --UnderlineNav_moreButton-visibility: hidden;\n --UnderlineNav_icons-display: inline;\n\n &[data-hide-icons='true'] {\n --UnderlineNav_icons-display: none;\n }\n\n &[data-has-overflow='true'] {\n --UnderlineNav_moreButton-visibility: visible;\n }\n}\n\n@keyframes detect-overflow {\n 0%,\n 100% {\n --UnderlineNav_moreButton-visibility: visible;\n --UnderlineNav_icons-display: none;\n }\n}\n\n.ItemsList [data-component='icon'] {\n display: var(--UnderlineNav_icons-display);\n}\n\n.MoreButtonContainer {\n display: flex;\n visibility: var(--UnderlineNav_moreButton-visibility);\n align-items: center;\n}\n\n.OverflowMenuItem [aria-current] {\n position: relative;\n\n .OverflowMenuItemLabel {\n font-weight: var(--base-text-weight-semibold);\n }\n\n &::after {\n content: '';\n width: var(--base-size-2);\n position: absolute;\n inset: var(--base-size-2) auto var(--base-size-2) 0;\n /* stylelint-disable-next-line primer/colors */\n background: var(--underlineNav-borderColor-active);\n }\n}\n\n.MoreButtonDivider {\n display: inline-block;\n border-left: var(--borderWidth-thin) solid var(--borderColor-muted);\n width: 0;\n margin-inline: var(--base-size-4);\n height: var(--base-size-24);\n}\n\n.MoreButton {\n margin: 0; /* reset Safari extra margin */\n font-weight: var(--base-text-weight-normal);\n position: relative;\n\n & > [data-component='trailingVisual'] {\n margin-left: 0;\n }\n\n /* When the current item has overflowed into the menu, style the overflow\n anchor so it looks like the current item (semibold text + active underline). */\n &[data-current='true'] {\n font-weight: var(--base-text-weight-semibold);\n\n &::after {\n position: absolute;\n inset: auto 0 0;\n margin-bottom: calc(-1 * var(--base-size-8));\n height: 2px;\n pointer-events: none;\n content: '';\n /* stylelint-disable-next-line primer/colors */\n background-color: var(--underlineNav-borderColor-active, var(--color-primer-border-active, #fd8c73));\n\n @media (forced-colors: active) {\n /* Support for Windows Forced Color Mode https://learn.microsoft.com/en-us/fluent-ui/web-components/design-system/high-contrast */\n background-color: LinkText;\n }\n }\n }\n}\n"]}
@@ -15,7 +15,5 @@ export type UnderlineNavProps = {
15
15
  */
16
16
  variant?: 'inset' | 'flush';
17
17
  };
18
- export declare const MORE_BTN_WIDTH = 86;
19
- export declare const getValidChildren: (children: React.ReactNode) => React.ReactElement<any>[];
20
18
  export declare const UnderlineNav: React.ForwardRefExoticComponent<UnderlineNavProps & React.RefAttributes<unknown>>;
21
19
  //# sourceMappingURL=UnderlineNav.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"UnderlineNav.d.ts","sourceRoot":"","sources":["../../src/UnderlineNav/UnderlineNav.tsx"],"names":[],"mappings":"AACA,OAAO,KAAkD,MAAM,OAAO,CAAA;AAoBtE,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;AAwEhC,eAAO,MAAM,gBAAgB,GAAI,UAAU,KAAK,CAAC,SAAS,KAEgC,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC,EAChH,CAAA;AAgCD,eAAO,MAAM,YAAY,mFA0SxB,CAAA"}
1
+ {"version":3,"file":"UnderlineNav.d.ts","sourceRoot":"","sources":["../../src/UnderlineNav/UnderlineNav.tsx"],"names":[],"mappings":"AACA,OAAO,KAA8C,MAAM,OAAO,CAAA;AAclE,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;AAUD,eAAO,MAAM,YAAY,mFAiIxB,CAAA"}
@@ -1,120 +1,23 @@
1
- import React, { forwardRef, useRef, useState, useCallback } from 'react';
2
- import { useDevOnlyEffect } from '../internal/hooks/useDevOnlyEffect.js';
3
- import { UnderlineNavContext } from './UnderlineNavContext.js';
4
- import { useResizeObserver } from '../hooks/useResizeObserver.js';
1
+ import React, { forwardRef, useRef, useState, useMemo } from 'react';
5
2
  import VisuallyHidden from '../_VisuallyHidden.js';
6
- import { dividerStyles, baseMenuMinWidth, menuItemStyles } from './styles.js';
7
- import { UnderlineWrapper, UnderlineItemList, LoadingCounter, GAP } from '../internal/components/UnderlineTabbedInterface.js';
8
- import { TriangleDownIcon } from '@primer/octicons-react';
9
- import { useOnEscapePress } from '../hooks/useOnEscapePress.js';
10
- import { useOnOutsideClick } from '../hooks/useOnOutsideClick.js';
11
- import { useId } from '../hooks/useId.js';
12
3
  import { ActionList } from '../ActionList/index.js';
4
+ import { UnderlineWrapper, UnderlineItemList, LoadingCounter } from '../internal/components/UnderlineTabbedInterface.js';
13
5
  import { invariant } from '../utils/invariant.js';
14
6
  import classes from './UnderlineNav.module.css.js';
15
- import { getAnchoredPosition } from '@primer/behaviors';
16
- import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
17
- import { ButtonComponent } from '../Button/Button.js';
7
+ import { UnderlineNavContext } from './UnderlineNavContext.js';
8
+ import { UnderlineNavItemsRegistry } from './UnderlineNavItem.js';
9
+ import { clsx } from 'clsx';
10
+ import { useDevOnlyEffect } from '../internal/hooks/useDevOnlyEffect.js';
11
+ import { jsxs, jsx } from 'react/jsx-runtime';
12
+ import { SkeletonText } from '../SkeletonText/SkeletonText.js';
18
13
  import CounterLabel from '../CounterLabel/CounterLabel.js';
14
+ import { ActionMenu } from '../ActionMenu/ActionMenu.js';
19
15
 
20
- // When page is loaded, we don't have ref for the more button as it is not on the DOM yet.
21
- // However, we need to calculate number of possible items when the more button present as well. So using the width of the more button as a constant.
22
- const MORE_BTN_WIDTH = 86;
23
- // The height is needed to make sure we don't have a layout shift when the more button is the only item in the nav.
24
- const MORE_BTN_HEIGHT = 45;
25
- const overflowEffect = (navWidth, moreMenuWidth, childArray, childWidthArray, noIconChildWidthArray, updateListAndMenu) => {
26
- let iconsVisible = true;
27
- if (childWidthArray.length === 0) {
28
- updateListAndMenu({
29
- items: childArray,
30
- menuItems: []
31
- }, iconsVisible, false);
32
- return;
33
- }
34
- const numberOfItemsPossible = calculatePossibleItems(childWidthArray, navWidth);
35
- const numberOfItemsWithoutIconPossible = calculatePossibleItems(noIconChildWidthArray, navWidth);
36
- // We need to take more menu width into account when calculating the number of items possible
37
- const numberOfItemsPossibleWithMoreMenu = calculatePossibleItems(noIconChildWidthArray, navWidth, moreMenuWidth || MORE_BTN_WIDTH);
38
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
39
- const items = [];
40
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
41
- const menuItems = [];
42
-
43
- // First, we check if we can fit all the items with their icons
44
- if (childArray.length <= numberOfItemsPossible) {
45
- items.push(...childArray);
46
- } else if (childArray.length <= numberOfItemsWithoutIconPossible) {
47
- // if we can't fit all the items with their icons, we check if we can fit all the items without their icons
48
- iconsVisible = false;
49
- items.push(...childArray);
50
- } else {
51
- // if we can't fit all the items without their icons, we keep the icons hidden and show the ones that doesn't fit into the list in the overflow menu
52
- iconsVisible = false;
53
-
54
- /* Below is an accessibility requirement. Never show only one item in the overflow menu.
55
- * If there is only one item left to display in the overflow menu according to the calculation,
56
- * we need to pull another item from the list into the overflow menu.
57
- */
58
- const numberOfItemsInMenu = childArray.length - numberOfItemsPossibleWithMoreMenu;
59
- const numberOfListItems = numberOfItemsInMenu === 1 ? numberOfItemsPossibleWithMoreMenu - 1 : numberOfItemsPossibleWithMoreMenu;
60
- for (const [index, child] of childArray.entries()) {
61
- if (index < numberOfListItems) {
62
- items.push(child);
63
- } else {
64
- const ariaCurrent = child.props['aria-current'];
65
- const isCurrent = Boolean(ariaCurrent) && ariaCurrent !== 'false';
66
- // We need to make sure to keep the selected item always visible.
67
- // To do that, we swap the selected item with the last item in the list to make it visible. (When there is at least 1 item in the list to swap.)
68
- if (isCurrent && numberOfListItems > 0) {
69
- // If selected item couldn't make in to the list, we swap it with the last item in the list.
70
- const indexToReplaceAt = numberOfListItems - 1; // because we are replacing the last item in the list
71
- // splice method modifies the array by removing 1 item here at the given index and replace it with the "child" element then returns the removed item.
72
- const propsectiveAction = items.splice(indexToReplaceAt, 1, child)[0];
73
- menuItems.push(propsectiveAction);
74
- } else {
75
- menuItems.push(child);
76
- }
77
- }
78
- }
79
- }
80
- updateListAndMenu({
81
- items,
82
- menuItems
83
- }, iconsVisible, true);
84
- };
85
16
  const getValidChildren = children => {
86
17
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
87
18
  return React.Children.toArray(children).filter(child => /*#__PURE__*/React.isValidElement(child));
88
19
  };
89
- const calculatePossibleItems = (childWidthArray, navWidth, moreMenuWidth = 0) => {
90
- const widthToFit = navWidth - moreMenuWidth;
91
- let breakpoint = childWidthArray.length; // assume all items will fit
92
- let sumsOfChildWidth = 0;
93
- for (const [index, childWidth] of childWidthArray.entries()) {
94
- sumsOfChildWidth = sumsOfChildWidth + childWidth.width + GAP;
95
- if (sumsOfChildWidth > widthToFit) {
96
- breakpoint = index;
97
- break;
98
- } else {
99
- continue;
100
- }
101
- }
102
- return breakpoint;
103
- };
104
-
105
- // Inline styles converted from baseMenuStyles for use as CSSProperties
106
- const baseMenuInlineStyles = {
107
- position: 'absolute',
108
- zIndex: 1,
109
- top: '90%',
110
- boxShadow: '0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24)',
111
- borderRadius: 12,
112
- background: 'var(--overlay-bgColor)',
113
- listStyle: 'none',
114
- minWidth: `${baseMenuMinWidth}px`,
115
- maxWidth: '640px',
116
- right: 0
117
- };
20
+ const isCurrent = props => props['aria-current'] !== undefined && props['aria-current'] !== false && props['aria-current'] !== 'false';
118
21
  const UnderlineNav = /*#__PURE__*/forwardRef(({
119
22
  as = 'nav',
120
23
  'aria-label': ariaLabel,
@@ -123,259 +26,111 @@ const UnderlineNav = /*#__PURE__*/forwardRef(({
123
26
  className,
124
27
  children
125
28
  }, forwardedRef) => {
126
- var _listRef$current2;
29
+ var _registeredItems$entr;
127
30
  const backupRef = useRef(null);
128
31
  const navRef = forwardedRef !== null && forwardedRef !== void 0 ? forwardedRef : backupRef;
129
32
  const listRef = useRef(null);
130
- const moreMenuRef = useRef(null);
131
- const moreMenuBtnRef = useRef(null);
132
- const containerRef = React.useRef(null);
133
- const disclosureWidgetId = useId();
134
- const [isWidgetOpen, setIsWidgetOpen] = useState(false);
135
- const [iconsVisible, setIconsVisible] = useState(true);
136
- const [childWidthArray, setChildWidthArray] = useState([]);
137
- const [noIconChildWidthArray, setNoIconChildWidthArray] = useState([]);
138
- // Track whether the initial overflow calculation is complete to prevent CLS
139
- const [isOverflowMeasured, setIsOverflowMeasured] = useState(false);
140
- const validChildren = getValidChildren(children);
141
-
142
- // Responsive props object manages which items are in the list and which items are in the menu.
143
- const [responsiveProps, setResponsiveProps] = useState({
144
- items: validChildren,
145
- menuItems: []
146
- });
147
33
 
148
- // Make sure to have the fresh props data for list items when children are changed (keeping aria-current up-to-date)
149
- const listItems = responsiveProps.items.map(item => {
150
- var _validChildren$find;
151
- return (_validChildren$find = validChildren.find(child => child.key === item.key)) !== null && _validChildren$find !== void 0 ? _validChildren$find : item;
152
- });
34
+ /** Tracks whether any item has ever overflowed for the lifecycle of this component. Used to prevent flickering. */
35
+ const [hasEverOverflowed, setHasOverflowed] = useState(false);
36
+ const [registeredItems, setRegisteredItems] = UnderlineNavItemsRegistry.useRegistryState();
37
+ const overflowMenuItems = Array.from((_registeredItems$entr = registeredItems === null || registeredItems === void 0 ? void 0 : registeredItems.entries()) !== null && _registeredItems$entr !== void 0 ? _registeredItems$entr : []).filter(entry => entry[1] !== null);
38
+ const isOverflowing = overflowMenuItems.length > 0;
39
+ if (isOverflowing && !hasEverOverflowed) setHasOverflowed(true);
153
40
 
154
- // Make sure to have the fresh props data for menu items when children are changed (keeping aria-current up-to-date)
155
- const menuItems = responsiveProps.menuItems.map(menuItem => {
156
- var _validChildren$find2;
157
- return (_validChildren$find2 = validChildren.find(child => child.key === menuItem.key)) !== null && _validChildren$find2 !== void 0 ? _validChildren$find2 : menuItem;
158
- });
159
- // 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
160
- const onlyMenuVisible = responsiveProps.items.length === 0;
41
+ // Find the current item if it has overflowed into the menu, so we can reflect
42
+ // its "current" state on the overflow menu anchor.
43
+ const overflowingCurrentItem = overflowMenuItems.some(([, itemProps]) => isCurrent(itemProps));
44
+ const validChildren = getValidChildren(children);
161
45
  useDevOnlyEffect(() => {
162
46
  // Address illegal state where there are multiple items that have `aria-current='page'` attribute
163
- const activeElements = validChildren.filter(child => {
164
- return child.props['aria-current'] !== undefined;
165
- });
47
+ const activeElements = validChildren.filter(child => isCurrent(child.props));
166
48
  !(activeElements.length <= 1) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Only one current element is allowed') : invariant(false) : void 0;
167
49
  !ariaLabel ? process.env.NODE_ENV !== "production" ? invariant(false, 'Use the `aria-label` prop to provide an accessible label for assistive technology') : invariant(false) : void 0;
168
50
  }, [validChildren, ariaLabel]);
169
- function getItemsWidth(itemText) {
170
- var _noIconChildWidthArra, _noIconChildWidthArra2;
171
- return (_noIconChildWidthArra = (_noIconChildWidthArra2 = noIconChildWidthArray.find(item => item.text === itemText)) === null || _noIconChildWidthArra2 === void 0 ? void 0 : _noIconChildWidthArra2.width) !== null && _noIconChildWidthArra !== void 0 ? _noIconChildWidthArra : 0;
172
- }
173
- const swapMenuItemWithListItem = (prospectiveListItem, indexOfProspectiveListItem, event, callback) => {
174
- var _navRef$current$getBo, _navRef$current, _listRef$current$getB, _listRef$current;
175
- // get the selected menu item's width
176
- const widthToFitIntoList = getItemsWidth(prospectiveListItem.props.children);
177
- // Check if there is any empty space on the right side of the list
178
- const availableSpace = ((_navRef$current$getBo = (_navRef$current = navRef.current) === null || _navRef$current === void 0 ? void 0 : _navRef$current.getBoundingClientRect().width) !== null && _navRef$current$getBo !== void 0 ? _navRef$current$getBo : 0) - ((_listRef$current$getB = (_listRef$current = listRef.current) === null || _listRef$current === void 0 ? void 0 : _listRef$current.getBoundingClientRect().width) !== null && _listRef$current$getB !== void 0 ? _listRef$current$getB : 0);
179
-
180
- // Calculate how many items need to be pulled in to the menu to make room for the selected menu item
181
- // I.e. if we need to pull 2 items in (index 0 and index 1), breakpoint (index) will return 1.
182
- const index = getBreakpointForItemSwapping(widthToFitIntoList, availableSpace);
183
- const indexToSliceAt = responsiveProps.items.length - 1 - index;
184
- // Form the new list of items
185
- const itemsLeftInList = [...responsiveProps.items].slice(0, indexToSliceAt);
186
- const updatedItemList = [...itemsLeftInList, prospectiveListItem];
187
- // Form the new menu items
188
- const itemsToAddToMenu = [...responsiveProps.items].slice(indexToSliceAt);
189
- const updatedMenuItems = [...menuItems];
190
- // Add itemsToAddToMenu array's items to the menu at the index of the prospectiveListItem and remove 1 count of items (prospectiveListItem)
191
- updatedMenuItems.splice(indexOfProspectiveListItem, 1, ...itemsToAddToMenu);
192
- callback({
193
- items: updatedItemList,
194
- menuItems: updatedMenuItems
195
- }, false, true);
196
- };
197
- // How many items do we need to pull in to the menu to make room for the selected menu item.
198
- function getBreakpointForItemSwapping(widthToFitIntoList, availableSpace) {
199
- let widthToSwap = 0;
200
- let breakpoint = 0;
201
- for (const [index, item] of [...responsiveProps.items].reverse().entries()) {
202
- widthToSwap += getItemsWidth(item.props.children);
203
- if (widthToFitIntoList < widthToSwap + availableSpace) {
204
- breakpoint = index;
205
- break;
206
- }
207
- }
208
- return breakpoint;
209
- }
210
- const updateListAndMenu = useCallback((props, displayIcons, overflowMeasured) => {
211
- setResponsiveProps(props);
212
- setIconsVisible(displayIcons);
213
- if (overflowMeasured) {
214
- setIsOverflowMeasured(true);
215
- }
216
- }, []);
217
- const setChildrenWidth = useCallback(size => {
218
- setChildWidthArray(arr => {
219
- const newArr = [...arr, size];
220
- return newArr;
221
- });
222
- }, []);
223
- const setNoIconChildrenWidth = useCallback(size => {
224
- setNoIconChildWidthArray(arr => {
225
- const newArr = [...arr, size];
226
- return newArr;
227
- });
228
- }, []);
229
- const closeOverlay = React.useCallback(() => {
230
- setIsWidgetOpen(false);
231
- }, [setIsWidgetOpen]);
232
- const focusOnMoreMenuBtn = React.useCallback(() => {
233
- var _moreMenuBtnRef$curre;
234
- (_moreMenuBtnRef$curre = moreMenuBtnRef.current) === null || _moreMenuBtnRef$curre === void 0 ? void 0 : _moreMenuBtnRef$curre.focus();
235
- }, []);
236
- const onAnchorClick = useCallback(event => {
237
- if (event.defaultPrevented || event.button !== 0) {
238
- return;
239
- }
240
- setIsWidgetOpen(isWidgetOpen => !isWidgetOpen);
241
- }, []);
242
- useOnEscapePress(event => {
243
- if (isWidgetOpen) {
244
- event.preventDefault();
245
- closeOverlay();
246
- focusOnMoreMenuBtn();
247
- }
248
- }, [isWidgetOpen]);
249
- useOnOutsideClick({
250
- onClickOutside: closeOverlay,
251
- containerRef,
252
- ignoreClickRefs: [moreMenuBtnRef]
253
- });
254
- useResizeObserver(resizeObserverEntries => {
255
- var _moreMenuRef$current$, _moreMenuRef$current;
256
- const navWidth = resizeObserverEntries[0].contentRect.width;
257
- 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;
258
- navWidth !== 0 && overflowEffect(navWidth, moreMenuWidth, validChildren, childWidthArray, noIconChildWidthArray, updateListAndMenu);
259
- }, navRef);
260
-
261
- // Compute menuInlineStyles if needed
262
- let menuInlineStyles = {
263
- ...baseMenuInlineStyles
264
- };
265
- if (containerRef.current && listRef.current) {
266
- const {
267
- left
268
- } = getAnchoredPosition(containerRef.current, listRef.current, {
269
- align: 'start',
270
- side: 'outside-bottom'
271
- });
272
- menuInlineStyles = {
273
- ...baseMenuInlineStyles,
274
- right: undefined,
275
- left
276
- };
277
- }
51
+ const contextValue = useMemo(() => ({
52
+ loadingCounters
53
+ }), [loadingCounters]);
278
54
  return /*#__PURE__*/jsxs(UnderlineNavContext.Provider, {
279
- value: {
280
- setChildrenWidth,
281
- setNoIconChildrenWidth,
282
- loadingCounters,
283
- iconsVisible
284
- },
55
+ value: contextValue,
285
56
  children: [ariaLabel && /*#__PURE__*/jsx(VisuallyHidden, {
286
57
  as: "h2",
287
58
  children: `${ariaLabel} navigation`
288
- }), /*#__PURE__*/jsx(UnderlineWrapper, {
59
+ }), /*#__PURE__*/jsxs(UnderlineWrapper, {
289
60
  as: as,
290
61
  "aria-label": ariaLabel,
291
- className: className,
62
+ className: clsx(classes.UnderlineWrapper, className),
292
63
  ref: navRef,
293
64
  "data-variant": variant,
294
- "data-overflow-measured": isOverflowMeasured ? 'true' : 'false',
295
- children: /*#__PURE__*/jsxs(UnderlineItemList, {
65
+ "data-overflow-mode": "wrap"
66
+ // Force icons to stay hidden, avoiding flickering as icons create/remove overflow
67
+ ,
68
+ "data-hide-icons": hasEverOverflowed ? 'true' : undefined
69
+ // Ensure button is shown (after initial render) on browsers that don't support scroll-driven animations
70
+ ,
71
+ "data-has-overflow": isOverflowing ? 'true' : undefined,
72
+ children: [/*#__PURE__*/jsx(UnderlineItemList, {
296
73
  ref: listRef,
297
74
  role: "list",
298
- children: [listItems, menuItems.length > 0 && /*#__PURE__*/jsxs("li", {
299
- ref: moreMenuRef,
300
- style: {
301
- display: 'flex',
302
- alignItems: 'center',
303
- height: `${MORE_BTN_HEIGHT}px`
304
- },
305
- children: [!onlyMenuVisible && /*#__PURE__*/jsx("div", {
306
- style: dividerStyles
307
- }), /*#__PURE__*/jsx(ButtonComponent, {
308
- ref: moreMenuBtnRef,
75
+ className: classes.ItemsList,
76
+ children: /*#__PURE__*/jsx(UnderlineNavItemsRegistry.Provider, {
77
+ setRegistry: setRegisteredItems,
78
+ children: children
79
+ })
80
+ }), /*#__PURE__*/jsxs("div", {
81
+ className: classes.MoreButtonContainer,
82
+ children: [/*#__PURE__*/jsx("div", {
83
+ className: classes.MoreButtonDivider
84
+ }), /*#__PURE__*/jsxs(ActionMenu, {
85
+ children: [/*#__PURE__*/jsx(ActionMenu.Button, {
309
86
  className: classes.MoreButton,
310
- "aria-controls": disclosureWidgetId,
311
- "aria-expanded": isWidgetOpen,
312
- onClick: onAnchorClick,
313
- trailingAction: TriangleDownIcon,
314
- children: /*#__PURE__*/jsx("span", {
315
- children: onlyMenuVisible ? /*#__PURE__*/jsxs(Fragment, {
316
- children: [/*#__PURE__*/jsxs(VisuallyHidden, {
317
- as: "span",
318
- children: [`${ariaLabel}`, "\xA0"]
319
- }), "Menu"]
320
- }) : /*#__PURE__*/jsxs(Fragment, {
321
- children: ["More", /*#__PURE__*/jsxs(VisuallyHidden, {
322
- as: "span",
323
- children: ["\xA0", `${ariaLabel} items`]
324
- })]
325
- })
87
+ variant: "invisible",
88
+ "data-component": "overflow-menu-button",
89
+ "data-current": overflowingCurrentItem ? 'true' : undefined,
90
+ "aria-label": overflowingCurrentItem ? `More items, including current item` : undefined,
91
+ children: /*#__PURE__*/jsxs("span", {
92
+ children: ["More", /*#__PURE__*/jsx(VisuallyHidden, {
93
+ as: "span",
94
+ children: " items"
95
+ })]
326
96
  })
327
- }), /*#__PURE__*/jsx(ActionList, {
328
- selectionVariant: "single",
329
- ref: containerRef,
330
- id: disclosureWidgetId,
331
- style: {
332
- ...((_listRef$current2 = listRef.current) !== null && _listRef$current2 !== void 0 && _listRef$current2.clientWidth && listRef.current.clientWidth >= baseMenuMinWidth ? baseMenuInlineStyles : menuInlineStyles),
333
- display: isWidgetOpen ? 'block' : 'none'
334
- },
335
- children: menuItems.map((menuItem, index) => {
336
- const {
337
- children: menuItemChildren,
338
- counter,
339
- 'aria-current': ariaCurrent,
340
- onSelect,
341
- ...menuItemProps
342
- } = menuItem.props;
343
-
344
- // This logic is used to pop the selected item out of the menu and into the list when the navigation is control externally
345
- if (Boolean(ariaCurrent) && ariaCurrent !== 'false') {
346
- const event = new MouseEvent('click');
347
- !onlyMenuVisible && swapMenuItemWithListItem(menuItem, index,
348
- // @ts-ignore - not a big deal because it is internally creating an event but ask help
349
- event, updateListAndMenu);
350
- }
351
- return /*#__PURE__*/jsx(ActionList.LinkItem, {
352
- style: menuItemStyles,
353
- onClick: event => {
354
- // When there are no items in the list, do not run the swap function as we want to keep everything in the menu.
355
- !onlyMenuVisible && swapMenuItemWithListItem(menuItem, index, event, updateListAndMenu);
356
- closeOverlay();
357
- focusOnMoreMenuBtn();
358
- // fire onSelect event that comes from the UnderlineNav.Item (if it is defined)
359
- typeof onSelect === 'function' && onSelect(event);
360
- },
361
- ...menuItemProps,
362
- children: /*#__PURE__*/jsxs("span", {
363
- className: classes.MenuItemContent,
364
- children: [menuItemChildren, loadingCounters ? /*#__PURE__*/jsx(LoadingCounter, {}) : counter !== undefined && /*#__PURE__*/jsx("span", {
365
- "data-component": "counter",
366
- children: /*#__PURE__*/jsx(CounterLabel, {
367
- children: counter
97
+ }), /*#__PURE__*/jsx(ActionMenu.Overlay, {
98
+ children: /*#__PURE__*/jsx(ActionList, {
99
+ children: registeredItems === undefined ? /*#__PURE__*/jsx(ActionList.Item, {
100
+ children: /*#__PURE__*/jsx(SkeletonText, {})
101
+ }) : overflowMenuItems.map(([key, allProps]) => {
102
+ const {
103
+ children: menuItemChildren,
104
+ counter,
105
+ onSelect,
106
+ ...menuItemProps
107
+ } = allProps;
108
+ return /*#__PURE__*/jsxs(ActionList.LinkItem, {
109
+ className: classes.OverflowMenuItem,
110
+ onClick: event => onSelect === null || onSelect === void 0 ? void 0 : onSelect(event),
111
+ ...menuItemProps,
112
+ children: [/*#__PURE__*/jsx("span", {
113
+ className: classes.OverflowMenuItemLabel,
114
+ children: menuItemChildren
115
+ }), loadingCounters ? /*#__PURE__*/jsx(ActionList.TrailingVisual, {
116
+ children: /*#__PURE__*/jsx(LoadingCounter, {})
117
+ }) : counter !== undefined && /*#__PURE__*/jsx(ActionList.TrailingVisual, {
118
+ children: /*#__PURE__*/jsx("span", {
119
+ "data-component": "counter",
120
+ children: /*#__PURE__*/jsx(CounterLabel, {
121
+ children: counter
122
+ })
368
123
  })
369
124
  })]
370
- })
371
- }, menuItemChildren);
125
+ }, key);
126
+ })
372
127
  })
373
128
  })]
374
129
  })]
375
- })
130
+ })]
376
131
  })]
377
132
  });
378
133
  });
379
134
  UnderlineNav.displayName = 'UnderlineNav';
380
135
 
381
- export { MORE_BTN_WIDTH, UnderlineNav, getValidChildren };
136
+ export { UnderlineNav };