@primer/react 0.0.0-20260424092845 → 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-20260424092845
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) [`b3f06f1`](https://github.com/primer/react/commit/b3f06f1e2c91125c7b6b035bd019f534219d358f) Thanks [@TylerJDev](https://github.com/TylerJDev)! - AnchoredOverlay: (Behind feature flag) Make popover API usage opt-in
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
- - [#7765](https://github.com/primer/react/pull/7765) [`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,EAAiC,KAAK,GAAG,EAAC,MAAM,OAAO,CAAA;AAE9D,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,iCAAiC;IACzC;;;OAGG;IACH,YAAY,EAAE,IAAI,CAAA;IAElB;;;OAGG;IACH,SAAS,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,CAAA;IAC9C;;OAEG;IACH,QA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AQ,EAAE,cAAc,CAAA;KAAC,KAAK,IAAI,CAAA;IACnE;;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 || !anchorRef.current) return;
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
- if (!cssAnchorPositioning || !open || !currentOverlay) return;
154
- currentOverlay.style.setProperty('position-anchor', `--anchored-overlay-anchor-${id}`);
155
- const anchorElement = anchorRef.current;
156
- if (anchorElement) {
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
- // Only call showPopover when renderAs is enabled
167
- if (shouldRenderAsPopover) {
168
- try {
169
- if (!currentOverlay.matches(':popover-open')) {
170
- currentOverlay.showPopover();
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
- // eslint-disable-next-line react-hooks/refs
177
- }, [cssAnchorPositioning, shouldRenderAsPopover, open, overlayElement, id, overlayRef, anchorRef, width]);
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,EAAsC,KAAK,mBAAmB,EAAoB,MAAM,OAAO,CAAA;AAC7G,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,qGA0Cb,CAAA;wBAK0B,cAAc,CAAC,OAAO,QAAQ,CAAC;AAA1D,wBAA0D"}
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 { useMergedRefs } from '../hooks/useMergedRefs.js';
8
+ import { useProvidedRefOrCreate } from '../hooks/useProvidedRefOrCreate.js';
8
9
 
9
10
  /**
10
11
  * An accessible, native checkbox component
@@ -23,16 +24,7 @@ const Checkbox = /*#__PURE__*/React.forwardRef(({
23
24
  }, ref
24
25
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
25
26
  ) => {
26
- const setIndeterminate = React.useCallback(node => {
27
- if (node) {
28
- node.indeterminate = indeterminate || false;
29
- }
30
- },
31
- // `checked` is intentionally included: browsers clear the indeterminate state
32
- // when checked changes, so we need the callback to re-run to restore it.
33
- // eslint-disable-next-line react-hooks/exhaustive-deps
34
- [indeterminate, checked]);
35
- const mergedRef = useMergedRefs(ref, setIndeterminate);
27
+ const checkboxRef = useProvidedRefOrCreate(ref);
36
28
  const checkboxGroupContext = useContext(CheckboxGroupContext);
37
29
  const handleOnChange = e => {
38
30
  checkboxGroupContext.onChange && checkboxGroupContext.onChange(e);
@@ -41,18 +33,36 @@ const Checkbox = /*#__PURE__*/React.forwardRef(({
41
33
  const inputProps = {
42
34
  type: 'checkbox',
43
35
  disabled,
44
- ref: mergedRef,
36
+ ref: checkboxRef,
45
37
  checked: indeterminate ? false : checked,
46
38
  defaultChecked,
47
39
  required,
48
40
  ['aria-required']: required ? 'true' : 'false',
49
41
  ['aria-invalid']: validationStatus === 'error' ? 'true' : 'false',
50
- ['aria-checked']: indeterminate ? 'mixed' : checked ? 'true' : 'false',
51
42
  onChange: handleOnChange,
52
43
  value,
53
44
  name: value,
54
45
  ...rest
55
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
56
66
  return /*#__PURE__*/jsx("input", {
57
67
  ...inputProps,
58
68
  className: clsx(className, sharedClasses.Input, classes.Checkbox)
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@primer/react",
3
3
  "type": "module",
4
- "version": "0.0.0-20260424092845",
4
+ "version": "0.0.0-20260424151259",
5
5
  "description": "An implementation of GitHub's Primer Design System using React",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.js",