@primer/react 0.0.0-20260710131553 → 0.0.0-20260710183719
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 +1 -3
- package/dist/ActionList/Group.js +1 -1
- package/dist/ActionList/List.js +16 -10
- package/dist/AnchoredOverlay/AnchoredOverlay.js +10 -3
- package/dist/Autocomplete/AutocompleteInput.js +10 -7
- package/dist/Autocomplete/AutocompleteMenu.js +44 -36
- package/dist/ButtonGroup/ButtonGroup.js +12 -5
- package/dist/Checkbox/Checkbox.js +10 -3
- package/dist/Dialog/Dialog.js +9 -2
- package/dist/FeatureFlags/DefaultFeatureFlags.js +2 -1
- package/dist/FilteredActionList/FilteredActionList.js +15 -4
- package/dist/FilteredActionList/FilteredActionListInput.d.ts +1 -1
- package/dist/LabelGroup/LabelGroup.js +16 -25
- package/dist/Overlay/Overlay.js +1 -1
- package/dist/PageHeader/PageHeader.js +18 -9
- package/dist/SelectPanel/SelectPanel.js +1 -1
- package/dist/TextInput/TextInput.js +10 -3
- package/dist/TooltipV2/Tooltip.js +9 -2
- package/dist/experimental/Tabs/types.d.ts +2 -2
- package/dist/experimental/Tabs/useTabList.js +15 -7
- package/dist/experimental/index.js +3 -3
- package/dist/hooks/useMergedRefs.js +4 -1
- package/dist/hooks/useProvidedRefOrCreate.d.ts +7 -10
- package/dist/hooks/useProvidedRefOrCreate.js +7 -10
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @primer/react
|
|
2
2
|
|
|
3
|
-
## 0.0.0-
|
|
3
|
+
## 0.0.0-20260710183719
|
|
4
4
|
|
|
5
5
|
### Minor Changes
|
|
6
6
|
|
|
@@ -19,8 +19,6 @@
|
|
|
19
19
|
|
|
20
20
|
### Patch Changes
|
|
21
21
|
|
|
22
|
-
- [#8005](https://github.com/primer/react/pull/8005) [`5d24be4`](https://github.com/primer/react/commit/5d24be483f2fdfa305970907984d04522e2aa13c) Thanks [@copilot-swe-agent](https://github.com/apps/copilot-swe-agent)! - Derive `AutocompleteMenu` close-time re-sorting and `LabelGroup` numeric truncation during render instead of in effects, removing redundant render passes. No public API or visual changes.
|
|
23
|
-
|
|
24
22
|
- Fake entry to force publishing
|
|
25
23
|
|
|
26
24
|
- [#7901](https://github.com/primer/react/pull/7901) [`8288ed9`](https://github.com/primer/react/commit/8288ed9d88668f93cf3b1eb70ee61edac6217367) Thanks [@mattcosta7](https://github.com/mattcosta7)! - PageHeader: improve rendering performance by removing expensive `:has()` selectors. No visual or API changes.
|
package/dist/ActionList/Group.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { useId as useId$1 } from "../hooks/useId.js";
|
|
2
|
+
import { useFeatureFlag } from "../FeatureFlags/useFeatureFlag.js";
|
|
2
3
|
import { invariant } from "../utils/invariant.js";
|
|
3
4
|
import { useSlots } from "../hooks/useSlots.js";
|
|
4
5
|
import { ListContext } from "./shared.js";
|
|
5
6
|
import ActionList_module_css_default from "./ActionList.module.css.js";
|
|
6
|
-
import { useFeatureFlag } from "../FeatureFlags/useFeatureFlag.js";
|
|
7
7
|
import Group_module_css_default from "./Group.module.css.js";
|
|
8
8
|
import { GroupHeadingTrailingAction } from "./GroupHeadingTrailingAction.js";
|
|
9
9
|
import { GroupContext } from "./GroupContext.js";
|
package/dist/ActionList/List.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { useMergedRefs } from "../hooks/useMergedRefs.js";
|
|
1
2
|
import { useProvidedRefOrCreate } from "../hooks/useProvidedRefOrCreate.js";
|
|
2
3
|
import useIsomorphicLayoutEffect from "../utils/useIsomorphicLayoutEffect.js";
|
|
3
4
|
import { useId as useId$1 } from "../hooks/useId.js";
|
|
5
|
+
import { useFeatureFlag } from "../FeatureFlags/useFeatureFlag.js";
|
|
4
6
|
import { fixedForwardRef } from "../utils/modern-polymorphic.js";
|
|
5
7
|
import { useSlots } from "../hooks/useSlots.js";
|
|
6
8
|
import { FocusKeys, useFocusZone } from "../hooks/useFocusZone.js";
|
|
@@ -8,11 +10,10 @@ import { ActionListContainerContext } from "./ActionListContainerContext.js";
|
|
|
8
10
|
import { ListContext } from "./shared.js";
|
|
9
11
|
import { Heading } from "./Heading.js";
|
|
10
12
|
import ActionList_module_css_default from "./ActionList.module.css.js";
|
|
11
|
-
import { useFeatureFlag } from "../FeatureFlags/useFeatureFlag.js";
|
|
12
13
|
import { c } from "react-compiler-runtime";
|
|
13
14
|
import { clsx } from "clsx";
|
|
14
15
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
15
|
-
import React from "react";
|
|
16
|
+
import React, { useRef } from "react";
|
|
16
17
|
//#region src/ActionList/List.tsx
|
|
17
18
|
const UnwrappedList = (props, forwardedRef) => {
|
|
18
19
|
var _slots$heading$props$;
|
|
@@ -60,7 +61,12 @@ const UnwrappedList = (props, forwardedRef) => {
|
|
|
60
61
|
const { listRole: listRoleFromContainer, listLabelledBy, selectionVariant: containerSelectionVariant, enableFocusZone: enableFocusZoneFromContainer, container } = React.useContext(ActionListContainerContext);
|
|
61
62
|
const ariaLabelledBy = slots.heading ? (_slots$heading$props$ = slots.heading.props.id) !== null && _slots$heading$props$ !== void 0 ? _slots$heading$props$ : headingId : listLabelledBy;
|
|
62
63
|
const listRole = role || listRoleFromContainer;
|
|
63
|
-
const
|
|
64
|
+
const mergedRefEnabled = useFeatureFlag("primer_react_merged_forwarded_refs");
|
|
65
|
+
const internalRef = useRef(null);
|
|
66
|
+
const mergedRef = useMergedRefs(forwardedRef, internalRef);
|
|
67
|
+
const providedOrCreatedRef = useProvidedRefOrCreate(forwardedRef);
|
|
68
|
+
const listRef = mergedRefEnabled ? internalRef : providedOrCreatedRef;
|
|
69
|
+
const appliedRef = mergedRefEnabled ? mergedRef : providedOrCreatedRef;
|
|
64
70
|
const itemGapEnabled = useFeatureFlag("primer_react_action_list_item_gap") && container === "NavList";
|
|
65
71
|
let enableFocusZone = false;
|
|
66
72
|
if (enableFocusZoneFromContainer !== void 0) enableFocusZone = enableFocusZoneFromContainer;
|
|
@@ -111,7 +117,7 @@ const UnwrappedList = (props, forwardedRef) => {
|
|
|
111
117
|
} else t9 = $[20];
|
|
112
118
|
const listContextValue = t9;
|
|
113
119
|
let t10;
|
|
114
|
-
if ($[21] !== listRef) {
|
|
120
|
+
if ($[21] !== listRef.current) {
|
|
115
121
|
t10 = () => {
|
|
116
122
|
const list = listRef.current;
|
|
117
123
|
if (!list) return;
|
|
@@ -120,7 +126,7 @@ const UnwrappedList = (props, forwardedRef) => {
|
|
|
120
126
|
if (hasMixed && current !== "true") list.setAttribute("data-mixed-descriptions", "true");
|
|
121
127
|
else if (!hasMixed && current !== null) list.removeAttribute("data-mixed-descriptions");
|
|
122
128
|
};
|
|
123
|
-
$[21] = listRef;
|
|
129
|
+
$[21] = listRef.current;
|
|
124
130
|
$[22] = t10;
|
|
125
131
|
} else t10 = $[22];
|
|
126
132
|
useIsomorphicLayoutEffect(t10);
|
|
@@ -133,12 +139,12 @@ const UnwrappedList = (props, forwardedRef) => {
|
|
|
133
139
|
} else t12 = $[24];
|
|
134
140
|
const t13 = itemGapEnabled ? "" : void 0;
|
|
135
141
|
let t14;
|
|
136
|
-
if ($[25] !== Component || $[26] !==
|
|
142
|
+
if ($[25] !== Component || $[26] !== appliedRef || $[27] !== ariaLabelledBy || $[28] !== childrenWithoutSlots || $[29] !== listRole || $[30] !== restProps || $[31] !== showDividers || $[32] !== t12 || $[33] !== t13 || $[34] !== variant) {
|
|
137
143
|
t14 = /*#__PURE__*/ jsx(Component, {
|
|
138
144
|
className: t12,
|
|
139
145
|
role: listRole,
|
|
140
146
|
"aria-labelledby": ariaLabelledBy,
|
|
141
|
-
ref:
|
|
147
|
+
ref: appliedRef,
|
|
142
148
|
"data-component": "ActionList",
|
|
143
149
|
"data-dividers": showDividers,
|
|
144
150
|
"data-variant": variant,
|
|
@@ -147,9 +153,9 @@ const UnwrappedList = (props, forwardedRef) => {
|
|
|
147
153
|
children: childrenWithoutSlots
|
|
148
154
|
});
|
|
149
155
|
$[25] = Component;
|
|
150
|
-
$[26] =
|
|
151
|
-
$[27] =
|
|
152
|
-
$[28] =
|
|
156
|
+
$[26] = appliedRef;
|
|
157
|
+
$[27] = ariaLabelledBy;
|
|
158
|
+
$[28] = childrenWithoutSlots;
|
|
153
159
|
$[29] = listRole;
|
|
154
160
|
$[30] = restProps;
|
|
155
161
|
$[31] = showDividers;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { reactMajorVersion } from "../utils/environment.js";
|
|
2
|
+
import { useMergedRefs } from "../hooks/useMergedRefs.js";
|
|
2
3
|
import { useProvidedRefOrCreate } from "../hooks/useProvidedRefOrCreate.js";
|
|
3
4
|
import { useAnchoredPosition } from "../hooks/useAnchoredPosition.js";
|
|
4
5
|
import { useRenderForcingRef } from "../hooks/useRenderForcingRef.js";
|
|
5
6
|
import { useId as useId$1 } from "../hooks/useId.js";
|
|
7
|
+
import { useFeatureFlag } from "../FeatureFlags/useFeatureFlag.js";
|
|
6
8
|
import { IconButton } from "../Button/IconButton.js";
|
|
7
9
|
import { useFocusTrap } from "../hooks/useFocusTrap.js";
|
|
8
10
|
import { useFocusZone } from "../hooks/useFocusZone.js";
|
|
9
|
-
import { useFeatureFlag } from "../FeatureFlags/useFeatureFlag.js";
|
|
10
11
|
import Overlay from "../Overlay/Overlay.js";
|
|
11
12
|
import AnchoredOverlay_module_css_default from "./AnchoredOverlay.module.css.js";
|
|
12
13
|
import { widthMap } from "../Overlay/constants.js";
|
|
@@ -33,6 +34,8 @@ const AnchoredOverlay = ({ renderAnchor, anchorRef: externalAnchorRef, anchorId:
|
|
|
33
34
|
const [anchorElement, setAnchorElement] = useState(null);
|
|
34
35
|
if (anchorRef.current !== anchorElement) setAnchorElement(anchorRef.current);
|
|
35
36
|
const [overlayRef, updateOverlayRef] = useRenderForcingRef();
|
|
37
|
+
const mergedRefEnabled = useFeatureFlag("primer_react_merged_forwarded_refs");
|
|
38
|
+
const mergedOverlayRef = useMergedRefs(updateOverlayRef, overlayProps === null || overlayProps === void 0 ? void 0 : overlayProps.ref);
|
|
36
39
|
const [overlayElement, setOverlayElement] = useState(null);
|
|
37
40
|
const anchorId = useId$1(externalAnchorId);
|
|
38
41
|
const onClickOutside = useCallback(() => onClose === null || onClose === void 0 ? void 0 : onClose("click-outside"), [onClose]);
|
|
@@ -189,10 +192,14 @@ const AnchoredOverlay = ({ renderAnchor, anchorRef: externalAnchorRef, anchorId:
|
|
|
189
192
|
...shouldRenderAsPopover ? { popover: "manual" } : {},
|
|
190
193
|
...restOverlayProps,
|
|
191
194
|
...shouldRenderAsPopover ? { id: popoverId } : {},
|
|
195
|
+
...cssAnchorPositioning ? { id: popoverId } : {},
|
|
192
196
|
ref: (node) => {
|
|
193
|
-
if (overlayProps !== null && overlayProps !== void 0 && overlayProps.ref) assignRef(overlayProps.ref, node);
|
|
194
|
-
updateOverlayRef(node);
|
|
195
197
|
setOverlayElement(node);
|
|
198
|
+
if (mergedRefEnabled) assignRef(mergedOverlayRef, node);
|
|
199
|
+
else {
|
|
200
|
+
if (overlayProps !== null && overlayProps !== void 0 && overlayProps.ref) assignRef(overlayProps.ref, node);
|
|
201
|
+
updateOverlayRef(node);
|
|
202
|
+
}
|
|
196
203
|
},
|
|
197
204
|
"data-anchor-position": cssAnchorPositioning,
|
|
198
205
|
"data-side": cssAnchorPositioning ? side : position === null || position === void 0 ? void 0 : position.anchorSide,
|
|
@@ -20,9 +20,11 @@ const AutocompleteInput = /*#__PURE__*/ React.forwardRef(({ as: Component = Text
|
|
|
20
20
|
if (openOnFocus) setShowMenu(true);
|
|
21
21
|
};
|
|
22
22
|
const handleInputBlur = useCallback((event) => {
|
|
23
|
-
onBlur
|
|
23
|
+
onBlur === null || onBlur === void 0 || onBlur(event);
|
|
24
24
|
safeSetTimeout(() => {
|
|
25
|
-
|
|
25
|
+
const nextFocusedElement = event.relatedTarget;
|
|
26
|
+
const menuElement = document.getElementById(`${id}-listbox`);
|
|
27
|
+
if (!nextFocusedElement || nextFocusedElement !== menuElement && !(menuElement !== null && menuElement !== void 0 && menuElement.contains(nextFocusedElement))) {
|
|
26
28
|
setShowMenu(false);
|
|
27
29
|
if (inputRef.current && autocompleteSuggestion && inputRef.current.value !== inputValue) inputRef.current.value = inputValue;
|
|
28
30
|
}
|
|
@@ -33,16 +35,17 @@ const AutocompleteInput = /*#__PURE__*/ React.forwardRef(({ as: Component = Text
|
|
|
33
35
|
inputRef,
|
|
34
36
|
safeSetTimeout,
|
|
35
37
|
autocompleteSuggestion,
|
|
36
|
-
inputValue
|
|
38
|
+
inputValue,
|
|
39
|
+
id
|
|
37
40
|
]);
|
|
38
41
|
const handleInputChange = (event) => {
|
|
39
|
-
onChange
|
|
42
|
+
onChange === null || onChange === void 0 || onChange(event);
|
|
40
43
|
setInputValue(event.currentTarget.value);
|
|
41
44
|
if (!showMenu) setShowMenu(true);
|
|
42
45
|
};
|
|
43
46
|
const handleInputKeyDown = useCallback((event) => {
|
|
44
47
|
var _inputRef$current;
|
|
45
|
-
onKeyDown
|
|
48
|
+
onKeyDown === null || onKeyDown === void 0 || onKeyDown(event);
|
|
46
49
|
if (event.key === "Backspace") setHighlightRemainingText(false);
|
|
47
50
|
if (event.key === "Escape" && (_inputRef$current = inputRef.current) !== null && _inputRef$current !== void 0 && _inputRef$current.value) {
|
|
48
51
|
setInputValue("");
|
|
@@ -58,11 +61,11 @@ const AutocompleteInput = /*#__PURE__*/ React.forwardRef(({ as: Component = Text
|
|
|
58
61
|
setShowMenu
|
|
59
62
|
]);
|
|
60
63
|
const handleInputKeyUp = useCallback((event) => {
|
|
61
|
-
onKeyUp
|
|
64
|
+
onKeyUp === null || onKeyUp === void 0 || onKeyUp(event);
|
|
62
65
|
if (event.key === "Backspace") setHighlightRemainingText(true);
|
|
63
66
|
}, [setHighlightRemainingText, onKeyUp]);
|
|
64
67
|
const onInputKeyPress = useCallback((event) => {
|
|
65
|
-
onKeyPress
|
|
68
|
+
onKeyPress === null || onKeyPress === void 0 || onKeyPress(event);
|
|
66
69
|
if (showMenu && event.key === "Enter" && activeDescendantRef.current) {
|
|
67
70
|
event.preventDefault();
|
|
68
71
|
event.nativeEvent.stopImmediatePropagation();
|
|
@@ -43,7 +43,7 @@ const debounceAnnouncement = debounce((announcement) => {
|
|
|
43
43
|
announce(announcement);
|
|
44
44
|
}, 250);
|
|
45
45
|
function AutocompleteMenu(props) {
|
|
46
|
-
const $ = c(
|
|
46
|
+
const $ = c(78);
|
|
47
47
|
const autocompleteContext = useContext(AutocompleteContext);
|
|
48
48
|
const deferredInputContext = useContext(AutocompleteDeferredInputContext);
|
|
49
49
|
if (autocompleteContext === null || deferredInputContext === null) throw new Error("AutocompleteContext returned null values");
|
|
@@ -253,46 +253,54 @@ function AutocompleteMenu(props) {
|
|
|
253
253
|
t16 = $[54];
|
|
254
254
|
}
|
|
255
255
|
useEffect(t15, t16);
|
|
256
|
-
if (showMenu === false) {
|
|
257
|
-
const itemIdSortResult = [...sortedItemIds].sort(sortOnCloseFn ? sortOnCloseFn : getDefaultSortFn((itemId_0) => isItemSelected(itemId_0, selectedItemIds)));
|
|
258
|
-
if (!(itemIdSortResult.length === sortedItemIds.length && itemIdSortResult.every((element_0, index) => element_0 === sortedItemIds[index]))) setSortedItemIds(itemIdSortResult);
|
|
259
|
-
}
|
|
260
256
|
let t17;
|
|
261
257
|
let t18;
|
|
262
|
-
if ($[55] !== onOpenChange || $[56] !== showMenu) {
|
|
258
|
+
if ($[55] !== onOpenChange || $[56] !== selectedItemIds || $[57] !== showMenu || $[58] !== sortOnCloseFn || $[59] !== sortedItemIds) {
|
|
263
259
|
t17 = () => {
|
|
260
|
+
const itemIdSortResult = [...sortedItemIds].sort(sortOnCloseFn ? sortOnCloseFn : getDefaultSortFn((itemId_0) => isItemSelected(itemId_0, selectedItemIds)));
|
|
261
|
+
const sortResultMatchesState = itemIdSortResult.length === sortedItemIds.length && itemIdSortResult.every((element_0, index) => element_0 === sortedItemIds[index]);
|
|
262
|
+
if (showMenu === false && !sortResultMatchesState) setSortedItemIds(itemIdSortResult);
|
|
264
263
|
onOpenChange && onOpenChange(Boolean(showMenu));
|
|
265
264
|
};
|
|
266
|
-
t18 = [
|
|
265
|
+
t18 = [
|
|
266
|
+
showMenu,
|
|
267
|
+
onOpenChange,
|
|
268
|
+
selectedItemIds,
|
|
269
|
+
sortOnCloseFn,
|
|
270
|
+
sortedItemIds
|
|
271
|
+
];
|
|
267
272
|
$[55] = onOpenChange;
|
|
268
|
-
$[56] =
|
|
269
|
-
$[57] =
|
|
270
|
-
$[58] =
|
|
273
|
+
$[56] = selectedItemIds;
|
|
274
|
+
$[57] = showMenu;
|
|
275
|
+
$[58] = sortOnCloseFn;
|
|
276
|
+
$[59] = sortedItemIds;
|
|
277
|
+
$[60] = t17;
|
|
278
|
+
$[61] = t18;
|
|
271
279
|
} else {
|
|
272
|
-
t17 = $[
|
|
273
|
-
t18 = $[
|
|
280
|
+
t17 = $[60];
|
|
281
|
+
t18 = $[61];
|
|
274
282
|
}
|
|
275
283
|
useEffect(t17, t18);
|
|
276
284
|
let t19;
|
|
277
|
-
if ($[
|
|
285
|
+
if ($[62] !== selectedItemIds.length || $[63] !== setSelectedItemLength) {
|
|
278
286
|
t19 = () => {
|
|
279
287
|
if (selectedItemIds.length) setSelectedItemLength(selectedItemIds.length);
|
|
280
288
|
};
|
|
281
|
-
$[
|
|
282
|
-
$[
|
|
283
|
-
$[
|
|
284
|
-
} else t19 = $[
|
|
289
|
+
$[62] = selectedItemIds.length;
|
|
290
|
+
$[63] = setSelectedItemLength;
|
|
291
|
+
$[64] = t19;
|
|
292
|
+
} else t19 = $[64];
|
|
285
293
|
let t20;
|
|
286
|
-
if ($[
|
|
294
|
+
if ($[65] !== selectedItemIds || $[66] !== setSelectedItemLength) {
|
|
287
295
|
t20 = [selectedItemIds, setSelectedItemLength];
|
|
288
|
-
$[
|
|
289
|
-
$[
|
|
290
|
-
$[
|
|
291
|
-
} else t20 = $[
|
|
296
|
+
$[65] = selectedItemIds;
|
|
297
|
+
$[66] = setSelectedItemLength;
|
|
298
|
+
$[67] = t20;
|
|
299
|
+
} else t20 = $[67];
|
|
292
300
|
useEffect(t19, t20);
|
|
293
301
|
if (selectionVariant === "single" && selectedItemIds.length > 1) throw new Error("Autocomplete: selectionVariant \"single\" cannot be used with multiple selected items");
|
|
294
302
|
let t21;
|
|
295
|
-
if ($[
|
|
303
|
+
if ($[68] !== allItemsToRender || $[69] !== ariaLabelledBy || $[70] !== emptyStateText || $[71] !== id || $[72] !== loading || $[73] !== selectionVariant) {
|
|
296
304
|
t21 = loading ? /*#__PURE__*/ jsx("div", {
|
|
297
305
|
className: AutocompleteMenu_module_css_default.SpinnerWrapper,
|
|
298
306
|
children: /*#__PURE__*/ jsx(Spinner, {})
|
|
@@ -310,24 +318,24 @@ function AutocompleteMenu(props) {
|
|
|
310
318
|
children: emptyStateText
|
|
311
319
|
}) : null
|
|
312
320
|
});
|
|
313
|
-
$[
|
|
314
|
-
$[
|
|
315
|
-
$[
|
|
316
|
-
$[
|
|
317
|
-
$[
|
|
318
|
-
$[
|
|
319
|
-
$[
|
|
320
|
-
} else t21 = $[
|
|
321
|
+
$[68] = allItemsToRender;
|
|
322
|
+
$[69] = ariaLabelledBy;
|
|
323
|
+
$[70] = emptyStateText;
|
|
324
|
+
$[71] = id;
|
|
325
|
+
$[72] = loading;
|
|
326
|
+
$[73] = selectionVariant;
|
|
327
|
+
$[74] = t21;
|
|
328
|
+
} else t21 = $[74];
|
|
321
329
|
let t22;
|
|
322
|
-
if ($[
|
|
330
|
+
if ($[75] !== showMenu || $[76] !== t21) {
|
|
323
331
|
t22 = /*#__PURE__*/ jsx(VisuallyHidden, {
|
|
324
332
|
isVisible: showMenu,
|
|
325
333
|
children: t21
|
|
326
334
|
});
|
|
327
|
-
$[
|
|
328
|
-
$[
|
|
329
|
-
$[
|
|
330
|
-
} else t22 = $[
|
|
335
|
+
$[75] = showMenu;
|
|
336
|
+
$[76] = t21;
|
|
337
|
+
$[77] = t22;
|
|
338
|
+
} else t22 = $[77];
|
|
331
339
|
return t22;
|
|
332
340
|
}
|
|
333
341
|
function _temp5(item_2) {
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
import { useMergedRefs } from "../hooks/useMergedRefs.js";
|
|
1
2
|
import { useProvidedRefOrCreate } from "../hooks/useProvidedRefOrCreate.js";
|
|
3
|
+
import { useFeatureFlag } from "../FeatureFlags/useFeatureFlag.js";
|
|
2
4
|
import { FocusKeys, useFocusZone } from "../hooks/useFocusZone.js";
|
|
3
5
|
import ButtonGroup_module_css_default from "./ButtonGroup.module.css.js";
|
|
4
6
|
import { c } from "react-compiler-runtime";
|
|
5
7
|
import { clsx } from "clsx";
|
|
6
8
|
import { jsx } from "react/jsx-runtime";
|
|
7
|
-
import React from "react";
|
|
9
|
+
import React, { useRef } from "react";
|
|
8
10
|
//#region src/ButtonGroup/ButtonGroup.tsx
|
|
9
11
|
const ButtonGroup = /*#__PURE__*/ React.forwardRef(function ButtonGroup(t0, forwardRef) {
|
|
10
12
|
const $ = c(20);
|
|
@@ -29,6 +31,12 @@ const ButtonGroup = /*#__PURE__*/ React.forwardRef(function ButtonGroup(t0, forw
|
|
|
29
31
|
t1 = $[5];
|
|
30
32
|
}
|
|
31
33
|
const BaseComponent = t1 === void 0 ? "div" : t1;
|
|
34
|
+
const mergedRefEnabled = useFeatureFlag("primer_react_merged_forwarded_refs");
|
|
35
|
+
const internalRef = useRef(null);
|
|
36
|
+
const mergedRef = useMergedRefs(internalRef, forwardRef);
|
|
37
|
+
const providedOrCreatedRef = useProvidedRefOrCreate(forwardRef);
|
|
38
|
+
const buttonRef = mergedRefEnabled ? internalRef : providedOrCreatedRef;
|
|
39
|
+
const appliedRef = mergedRefEnabled ? mergedRef : providedOrCreatedRef;
|
|
32
40
|
let t2;
|
|
33
41
|
if ($[6] !== children) {
|
|
34
42
|
t2 = React.Children.map(children, _temp);
|
|
@@ -36,7 +44,6 @@ const ButtonGroup = /*#__PURE__*/ React.forwardRef(function ButtonGroup(t0, forw
|
|
|
36
44
|
$[7] = t2;
|
|
37
45
|
} else t2 = $[7];
|
|
38
46
|
const buttons = t2;
|
|
39
|
-
const buttonRef = useProvidedRefOrCreate(forwardRef);
|
|
40
47
|
const t3 = role !== "toolbar";
|
|
41
48
|
let t4;
|
|
42
49
|
if ($[8] !== buttonRef || $[9] !== t3) {
|
|
@@ -58,9 +65,9 @@ const ButtonGroup = /*#__PURE__*/ React.forwardRef(function ButtonGroup(t0, forw
|
|
|
58
65
|
$[12] = t5;
|
|
59
66
|
} else t5 = $[12];
|
|
60
67
|
let t6;
|
|
61
|
-
if ($[13] !== BaseComponent || $[14] !==
|
|
68
|
+
if ($[13] !== BaseComponent || $[14] !== appliedRef || $[15] !== buttons || $[16] !== rest || $[17] !== role || $[18] !== t5) {
|
|
62
69
|
t6 = /*#__PURE__*/ jsx(BaseComponent, {
|
|
63
|
-
ref:
|
|
70
|
+
ref: appliedRef,
|
|
64
71
|
className: t5,
|
|
65
72
|
role,
|
|
66
73
|
...rest,
|
|
@@ -68,7 +75,7 @@ const ButtonGroup = /*#__PURE__*/ React.forwardRef(function ButtonGroup(t0, forw
|
|
|
68
75
|
children: buttons
|
|
69
76
|
});
|
|
70
77
|
$[13] = BaseComponent;
|
|
71
|
-
$[14] =
|
|
78
|
+
$[14] = appliedRef;
|
|
72
79
|
$[15] = buttons;
|
|
73
80
|
$[16] = rest;
|
|
74
81
|
$[17] = role;
|
|
@@ -1,17 +1,24 @@
|
|
|
1
|
+
import { useMergedRefs } from "../hooks/useMergedRefs.js";
|
|
1
2
|
import { useProvidedRefOrCreate } from "../hooks/useProvidedRefOrCreate.js";
|
|
2
3
|
import useIsomorphicLayoutEffect from "../utils/useIsomorphicLayoutEffect.js";
|
|
4
|
+
import { useFeatureFlag } from "../FeatureFlags/useFeatureFlag.js";
|
|
3
5
|
import shared_module_css_default from "./shared.module.css.js";
|
|
4
6
|
import { CheckboxGroupContext } from "../CheckboxGroup/CheckboxGroupContext.js";
|
|
5
7
|
import Checkbox_module_css_default from "./Checkbox.module.css.js";
|
|
6
8
|
import { clsx } from "clsx";
|
|
7
9
|
import { jsx } from "react/jsx-runtime";
|
|
8
|
-
import React, { useContext, useEffect } from "react";
|
|
10
|
+
import React, { useContext, useEffect, useRef } from "react";
|
|
9
11
|
//#region src/Checkbox/Checkbox.tsx
|
|
10
12
|
/**
|
|
11
13
|
* An accessible, native checkbox component
|
|
12
14
|
*/
|
|
13
15
|
const Checkbox = /*#__PURE__*/ React.forwardRef(({ checked, className, defaultChecked, indeterminate, disabled, onChange, required, validationStatus, value, ["data-component"]: dataComponent, ...rest }, ref) => {
|
|
14
|
-
const
|
|
16
|
+
const mergedRefEnabled = useFeatureFlag("primer_react_merged_forwarded_refs");
|
|
17
|
+
const internalRef = useRef(null);
|
|
18
|
+
const mergedRef = useMergedRefs(internalRef, ref);
|
|
19
|
+
const providedOrCreatedRef = useProvidedRefOrCreate(ref);
|
|
20
|
+
const checkboxRef = mergedRefEnabled ? internalRef : providedOrCreatedRef;
|
|
21
|
+
const appliedRef = mergedRefEnabled ? mergedRef : providedOrCreatedRef;
|
|
15
22
|
const checkboxGroupContext = useContext(CheckboxGroupContext);
|
|
16
23
|
const handleOnChange = (e) => {
|
|
17
24
|
checkboxGroupContext.onChange && checkboxGroupContext.onChange(e);
|
|
@@ -24,7 +31,7 @@ const Checkbox = /*#__PURE__*/ React.forwardRef(({ checked, className, defaultCh
|
|
|
24
31
|
const inputProps = {
|
|
25
32
|
type: "checkbox",
|
|
26
33
|
disabled,
|
|
27
|
-
ref:
|
|
34
|
+
ref: appliedRef,
|
|
28
35
|
checked: indeterminate ? false : checked,
|
|
29
36
|
defaultChecked,
|
|
30
37
|
required,
|
package/dist/Dialog/Dialog.js
CHANGED
|
@@ -3,6 +3,7 @@ import { useProvidedRefOrCreate } from "../hooks/useProvidedRefOrCreate.js";
|
|
|
3
3
|
import { useOnEscapePress } from "../hooks/useOnEscapePress.js";
|
|
4
4
|
import { useResizeObserver } from "../hooks/useResizeObserver.js";
|
|
5
5
|
import { useId as useId$1 } from "../hooks/useId.js";
|
|
6
|
+
import { useFeatureFlag } from "../FeatureFlags/useFeatureFlag.js";
|
|
6
7
|
import { IconButton } from "../Button/IconButton.js";
|
|
7
8
|
import { ButtonComponent } from "../Button/Button.js";
|
|
8
9
|
import { useSlots } from "../hooks/useSlots.js";
|
|
@@ -244,7 +245,13 @@ const Footer = /*#__PURE__*/ React.forwardRef(function Footer({ className, ...re
|
|
|
244
245
|
Footer.displayName = "Dialog.Footer";
|
|
245
246
|
const Buttons = ({ buttons }) => {
|
|
246
247
|
var _buttons$find;
|
|
247
|
-
const
|
|
248
|
+
const mergedRefEnabled = useFeatureFlag("primer_react_merged_forwarded_refs");
|
|
249
|
+
const providedButtonRef = (_buttons$find = buttons.find((button) => button.autoFocus)) === null || _buttons$find === void 0 ? void 0 : _buttons$find.ref;
|
|
250
|
+
const internalRef = useRef(null);
|
|
251
|
+
const mergedRef = useMergedRefs(internalRef, providedButtonRef);
|
|
252
|
+
const providedOrCreatedRef = useProvidedRefOrCreate(providedButtonRef);
|
|
253
|
+
const autoFocusRef = mergedRefEnabled ? internalRef : providedOrCreatedRef;
|
|
254
|
+
const appliedRef = mergedRefEnabled ? mergedRef : providedOrCreatedRef;
|
|
248
255
|
let autoFocusCount = 0;
|
|
249
256
|
const [hasRendered, setHasRendered] = useState(0);
|
|
250
257
|
useEffect(() => {
|
|
@@ -259,7 +266,7 @@ const Buttons = ({ buttons }) => {
|
|
|
259
266
|
"data-component": "Dialog.FooterButton",
|
|
260
267
|
...buttonProps,
|
|
261
268
|
variant: buttonType === "normal" ? "default" : buttonType,
|
|
262
|
-
ref: autoFocus && autoFocusCount === 0 ? (autoFocusCount++,
|
|
269
|
+
ref: autoFocus && autoFocusCount === 0 ? (autoFocusCount++, appliedRef) : null,
|
|
263
270
|
children: content
|
|
264
271
|
}, index);
|
|
265
272
|
}) });
|
|
@@ -7,7 +7,8 @@ const DefaultFeatureFlags = FeatureFlagScope.create({
|
|
|
7
7
|
primer_react_styled_react_use_primer_theme_providers: false,
|
|
8
8
|
primer_react_action_list_group_heading_trailing_action: false,
|
|
9
9
|
primer_react_action_list_item_gap: false,
|
|
10
|
-
primer_react_timeline_list_semantics: false
|
|
10
|
+
primer_react_timeline_list_semantics: false,
|
|
11
|
+
primer_react_merged_forwarded_refs: true
|
|
11
12
|
});
|
|
12
13
|
//#endregion
|
|
13
14
|
export { DefaultFeatureFlags };
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { useMergedRefs } from "../hooks/useMergedRefs.js";
|
|
1
2
|
import { VisuallyHidden } from "../VisuallyHidden/VisuallyHidden.js";
|
|
2
3
|
import { useProvidedRefOrCreate } from "../hooks/useProvidedRefOrCreate.js";
|
|
3
4
|
import { useProvidedStateOrCreate } from "../hooks/useProvidedStateOrCreate.js";
|
|
4
5
|
import { useId as useId$1 } from "../hooks/useId.js";
|
|
6
|
+
import { useFeatureFlag } from "../FeatureFlags/useFeatureFlag.js";
|
|
5
7
|
import { useFocusZone } from "../hooks/useFocusZone.js";
|
|
6
8
|
import { ActionListContainerContext } from "../ActionList/ActionListContainerContext.js";
|
|
7
9
|
import { ActionList } from "../ActionList/index.js";
|
|
@@ -34,8 +36,17 @@ function FilteredActionList({ loading = false, placeholderText, filterValue: ext
|
|
|
34
36
|
}, [onFilterChange, setInternalFilterValue]);
|
|
35
37
|
const inputAndListContainerRef = useRef(null);
|
|
36
38
|
const listRef = useRef(null);
|
|
37
|
-
const
|
|
38
|
-
const
|
|
39
|
+
const mergedRefEnabled = useFeatureFlag("primer_react_merged_forwarded_refs");
|
|
40
|
+
const internalScrollContainerRef = useRef(null);
|
|
41
|
+
const combinedScrollContainerRef = useMergedRefs(internalScrollContainerRef, providedScrollContainerRef);
|
|
42
|
+
const providedOrCreatedScrollContainerRef = useProvidedRefOrCreate(providedScrollContainerRef);
|
|
43
|
+
const scrollContainerRef = mergedRefEnabled ? internalScrollContainerRef : providedOrCreatedScrollContainerRef;
|
|
44
|
+
const appliedScrollContainerRef = mergedRefEnabled ? combinedScrollContainerRef : providedOrCreatedScrollContainerRef;
|
|
45
|
+
const internalInputRef = useRef(null);
|
|
46
|
+
const combinedInputRef = useMergedRefs(internalInputRef, providedInputRef);
|
|
47
|
+
const providedOrCreatedInputRef = useProvidedRefOrCreate(providedInputRef);
|
|
48
|
+
const inputRef = mergedRefEnabled ? internalInputRef : providedOrCreatedInputRef;
|
|
49
|
+
const appliedInputRef = mergedRefEnabled ? combinedInputRef : providedOrCreatedInputRef;
|
|
39
50
|
const usingRovingTabindex = _PrivateFocusManagement === "roving-tabindex";
|
|
40
51
|
const [listContainerElement, setListContainerElement] = useState(null);
|
|
41
52
|
const activeDescendantRef = useRef();
|
|
@@ -290,7 +301,7 @@ function FilteredActionList({ loading = false, placeholderText, filterValue: ext
|
|
|
290
301
|
"data-component": "FilteredActionList",
|
|
291
302
|
children: [
|
|
292
303
|
/*#__PURE__*/ jsx(FilteredActionListInput, {
|
|
293
|
-
inputRef,
|
|
304
|
+
inputRef: appliedInputRef,
|
|
294
305
|
value: filterValue,
|
|
295
306
|
onInputChange,
|
|
296
307
|
onInputKeyPress,
|
|
@@ -324,7 +335,7 @@ function FilteredActionList({ loading = false, placeholderText, filterValue: ext
|
|
|
324
335
|
})]
|
|
325
336
|
}),
|
|
326
337
|
/*#__PURE__*/ jsx("div", {
|
|
327
|
-
ref:
|
|
338
|
+
ref: appliedScrollContainerRef,
|
|
328
339
|
className: FilteredActionList_module_css_default.Container,
|
|
329
340
|
children: getBodyContent()
|
|
330
341
|
})
|
|
@@ -3,7 +3,7 @@ import React from "react";
|
|
|
3
3
|
|
|
4
4
|
//#region src/FilteredActionList/FilteredActionListInput.d.ts
|
|
5
5
|
interface FilteredActionListInputProps extends Partial<Omit<TextInputProps, 'onChange' | 'onKeyDown'>> {
|
|
6
|
-
inputRef: React.
|
|
6
|
+
inputRef: React.Ref<HTMLInputElement | null>;
|
|
7
7
|
onInputChange?: (e: React.ChangeEvent<HTMLInputElement>) => void;
|
|
8
8
|
onInputKeyPress?: React.KeyboardEventHandler<HTMLInputElement>;
|
|
9
9
|
onInputKeyDown?: React.KeyboardEventHandler<HTMLInputElement>;
|
|
@@ -13,16 +13,6 @@ const getOverlayWidth = (buttonClientRect, containerRef, overlayPaddingPx) => {
|
|
|
13
13
|
var _containerRef$current;
|
|
14
14
|
return overlayPaddingPx + buttonClientRect.right - (((_containerRef$current = containerRef.current) === null || _containerRef$current === void 0 ? void 0 : _containerRef$current.getBoundingClientRect().left) || 0);
|
|
15
15
|
};
|
|
16
|
-
const getVisibilityMapAfterIndex = (childCount, truncateAfter) => {
|
|
17
|
-
const updatedEntries = {};
|
|
18
|
-
for (let index = 0; index < childCount; index++) updatedEntries[index.toString()] = index < truncateAfter;
|
|
19
|
-
return updatedEntries;
|
|
20
|
-
};
|
|
21
|
-
const visibilityMapsMatch = (left, right) => {
|
|
22
|
-
const leftKeys = Object.keys(left);
|
|
23
|
-
const rightKeys = Object.keys(right);
|
|
24
|
-
return leftKeys.length === rightKeys.length && leftKeys.every((key) => Object.prototype.hasOwnProperty.call(right, key) && left[key] === right[key]);
|
|
25
|
-
};
|
|
26
16
|
const InlineToggle = ({ collapseButtonRef, collapseInlineExpandedChildren, expandButtonRef, hiddenItemIds, isOverflowShown, showAllTokensInline }) => isOverflowShown ? /*#__PURE__*/ jsx(ButtonComponent, {
|
|
27
17
|
ref: collapseButtonRef,
|
|
28
18
|
onClick: collapseInlineExpandedChildren,
|
|
@@ -109,7 +99,6 @@ const LabelGroup = ({ children, visibleChildCount, overflowStyle = "overlay", as
|
|
|
109
99
|
bottom: 0,
|
|
110
100
|
toJSON: () => void 0
|
|
111
101
|
});
|
|
112
|
-
const childArray = React.Children.toArray(children);
|
|
113
102
|
const overlayPaddingPx = 8;
|
|
114
103
|
const hiddenItemIds = Object.keys(visibilityMap).filter((key) => !visibilityMap[key]);
|
|
115
104
|
const overlayWidth = hiddenItemIds.length && overflowStyle === "overlay" ? getOverlayWidth(buttonClientRect, containerRef, overlayPaddingPx) : void 0;
|
|
@@ -121,8 +110,15 @@ const LabelGroup = ({ children, visibleChildCount, overflowStyle = "overlay", as
|
|
|
121
110
|
}
|
|
122
111
|
}, [buttonClientRect]);
|
|
123
112
|
const hideChildrenAfterIndex = React.useCallback((truncateAfter) => {
|
|
124
|
-
|
|
125
|
-
|
|
113
|
+
var _containerRef$current2;
|
|
114
|
+
const containerChildren = ((_containerRef$current2 = containerRef.current) === null || _containerRef$current2 === void 0 ? void 0 : _containerRef$current2.children) || [];
|
|
115
|
+
const updatedEntries = {};
|
|
116
|
+
for (const child of containerChildren) {
|
|
117
|
+
const targetId = child.getAttribute("data-index");
|
|
118
|
+
if (targetId) updatedEntries[targetId] = parseInt(targetId, 10) < truncateAfter;
|
|
119
|
+
}
|
|
120
|
+
setVisibilityMap(updatedEntries);
|
|
121
|
+
}, []);
|
|
126
122
|
const openOverflowOverlay = React.useCallback(() => setIsOverflowShown(true), [setIsOverflowShown]);
|
|
127
123
|
const closeOverflowOverlay = React.useCallback(() => {
|
|
128
124
|
setIsOverflowShown(false);
|
|
@@ -143,12 +139,6 @@ const LabelGroup = ({ children, visibleChildCount, overflowStyle = "overlay", as
|
|
|
143
139
|
setVisibilityMap({});
|
|
144
140
|
setIsOverflowShown(true);
|
|
145
141
|
}, [setVisibilityMap, setIsOverflowShown]);
|
|
146
|
-
const numericVisibilityMap = React.useMemo(() => visibleChildCount && typeof visibleChildCount === "number" && !isOverflowShown ? getVisibilityMapAfterIndex(childArray.length, visibleChildCount) : void 0, [
|
|
147
|
-
childArray.length,
|
|
148
|
-
isOverflowShown,
|
|
149
|
-
visibleChildCount
|
|
150
|
-
]);
|
|
151
|
-
if (numericVisibilityMap && !visibilityMapsMatch(visibilityMap, numericVisibilityMap)) setVisibilityMap(numericVisibilityMap);
|
|
152
142
|
React.useEffect(() => {
|
|
153
143
|
if (!visibleChildCount || isOverflowShown) return;
|
|
154
144
|
if (visibleChildCount === "auto") {
|
|
@@ -167,15 +157,16 @@ const LabelGroup = ({ children, visibleChildCount, overflowStyle = "overlay", as
|
|
|
167
157
|
rootMargin: `0px -${buttonClientRect.width}px 0px 0px`,
|
|
168
158
|
threshold: 1
|
|
169
159
|
});
|
|
170
|
-
for (const item of ((_containerRef$
|
|
171
|
-
var _containerRef$
|
|
160
|
+
for (const item of ((_containerRef$current3 = containerRef.current) === null || _containerRef$current3 === void 0 ? void 0 : _containerRef$current3.children) || []) {
|
|
161
|
+
var _containerRef$current3;
|
|
172
162
|
if (item.getAttribute("data-index")) observer.observe(item);
|
|
173
163
|
}
|
|
174
164
|
return () => observer.disconnect();
|
|
175
|
-
}
|
|
165
|
+
} else hideChildrenAfterIndex(visibleChildCount);
|
|
176
166
|
}, [
|
|
177
167
|
buttonClientRect,
|
|
178
168
|
visibleChildCount,
|
|
169
|
+
hideChildrenAfterIndex,
|
|
179
170
|
isOverflowShown
|
|
180
171
|
]);
|
|
181
172
|
React.useEffect(() => {
|
|
@@ -205,7 +196,7 @@ const LabelGroup = ({ children, visibleChildCount, overflowStyle = "overlay", as
|
|
|
205
196
|
"data-list": isList || void 0,
|
|
206
197
|
className: clsx(className, LabelGroup_module_css_default.Container),
|
|
207
198
|
"data-component": "LabelGroup",
|
|
208
|
-
children: [
|
|
199
|
+
children: [React.Children.map(children, (child, index) => /*#__PURE__*/ jsx(ItemWrapperComponent, {
|
|
209
200
|
"data-index": index,
|
|
210
201
|
className: clsx(LabelGroup_module_css_default.ItemWrapper, { [LabelGroup_module_css_default["ItemWrapper--hidden"]]: hiddenItemIds.includes(index.toString()) }),
|
|
211
202
|
children: child
|
|
@@ -218,7 +209,7 @@ const LabelGroup = ({ children, visibleChildCount, overflowStyle = "overlay", as
|
|
|
218
209
|
hiddenItemIds,
|
|
219
210
|
isOverflowShown,
|
|
220
211
|
showAllTokensInline,
|
|
221
|
-
totalLength:
|
|
212
|
+
totalLength: React.Children.toArray(children).length
|
|
222
213
|
}) : /*#__PURE__*/ jsx(OverlayToggle, {
|
|
223
214
|
closeOverflowOverlay,
|
|
224
215
|
expandButtonRef,
|
|
@@ -227,7 +218,7 @@ const LabelGroup = ({ children, visibleChildCount, overflowStyle = "overlay", as
|
|
|
227
218
|
openOverflowOverlay,
|
|
228
219
|
overlayPaddingPx,
|
|
229
220
|
overlayWidth,
|
|
230
|
-
totalLength:
|
|
221
|
+
totalLength: React.Children.toArray(children).length,
|
|
231
222
|
children
|
|
232
223
|
})
|
|
233
224
|
})]
|
package/dist/Overlay/Overlay.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { useMergedRefs } from "../hooks/useMergedRefs.js";
|
|
2
2
|
import useIsomorphicLayoutEffect from "../utils/useIsomorphicLayoutEffect.js";
|
|
3
3
|
import { useOverlay } from "../hooks/useOverlay.js";
|
|
4
|
-
import Portal_default from "../Portal/index.js";
|
|
5
4
|
import { useFeatureFlag } from "../FeatureFlags/useFeatureFlag.js";
|
|
5
|
+
import Portal_default from "../Portal/index.js";
|
|
6
6
|
import Overlay_module_css_default from "./Overlay.module.css.js";
|
|
7
7
|
import { clsx } from "clsx";
|
|
8
8
|
import { jsx } from "react/jsx-runtime";
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { useMergedRefs } from "../hooks/useMergedRefs.js";
|
|
1
2
|
import { useProvidedRefOrCreate } from "../hooks/useProvidedRefOrCreate.js";
|
|
2
3
|
import { warning } from "../utils/warning.js";
|
|
4
|
+
import { useFeatureFlag } from "../FeatureFlags/useFeatureFlag.js";
|
|
3
5
|
import { isResponsiveValue } from "../hooks/useResponsiveValue.js";
|
|
4
6
|
import { isSlot } from "../utils/is-slot.js";
|
|
5
7
|
import { getResponsiveAttributes } from "../internal/utils/getResponsiveAttributes.js";
|
|
@@ -10,7 +12,7 @@ import PageHeader_module_css_default from "./PageHeader.module.css.js";
|
|
|
10
12
|
import { c } from "react-compiler-runtime";
|
|
11
13
|
import { clsx } from "clsx";
|
|
12
14
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
13
|
-
import React, { useEffect } from "react";
|
|
15
|
+
import React, { useEffect, useRef } from "react";
|
|
14
16
|
import { ArrowLeftIcon } from "@primer/octicons-react";
|
|
15
17
|
//#region src/PageHeader/PageHeader.tsx
|
|
16
18
|
const hiddenOnRegularAndWide = {
|
|
@@ -27,7 +29,12 @@ const Root = /*#__PURE__*/ React.forwardRef((t0, forwardedRef) => {
|
|
|
27
29
|
const $ = c(17);
|
|
28
30
|
const { children, className, as: t1, "aria-label": ariaLabel, role, hasBorder } = t0;
|
|
29
31
|
const BaseComponent = t1 === void 0 ? "div" : t1;
|
|
30
|
-
const
|
|
32
|
+
const mergedRefEnabled = useFeatureFlag("primer_react_merged_forwarded_refs");
|
|
33
|
+
const internalRef = useRef(null);
|
|
34
|
+
const mergedRef = useMergedRefs(internalRef, forwardedRef);
|
|
35
|
+
const providedOrCreatedRef = useProvidedRefOrCreate(forwardedRef);
|
|
36
|
+
const rootRef = mergedRefEnabled ? internalRef : providedOrCreatedRef;
|
|
37
|
+
const appliedRef = mergedRefEnabled ? mergedRef : providedOrCreatedRef;
|
|
31
38
|
const hoistChildState = (nodes) => {
|
|
32
39
|
const result = { hasNavigation: false };
|
|
33
40
|
for (const child of React.Children.toArray(nodes)) {
|
|
@@ -89,9 +96,9 @@ const Root = /*#__PURE__*/ React.forwardRef((t0, forwardedRef) => {
|
|
|
89
96
|
const t8 = getResponsiveAttributes("title-size-variant", titleVariant);
|
|
90
97
|
const t9 = getNavHiddenDataAttributes(navigationHidden);
|
|
91
98
|
let t10;
|
|
92
|
-
if ($[6] !== BaseComponent || $[7] !==
|
|
99
|
+
if ($[6] !== BaseComponent || $[7] !== appliedRef || $[8] !== ariaLabel || $[9] !== children || $[10] !== role || $[11] !== t4 || $[12] !== t6 || $[13] !== t7 || $[14] !== t8 || $[15] !== t9) {
|
|
93
100
|
t10 = /*#__PURE__*/ jsx(BaseComponent, {
|
|
94
|
-
ref:
|
|
101
|
+
ref: appliedRef,
|
|
95
102
|
className: t4,
|
|
96
103
|
"data-component": t5,
|
|
97
104
|
"data-has-border": t6,
|
|
@@ -103,10 +110,10 @@ const Root = /*#__PURE__*/ React.forwardRef((t0, forwardedRef) => {
|
|
|
103
110
|
children
|
|
104
111
|
});
|
|
105
112
|
$[6] = BaseComponent;
|
|
106
|
-
$[7] =
|
|
107
|
-
$[8] =
|
|
108
|
-
$[9] =
|
|
109
|
-
$[10] =
|
|
113
|
+
$[7] = appliedRef;
|
|
114
|
+
$[8] = ariaLabel;
|
|
115
|
+
$[9] = children;
|
|
116
|
+
$[10] = role;
|
|
110
117
|
$[11] = t4;
|
|
111
118
|
$[12] = t6;
|
|
112
119
|
$[13] = t7;
|
|
@@ -295,7 +302,9 @@ const TitleArea = /*#__PURE__*/ React.forwardRef((t0, forwardedRef) => {
|
|
|
295
302
|
const { children, className, hidden: t1, variant: t2 } = t0;
|
|
296
303
|
const hidden = t1 === void 0 ? false : t1;
|
|
297
304
|
const variant = t2 === void 0 ? "medium" : t2;
|
|
298
|
-
const
|
|
305
|
+
const mergedRefEnabled = useFeatureFlag("primer_react_merged_forwarded_refs");
|
|
306
|
+
const providedOrCreatedRef = useProvidedRefOrCreate(forwardedRef);
|
|
307
|
+
const titleAreaRef = mergedRefEnabled ? forwardedRef : providedOrCreatedRef;
|
|
299
308
|
let t3;
|
|
300
309
|
if ($[0] !== className) {
|
|
301
310
|
t3 = clsx(PageHeader_module_css_default.TitleArea, className);
|
|
@@ -2,13 +2,13 @@ import { useProvidedRefOrCreate } from "../hooks/useProvidedRefOrCreate.js";
|
|
|
2
2
|
import { useProvidedStateOrCreate } from "../hooks/useProvidedStateOrCreate.js";
|
|
3
3
|
import { isAlphabetKey } from "../hooks/useMnemonics.js";
|
|
4
4
|
import { useId as useId$1 } from "../hooks/useId.js";
|
|
5
|
+
import { useFeatureFlag } from "../FeatureFlags/useFeatureFlag.js";
|
|
5
6
|
import useSafeTimeout from "../hooks/useSafeTimeout.js";
|
|
6
7
|
import { IconButton } from "../Button/IconButton.js";
|
|
7
8
|
import { LinkButton } from "../Button/LinkButton.js";
|
|
8
9
|
import { ButtonComponent } from "../Button/Button.js";
|
|
9
10
|
import { useResponsiveValue } from "../hooks/useResponsiveValue.js";
|
|
10
11
|
import Heading from "../Heading/Heading.js";
|
|
11
|
-
import { useFeatureFlag } from "../FeatureFlags/useFeatureFlag.js";
|
|
12
12
|
import { AnchoredOverlay } from "../AnchoredOverlay/AnchoredOverlay.js";
|
|
13
13
|
import { Banner } from "../Banner/index.js";
|
|
14
14
|
import { useFormControlContext } from "../FormControl/_FormControlContext.js";
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { useMergedRefs } from "../hooks/useMergedRefs.js";
|
|
1
2
|
import { useProvidedRefOrCreate } from "../hooks/useProvidedRefOrCreate.js";
|
|
2
3
|
import { AriaStatus } from "../live-region/AriaStatus.js";
|
|
4
|
+
import { useFeatureFlag } from "../FeatureFlags/useFeatureFlag.js";
|
|
3
5
|
import Text_default from "../Text/Text.js";
|
|
4
6
|
import _VisuallyHidden_module_css_default from "../_VisuallyHidden.module.css.js";
|
|
5
7
|
import VisuallyHidden from "../_VisuallyHidden.js";
|
|
@@ -11,14 +13,19 @@ import UnstyledTextInput from "../internal/components/UnstyledTextInput.js";
|
|
|
11
13
|
import { getCharacterCountState } from "../utils/character-counter.js";
|
|
12
14
|
import { clsx } from "clsx";
|
|
13
15
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
14
|
-
import React, { useCallback, useId, useState } from "react";
|
|
16
|
+
import React, { useCallback, useId, useRef, useState } from "react";
|
|
15
17
|
import { isValidElementType } from "react-is";
|
|
16
18
|
import { AlertFillIcon } from "@primer/octicons-react";
|
|
17
19
|
//#region src/TextInput/TextInput.tsx
|
|
18
20
|
const TextInput = /*#__PURE__*/ React.forwardRef(({ icon: IconComponent, leadingVisual: LeadingVisual, trailingVisual: TrailingVisual, trailingAction, block, className, contrast, disabled, loading, loaderPosition = "auto", loaderText = "Loading", monospace, validationStatus, size: sizeProp, onFocus, onBlur, variant: variantProp, width: widthProp, minWidth: minWidthProp, maxWidth: maxWidthProp, type = "text", required, characterLimit, onChange, value, defaultValue, "data-component": dataComponent, ...inputProps }, ref) => {
|
|
19
21
|
var _counter$isOverLimit;
|
|
20
22
|
const [isInputFocused, setIsInputFocused] = useState(false);
|
|
21
|
-
const
|
|
23
|
+
const mergedRefEnabled = useFeatureFlag("primer_react_merged_forwarded_refs");
|
|
24
|
+
const internalRef = useRef(null);
|
|
25
|
+
const mergedRef = useMergedRefs(internalRef, ref);
|
|
26
|
+
const providedOrCreatedRef = useProvidedRefOrCreate(ref);
|
|
27
|
+
const inputRef = mergedRefEnabled ? internalRef : providedOrCreatedRef;
|
|
28
|
+
const appliedRef = mergedRefEnabled ? mergedRef : providedOrCreatedRef;
|
|
22
29
|
const isControlled = value !== void 0;
|
|
23
30
|
const [uncontrolledLength, setUncontrolledLength] = useState(() => defaultValue !== void 0 ? String(defaultValue).length : 0);
|
|
24
31
|
const currentLength = isControlled ? String(value).length : uncontrolledLength;
|
|
@@ -88,7 +95,7 @@ const TextInput = /*#__PURE__*/ React.forwardRef(({ icon: IconComponent, leading
|
|
|
88
95
|
children: typeof LeadingVisual !== "string" && isValidElementType(LeadingVisual) ? /*#__PURE__*/ jsx(LeadingVisual, {}) : LeadingVisual
|
|
89
96
|
}),
|
|
90
97
|
/*#__PURE__*/ jsx(UnstyledTextInput, {
|
|
91
|
-
ref:
|
|
98
|
+
ref: appliedRef,
|
|
92
99
|
disabled,
|
|
93
100
|
onFocus: handleInputFocus,
|
|
94
101
|
onBlur: handleInputBlur,
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { useMergedRefs } from "../hooks/useMergedRefs.js";
|
|
1
2
|
import { useProvidedRefOrCreate } from "../hooks/useProvidedRefOrCreate.js";
|
|
2
3
|
import { useOnEscapePress } from "../hooks/useOnEscapePress.js";
|
|
3
4
|
import { useId as useId$1 } from "../hooks/useId.js";
|
|
4
5
|
import { warning } from "../utils/warning.js";
|
|
6
|
+
import { useFeatureFlag } from "../FeatureFlags/useFeatureFlag.js";
|
|
5
7
|
import { invariant } from "../utils/invariant.js";
|
|
6
8
|
import Tooltip_module_css_default from "./Tooltip.module.css.js";
|
|
7
9
|
import VisuallyHidden from "../_VisuallyHidden.js";
|
|
@@ -80,7 +82,12 @@ const emptyKeybindingHints = [];
|
|
|
80
82
|
const Tooltip = /*#__PURE__*/ React.forwardRef(({ direction = "s", text, type = "description", children, id, className, keybindingHint = emptyKeybindingHints, delay = "short", _privateDisableTooltip = false, ...rest }, forwardedRef) => {
|
|
81
83
|
const tooltipId = useId$1(id);
|
|
82
84
|
const child = Children.only(children);
|
|
83
|
-
const
|
|
85
|
+
const mergedRefEnabled = useFeatureFlag("primer_react_merged_forwarded_refs");
|
|
86
|
+
const internalRef = useRef(null);
|
|
87
|
+
const mergedTriggerRef = useMergedRefs(internalRef, forwardedRef);
|
|
88
|
+
const providedOrCreatedRef = useProvidedRefOrCreate(forwardedRef);
|
|
89
|
+
const triggerRef = mergedRefEnabled ? internalRef : providedOrCreatedRef;
|
|
90
|
+
const appliedTriggerRef = mergedRefEnabled ? mergedTriggerRef : providedOrCreatedRef;
|
|
84
91
|
const tooltipElRef = useRef(null);
|
|
85
92
|
const [calculatedDirection, setCalculatedDirection] = useState(direction);
|
|
86
93
|
const [isPopoverOpen, setIsPopoverOpen] = useState(false);
|
|
@@ -157,7 +164,7 @@ const Tooltip = /*#__PURE__*/ React.forwardRef(({ direction = "s", text, type =
|
|
|
157
164
|
return /*#__PURE__*/ jsx(TooltipContext.Provider, {
|
|
158
165
|
value,
|
|
159
166
|
children: /*#__PURE__*/ jsxs(Fragment, { children: [/*#__PURE__*/ React.isValidElement(child) && /*#__PURE__*/ React.cloneElement(child, {
|
|
160
|
-
ref:
|
|
167
|
+
ref: appliedTriggerRef,
|
|
161
168
|
"aria-describedby": (() => {
|
|
162
169
|
if (type !== "description") return child.props["aria-describedby"];
|
|
163
170
|
const existingDescribedBy = child.props["aria-describedby"];
|
|
@@ -73,7 +73,7 @@ type TabPanelProps = {
|
|
|
73
73
|
value: string;
|
|
74
74
|
};
|
|
75
75
|
type TabListHookProps<T extends HTMLElement> = TabListProps & {
|
|
76
|
-
/** Optional ref to use for the tablist. If none is provided, one will be generated automatically */ref?: React.
|
|
76
|
+
/** Optional ref to use for the tablist. If none is provided, one will be generated automatically */ref?: React.Ref<T | null>;
|
|
77
77
|
};
|
|
78
78
|
type TabListHookResult<T extends HTMLElement> = {
|
|
79
79
|
/** Props to be spread onto the tablist element */tabListProps: {
|
|
@@ -81,7 +81,7 @@ type TabListHookResult<T extends HTMLElement> = {
|
|
|
81
81
|
'aria-orientation': AriaAttributes['aria-orientation'];
|
|
82
82
|
'aria-label': AriaAttributes['aria-label'];
|
|
83
83
|
'aria-labelledby': AriaAttributes['aria-labelledby'];
|
|
84
|
-
ref: React.
|
|
84
|
+
ref: React.Ref<T | null>;
|
|
85
85
|
role: 'tablist';
|
|
86
86
|
};
|
|
87
87
|
};
|
|
@@ -1,10 +1,18 @@
|
|
|
1
|
+
import { useMergedRefs } from "../../hooks/useMergedRefs.js";
|
|
1
2
|
import { useProvidedRefOrCreate } from "../../hooks/useProvidedRefOrCreate.js";
|
|
3
|
+
import { useFeatureFlag } from "../../FeatureFlags/useFeatureFlag.js";
|
|
2
4
|
import { c } from "react-compiler-runtime";
|
|
5
|
+
import { useRef } from "react";
|
|
3
6
|
//#region src/experimental/Tabs/useTabList.ts
|
|
4
7
|
function useTabList(props) {
|
|
5
8
|
const $ = c(9);
|
|
6
9
|
const { "aria-label": ariaLabel, "aria-labelledby": ariaLabelledby, "aria-orientation": ariaOrientation } = props;
|
|
7
|
-
const
|
|
10
|
+
const mergedRefEnabled = useFeatureFlag("primer_react_merged_forwarded_refs");
|
|
11
|
+
const internalRef = useRef(null);
|
|
12
|
+
const mergedRef = useMergedRefs(internalRef, props.ref);
|
|
13
|
+
const providedOrCreatedRef = useProvidedRefOrCreate(props.ref);
|
|
14
|
+
const ref = mergedRefEnabled ? internalRef : providedOrCreatedRef;
|
|
15
|
+
const appliedRef = mergedRefEnabled ? mergedRef : providedOrCreatedRef;
|
|
8
16
|
let t0;
|
|
9
17
|
if ($[0] !== ariaOrientation || $[1] !== ref) {
|
|
10
18
|
t0 = (event) => {
|
|
@@ -39,19 +47,19 @@ function useTabList(props) {
|
|
|
39
47
|
const onKeyDown = t0;
|
|
40
48
|
const t1 = ariaOrientation !== null && ariaOrientation !== void 0 ? ariaOrientation : "horizontal";
|
|
41
49
|
let t2;
|
|
42
|
-
if ($[3] !==
|
|
50
|
+
if ($[3] !== appliedRef || $[4] !== ariaLabel || $[5] !== ariaLabelledby || $[6] !== onKeyDown || $[7] !== t1) {
|
|
43
51
|
t2 = { tabListProps: {
|
|
44
|
-
ref,
|
|
52
|
+
ref: appliedRef,
|
|
45
53
|
"aria-label": ariaLabel,
|
|
46
54
|
"aria-labelledby": ariaLabelledby,
|
|
47
55
|
"aria-orientation": t1,
|
|
48
56
|
role: "tablist",
|
|
49
57
|
onKeyDown
|
|
50
58
|
} };
|
|
51
|
-
$[3] =
|
|
52
|
-
$[4] =
|
|
53
|
-
$[5] =
|
|
54
|
-
$[6] =
|
|
59
|
+
$[3] = appliedRef;
|
|
60
|
+
$[4] = ariaLabel;
|
|
61
|
+
$[5] = ariaLabelledby;
|
|
62
|
+
$[6] = onKeyDown;
|
|
55
63
|
$[7] = t1;
|
|
56
64
|
$[8] = t2;
|
|
57
65
|
} else t2 = $[8];
|
|
@@ -3,6 +3,9 @@ import { Announce } from "../live-region/Announce.js";
|
|
|
3
3
|
import { AriaAlert } from "../live-region/AriaAlert.js";
|
|
4
4
|
import { AriaStatus } from "../live-region/AriaStatus.js";
|
|
5
5
|
import { ButtonBase } from "../Button/ButtonBase.js";
|
|
6
|
+
import { DefaultFeatureFlags } from "../FeatureFlags/DefaultFeatureFlags.js";
|
|
7
|
+
import { FeatureFlags } from "../FeatureFlags/FeatureFlags.js";
|
|
8
|
+
import { useFeatureFlag } from "../FeatureFlags/useFeatureFlag.js";
|
|
6
9
|
import { KeybindingHint } from "../KeybindingHint/KeybindingHint.js";
|
|
7
10
|
import { getAccessibleKeybindingHintString } from "../KeybindingHint/utils.js";
|
|
8
11
|
import { Tooltip } from "../TooltipV2/Tooltip.js";
|
|
@@ -10,9 +13,6 @@ import { useSlots } from "../hooks/useSlots.js";
|
|
|
10
13
|
import { useOverflow } from "../hooks/useOverflow.js";
|
|
11
14
|
import { ScrollableRegion } from "../ScrollableRegion/ScrollableRegion.js";
|
|
12
15
|
import { Dialog } from "../Dialog/Dialog.js";
|
|
13
|
-
import { DefaultFeatureFlags } from "../FeatureFlags/DefaultFeatureFlags.js";
|
|
14
|
-
import { FeatureFlags } from "../FeatureFlags/FeatureFlags.js";
|
|
15
|
-
import { useFeatureFlag } from "../FeatureFlags/useFeatureFlag.js";
|
|
16
16
|
import { Stack } from "../Stack/index.js";
|
|
17
17
|
import { SkeletonBox } from "../Skeleton/SkeletonBox.js";
|
|
18
18
|
import { FilteredActionListLoadingTypes } from "../FilteredActionList/constants.js";
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { isExperimentalReactVersion, reactMajorVersion } from "../utils/environment.js";
|
|
2
2
|
import { c } from "react-compiler-runtime";
|
|
3
|
-
import "react";
|
|
3
|
+
import { version } from "react";
|
|
4
4
|
//#region src/hooks/useMergedRefs.ts
|
|
5
|
+
var _version$split$;
|
|
6
|
+
const majorReactVersion = parseInt((_version$split$ = version.split(".")[0]) !== null && _version$split$ !== void 0 ? _version$split$ : "18", 10);
|
|
5
7
|
/**
|
|
6
8
|
* Cleanup functions for refs were introduced in React 19. For feature detection,
|
|
7
9
|
* we look to see if current version of React is >= 19 or if it is an
|
|
@@ -48,6 +50,7 @@ function useMergedRefs(refA, refB) {
|
|
|
48
50
|
const cleanupA = setRef(refA, value);
|
|
49
51
|
const cleanupB = setRef(refB, value);
|
|
50
52
|
if (!supportsRefCleanup) return;
|
|
53
|
+
if (majorReactVersion <= 18) return;
|
|
51
54
|
return () => {
|
|
52
55
|
if (cleanupA) cleanupA();
|
|
53
56
|
else setRef(refA, null);
|
|
@@ -9,17 +9,14 @@ import React from "react";
|
|
|
9
9
|
* @param providedRef The ref to use - if undefined, will use the ref from a call to React.useRef
|
|
10
10
|
* @type TRef The type of the RefObject which should be created.
|
|
11
11
|
*
|
|
12
|
-
* @
|
|
13
|
-
*
|
|
12
|
+
* @note This hook is overly restrictive in that it forces the provided ref to be a ref object rather than a callback.
|
|
13
|
+
* In particular, it should **not** be used to merge internal refs with forwarded refs. For this, use
|
|
14
|
+
* {@linkcode useMergedRefs} instead.
|
|
14
15
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* - return <div ref={ref} />
|
|
21
|
-
* + return <div ref={mergedRef} />
|
|
22
|
-
* ```
|
|
16
|
+
* The primary valid use case for this hook is for when the consumer is using the provided ref to point to an external
|
|
17
|
+
* element, like an externally rendered anchor. This is 'backwards' from forwarded refs with respect to data flow; the
|
|
18
|
+
* consumer is passing a reference to an external element, rather than passing a handle to obtain a reference to an
|
|
19
|
+
* internal element.
|
|
23
20
|
*/
|
|
24
21
|
declare function useProvidedRefOrCreate<TRef>(providedRef?: React.RefObject<TRef | null>): React.RefObject<TRef | null>;
|
|
25
22
|
//#endregion
|
|
@@ -8,17 +8,14 @@ import React from "react";
|
|
|
8
8
|
* @param providedRef The ref to use - if undefined, will use the ref from a call to React.useRef
|
|
9
9
|
* @type TRef The type of the RefObject which should be created.
|
|
10
10
|
*
|
|
11
|
-
* @
|
|
12
|
-
*
|
|
11
|
+
* @note This hook is overly restrictive in that it forces the provided ref to be a ref object rather than a callback.
|
|
12
|
+
* In particular, it should **not** be used to merge internal refs with forwarded refs. For this, use
|
|
13
|
+
* {@linkcode useMergedRefs} instead.
|
|
13
14
|
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* - return <div ref={ref} />
|
|
20
|
-
* + return <div ref={mergedRef} />
|
|
21
|
-
* ```
|
|
15
|
+
* The primary valid use case for this hook is for when the consumer is using the provided ref to point to an external
|
|
16
|
+
* element, like an externally rendered anchor. This is 'backwards' from forwarded refs with respect to data flow; the
|
|
17
|
+
* consumer is passing a reference to an external element, rather than passing a handle to obtain a reference to an
|
|
18
|
+
* internal element.
|
|
22
19
|
*/
|
|
23
20
|
function useProvidedRefOrCreate(providedRef) {
|
|
24
21
|
const createdRef = React.useRef(null);
|
package/package.json
CHANGED