@primer/react 0.0.0-20260424133134 → 0.0.0-20260424151259
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @primer/react
|
|
2
2
|
|
|
3
|
-
## 0.0.0-
|
|
3
|
+
## 0.0.0-20260424151259
|
|
4
4
|
|
|
5
5
|
### Minor Changes
|
|
6
6
|
|
|
@@ -23,14 +23,12 @@
|
|
|
23
23
|
|
|
24
24
|
This enables consumers to query and test components using stable selectors like `[data-component="Table.Row"]`.
|
|
25
25
|
|
|
26
|
-
- [#7766](https://github.com/primer/react/pull/7766) [`
|
|
26
|
+
- [#7766](https://github.com/primer/react/pull/7766) [`6770095`](https://github.com/primer/react/commit/67700952bec8373c01843b88e39ccb6dfe5b108c) Thanks [@TylerJDev](https://github.com/TylerJDev)! - AnchoredOverlay: (Behind feature flag) Make popover API usage opt-in
|
|
27
27
|
|
|
28
28
|
- [#7763](https://github.com/primer/react/pull/7763) [`b288d6e`](https://github.com/primer/react/commit/b288d6e2dc9d1eef345ef4d16f6b0fba4f165955) Thanks [@liuliu-dev](https://github.com/liuliu-dev)! - Add borderRadius prop to Card component.
|
|
29
29
|
|
|
30
30
|
### Patch Changes
|
|
31
31
|
|
|
32
|
-
- [`4c2c54d`](https://github.com/primer/react/commit/4c2c54d1f96646a5705d83374317f29cc1cfd0ba) Thanks [@alexus37](https://github.com/alexus37)! - Checkbox: replace useLayoutEffect with ref callback for setting indeterminate state
|
|
33
|
-
|
|
34
32
|
- [#7714](https://github.com/primer/react/pull/7714) [`e974d9f`](https://github.com/primer/react/commit/e974d9f6d156805dbda9639a3fe6091a02a1a754) Thanks [@hectahertz](https://github.com/hectahertz)! - perf(ActionList): replace :has() selector with JS-computed attribute
|
|
35
33
|
|
|
36
34
|
- [#7754](https://github.com/primer/react/pull/7754) [`9e3fe4b`](https://github.com/primer/react/commit/9e3fe4b501ce5affb558bf92697e5c79341903ca) Thanks [@liuliu-dev](https://github.com/liuliu-dev)! - Breadcrumbs: On narrow viewports, only show the current page breadcrumb and the overflow menu when `overflow="menu"` is set.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AnchoredOverlay.d.ts","sourceRoot":"","sources":["../../src/AnchoredOverlay/AnchoredOverlay.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,
|
|
1
|
+
{"version":3,"file":"AnchoredOverlay.d.ts","sourceRoot":"","sources":["../../src/AnchoredOverlay/AnchoredOverlay.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAA2C,KAAK,GAAG,EAAC,MAAM,OAAO,CAAA;AACxE,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,YAAY,CAAA;AAE5C,OAAO,KAAK,EAAC,qBAAqB,EAAC,MAAM,uBAAuB,CAAA;AAEhE,OAAO,KAAK,EAAC,qBAAqB,EAAC,MAAM,uBAAuB,CAAA;AAIhE,OAAO,KAAK,EAAC,cAAc,EAAE,gBAAgB,EAAC,MAAM,mBAAmB,CAAA;AACvE,OAAO,EAAC,KAAK,eAAe,EAAC,MAAM,6BAA6B,CAAA;AAChE,OAAO,EAAa,KAAK,eAAe,EAAC,MAAM,WAAW,CAAA;AAO1D,UAAU,8BAA8B;IACtC;;;OAGG;IACH,YAAY,EAAE,CAAC,CAAC,SAAS,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,WAAW,CAAC,EAAE,YAAY,GAAG,iBAAiB,CAAC,EAChG,KAAK,EAAE,CAAC,KACL,GAAG,CAAC,OAAO,CAAA;IAEhB;;OAEG;IACH,SAAS,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,CAAA;IAE/C;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAED,UAAU,iC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nE;;OAEG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAA;IAC5B;;OAEG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC,eAAe,CAAC,CAAA;IAC3C;;;OAGG;IACH,QAAQ,CAAC,EAAE,QAAQ,GAAG,SAAS,CAAA;CAChC;AAED,MAAM,MAAM,oBAAoB,GAAG,wBAAwB,GACzD,CAAC,8BAA8B,GAAG,iCAAiC,CAAC,GACpE,OAAO,CAAC,IAAI,CAAC,gBAAgB,EAAE,OAAO,GAAG,MAAM,GAAG,cAAc,GAAG,iBAAiB,GAAG,mBAAmB,CAAC,CAAC,CAAA;AAS9G;;;GAGG;AACH,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,iBAAiB,CAAC,oBAAoB,CAAC,CA4OnF,CAAA"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { useRef, useCallback, useEffect } from 'react';
|
|
2
|
-
import useIsomorphicLayoutEffect from '../utils/useIsomorphicLayoutEffect.js';
|
|
1
|
+
import { useRef, useState, useCallback, useEffect } from 'react';
|
|
3
2
|
import { useFocusTrap } from '../hooks/useFocusTrap.js';
|
|
4
3
|
import { useFocusZone } from '../hooks/useFocusZone.js';
|
|
5
4
|
import { useId } from '../hooks/useId.js';
|
|
@@ -58,7 +57,18 @@ const AnchoredOverlay = ({
|
|
|
58
57
|
// Only use Popover API when both CSS anchor positioning is enabled AND renderAs is true
|
|
59
58
|
const shouldRenderAsPopover = cssAnchorPositioning && renderAs === 'popover';
|
|
60
59
|
const anchorRef = useProvidedRefOrCreate(externalAnchorRef);
|
|
60
|
+
// Track the current anchor DOM element in state so that effects depending on
|
|
61
|
+
// its identity (e.g. applying `anchor-name` for CSS anchor positioning) re-run
|
|
62
|
+
// when a consumer remounts/replaces the anchor element while keeping the same
|
|
63
|
+
// `anchorRef` object. Refs alone don't notify React when `.current` changes.
|
|
64
|
+
const [anchorElement, setAnchorElement] = useState(anchorRef.current);
|
|
65
|
+
// Detect when `anchorRef.current` has been mutated by a consumer (e.g. via
|
|
66
|
+
// their own `ref={anchorRef}`) without React's ref system notifying us.
|
|
67
|
+
if (anchorRef.current !== anchorElement) {
|
|
68
|
+
setAnchorElement(anchorRef.current);
|
|
69
|
+
}
|
|
61
70
|
const [overlayRef, updateOverlayRef] = useRenderForcingRef();
|
|
71
|
+
const [overlayElement, setOverlayElement] = useState(null);
|
|
62
72
|
const anchorId = useId(externalAnchorId);
|
|
63
73
|
const onClickOutside = useCallback(() => onClose === null || onClose === void 0 ? void 0 : onClose('click-outside'), [onClose]);
|
|
64
74
|
const onEscape = useCallback(() => onClose === null || onClose === void 0 ? void 0 : onClose('escape'), [onClose]);
|
|
@@ -129,31 +139,13 @@ const AnchoredOverlay = ({
|
|
|
129
139
|
const id = popoverId.replaceAll(':', '_'); // popoverId can contain colons which are invalid in CSS custom property names, so we replace them with underscores
|
|
130
140
|
|
|
131
141
|
useEffect(() => {
|
|
132
|
-
if (!cssAnchorPositioning || !
|
|
133
|
-
const anchor = anchorRef.current;
|
|
134
|
-
const overlay = overlayRef.current;
|
|
135
|
-
anchor.style.setProperty('anchor-name', `--anchored-overlay-anchor-${id}`);
|
|
136
|
-
return () => {
|
|
137
|
-
anchor.style.removeProperty('anchor-name');
|
|
138
|
-
if (overlay) {
|
|
139
|
-
overlay.style.removeProperty('position-anchor');
|
|
140
|
-
}
|
|
141
|
-
};
|
|
142
|
-
// eslint-disable-next-line react-hooks/refs
|
|
143
|
-
}, [cssAnchorPositioning, anchorRef, overlayRef, id, open]);
|
|
144
|
-
|
|
145
|
-
// Track the overlay element so we can re-run the effect when it changes.
|
|
146
|
-
// The overlay unmounts when closed, so each open creates a new DOM node -
|
|
147
|
-
// that needs showPopover() called.
|
|
148
|
-
// eslint-disable-next-line react-hooks/refs
|
|
149
|
-
const overlayElement = overlayRef.current;
|
|
150
|
-
useIsomorphicLayoutEffect(() => {
|
|
151
|
-
// Read ref inside effect to get the value after child refs are attached
|
|
142
|
+
if (!cssAnchorPositioning || !anchorElement) return;
|
|
152
143
|
const currentOverlay = overlayRef.current;
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
if (
|
|
144
|
+
|
|
145
|
+
// Link the anchor and the overlay (when present) via CSS anchor positioning.
|
|
146
|
+
anchorElement.style.setProperty('anchor-name', `--anchored-overlay-anchor-${id}`);
|
|
147
|
+
if (open && currentOverlay) {
|
|
148
|
+
currentOverlay.style.setProperty('position-anchor', `--anchored-overlay-anchor-${id}`);
|
|
157
149
|
const overlayWidth = width ? parseInt(widthMap[width]) : null;
|
|
158
150
|
const result = getDefaultPosition(anchorElement, overlayWidth);
|
|
159
151
|
currentOverlay.setAttribute('data-align', result.horizontal);
|
|
@@ -161,20 +153,25 @@ const AnchoredOverlay = ({
|
|
|
161
153
|
// Apply offset only when viewport is too narrow
|
|
162
154
|
const offset = result.horizontal === 'left' ? result.leftOffset : result.rightOffset;
|
|
163
155
|
currentOverlay.style.setProperty(`--anchored-overlay-anchor-offset-${result.horizontal}`, `${offset || 0}px`);
|
|
164
|
-
}
|
|
165
156
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
157
|
+
// Only call showPopover when shouldRenderAsPopover is enabled
|
|
158
|
+
if (shouldRenderAsPopover) {
|
|
159
|
+
try {
|
|
160
|
+
if (!currentOverlay.matches(':popover-open')) {
|
|
161
|
+
currentOverlay.showPopover();
|
|
162
|
+
}
|
|
163
|
+
} catch {
|
|
164
|
+
// Ignore if popover is already showing or not supported
|
|
171
165
|
}
|
|
172
|
-
} catch {
|
|
173
|
-
// Ignore if popover is already showing or not supported
|
|
174
166
|
}
|
|
175
167
|
}
|
|
176
|
-
|
|
177
|
-
|
|
168
|
+
return () => {
|
|
169
|
+
anchorElement.style.removeProperty('anchor-name');
|
|
170
|
+
if (currentOverlay) {
|
|
171
|
+
currentOverlay.style.removeProperty('position-anchor');
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
}, [cssAnchorPositioning, shouldRenderAsPopover, open, anchorElement, overlayElement, overlayRef, id, width]);
|
|
178
175
|
const showXIcon = onClose && variant.narrow === 'fullscreen' && displayCloseButton;
|
|
179
176
|
const XButtonAriaLabelledBy = closeButtonProps['aria-labelledby'];
|
|
180
177
|
const XButtonAriaLabel = closeButtonProps['aria-label'];
|
|
@@ -226,6 +223,7 @@ const AnchoredOverlay = ({
|
|
|
226
223
|
assignRef(overlayProps.ref, node);
|
|
227
224
|
}
|
|
228
225
|
updateOverlayRef(node);
|
|
226
|
+
setOverlayElement(node);
|
|
229
227
|
},
|
|
230
228
|
"data-anchor-position": cssAnchorPositioning,
|
|
231
229
|
"data-side": cssAnchorPositioning ? side : position_0 === null || position_0 === void 0 ? void 0 : position_0.anchorSide,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Checkbox.d.ts","sourceRoot":"","sources":["../../src/Checkbox/Checkbox.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"Checkbox.d.ts","sourceRoot":"","sources":["../../src/Checkbox/Checkbox.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,EAAiD,KAAK,mBAAmB,EAAoB,MAAM,OAAO,CAAA;AAExH,OAAO,KAAK,EAAC,oBAAoB,EAAC,MAAM,qCAAqC,CAAA;AAI7E,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,gBAAgB,CAAA;AAElD,MAAM,MAAM,aAAa,GAAG;IAC1B;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB;;OAEG;IACH,GAAG,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC,gBAAgB,CAAC,CAAA;IACvC;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB;;OAEG;IACH,gBAAgB,CAAC,EAAE,oBAAoB,CAAA;IACvC;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,GAAG,OAAO,CAAC,mBAAmB,CAAC,gBAAgB,CAAC,EAAE,OAAO,CAAC,CAAA;AAE3D;;GAEG;AACH,QAAA,MAAM,QAAQ,qGAgDb,CAAA;wBAK0B,cAAc,CAAC,OAAO,QAAQ,CAAC;AAA1D,wBAA0D"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { clsx } from 'clsx';
|
|
2
|
-
import React, { useContext } from 'react';
|
|
2
|
+
import React, { useContext, useEffect } from 'react';
|
|
3
|
+
import useIsomorphicLayoutEffect from '../utils/useIsomorphicLayoutEffect.js';
|
|
3
4
|
import { CheckboxGroupContext } from '../CheckboxGroup/CheckboxGroupContext.js';
|
|
4
5
|
import classes from './Checkbox.module.css.js';
|
|
5
6
|
import sharedClasses from './shared.module.css.js';
|
|
6
7
|
import { jsx } from 'react/jsx-runtime';
|
|
7
|
-
import {
|
|
8
|
+
import { useProvidedRefOrCreate } from '../hooks/useProvidedRefOrCreate.js';
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* An accessible, native checkbox component
|
|
@@ -23,43 +24,45 @@ const Checkbox = /*#__PURE__*/React.forwardRef(({
|
|
|
23
24
|
}, ref
|
|
24
25
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
25
26
|
) => {
|
|
26
|
-
const
|
|
27
|
-
if (node) {
|
|
28
|
-
node.indeterminate = indeterminate || false;
|
|
29
|
-
}
|
|
30
|
-
},
|
|
31
|
-
// `checked` is intentionally included even though it is not used inside
|
|
32
|
-
// the callback: browsers silently clear the `indeterminate` property
|
|
33
|
-
// whenever the checked state changes, so the callback must re-run to
|
|
34
|
-
// restore it. The exhaustive-deps rule flags this as an unnecessary
|
|
35
|
-
// dependency (because `checked` isn't referenced in the body), hence the
|
|
36
|
-
// suppression below.
|
|
37
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
38
|
-
[indeterminate, checked]);
|
|
39
|
-
const mergedRef = useMergedRefs(ref, setIndeterminate);
|
|
27
|
+
const checkboxRef = useProvidedRefOrCreate(ref);
|
|
40
28
|
const checkboxGroupContext = useContext(CheckboxGroupContext);
|
|
41
29
|
const handleOnChange = e => {
|
|
42
30
|
checkboxGroupContext.onChange && checkboxGroupContext.onChange(e);
|
|
43
31
|
onChange && onChange(e);
|
|
44
32
|
};
|
|
45
|
-
|
|
46
|
-
// aria-checked must reflect three states: mixed (indeterminate), true, or false.
|
|
47
|
-
const ariaChecked = indeterminate ? 'mixed' : checked ? 'true' : 'false';
|
|
48
33
|
const inputProps = {
|
|
49
34
|
type: 'checkbox',
|
|
50
35
|
disabled,
|
|
51
|
-
ref:
|
|
36
|
+
ref: checkboxRef,
|
|
52
37
|
checked: indeterminate ? false : checked,
|
|
53
38
|
defaultChecked,
|
|
54
39
|
required,
|
|
55
40
|
['aria-required']: required ? 'true' : 'false',
|
|
56
41
|
['aria-invalid']: validationStatus === 'error' ? 'true' : 'false',
|
|
57
|
-
['aria-checked']: ariaChecked,
|
|
58
42
|
onChange: handleOnChange,
|
|
59
43
|
value,
|
|
60
44
|
name: value,
|
|
61
45
|
...rest
|
|
62
46
|
};
|
|
47
|
+
useIsomorphicLayoutEffect(() => {
|
|
48
|
+
if (checkboxRef.current) {
|
|
49
|
+
checkboxRef.current.indeterminate = indeterminate || false;
|
|
50
|
+
}
|
|
51
|
+
}, [indeterminate, checked, checkboxRef]);
|
|
52
|
+
useEffect(() => {
|
|
53
|
+
const {
|
|
54
|
+
current: checkbox
|
|
55
|
+
} = checkboxRef;
|
|
56
|
+
if (!checkbox) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
if (indeterminate) {
|
|
60
|
+
checkbox.setAttribute('aria-checked', 'mixed');
|
|
61
|
+
} else {
|
|
62
|
+
checkbox.setAttribute('aria-checked', checkbox.checked ? 'true' : 'false');
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
// @ts-expect-error inputProp needs a non nullable ref
|
|
63
66
|
return /*#__PURE__*/jsx("input", {
|
|
64
67
|
...inputProps,
|
|
65
68
|
className: clsx(className, sharedClasses.Input, classes.Checkbox)
|
package/package.json
CHANGED