@primer/react 0.0.0-20260223192626 → 0.0.0-20260223201426

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.
@@ -1,6 +1,5 @@
1
1
  import { c } from 'react-compiler-runtime';
2
2
  import React, { startTransition } from 'react';
3
- import { canUseDOM } from '../utils/environment.js';
4
3
  import useIsomorphicLayoutEffect from '../utils/useIsomorphicLayoutEffect.js';
5
4
  import classes from './PageLayout.module.css.js';
6
5
 
@@ -28,9 +27,6 @@ const DEFAULT_MAX_WIDTH_DIFF = Number(classes.paneMaxWidthDiffDefault);
28
27
  */
29
28
  const DEFAULT_SIDEBAR_MAX_WIDTH_DIFF = Number(classes.sidebarMaxWidthDiffDefault);
30
29
 
31
- // Value for --pane-max-width-diff at/above the wide breakpoint.
32
- const WIDE_MAX_WIDTH_DIFF = Number(classes.paneMaxWidthDiffWide);
33
-
34
30
  // --pane-max-width-diff changes at this breakpoint in PageLayout.module.css.
35
31
  const DEFAULT_PANE_MAX_WIDTH_DIFF_BREAKPOINT = Number(classes.paneMaxWidthDiffBreakpoint);
36
32
  /**
@@ -71,13 +67,17 @@ const getDefaultPaneWidth = w => {
71
67
  };
72
68
 
73
69
  /**
74
- * Derives the --pane-max-width-diff value from viewport width alone.
75
- * Avoids the expensive getComputedStyle call that forces a synchronous layout recalc.
76
- * The CSS only defines two breakpoint-dependent values, so a simple width check is equivalent.
70
+ * Gets the max-width-diff CSS variable value from a pane element.
71
+ * For sidebars, reads --sidebar-max-width-diff (constant across viewports).
72
+ * For panes, reads --pane-max-width-diff (changes at 1280px breakpoint).
73
+ * Note: This calls getComputedStyle which forces layout - cache the result when possible.
77
74
  */
78
- function getMaxWidthDiffFromViewport() {
79
- if (!canUseDOM) return DEFAULT_MAX_WIDTH_DIFF;
80
- return window.innerWidth >= DEFAULT_PANE_MAX_WIDTH_DIFF_BREAKPOINT ? WIDE_MAX_WIDTH_DIFF : DEFAULT_MAX_WIDTH_DIFF;
75
+ function getPaneMaxWidthDiff(paneElement, isSidebar = false) {
76
+ const defaultValue = isSidebar ? DEFAULT_SIDEBAR_MAX_WIDTH_DIFF : DEFAULT_MAX_WIDTH_DIFF;
77
+ const cssVar = isSidebar ? '--sidebar-max-width-diff' : '--pane-max-width-diff';
78
+ if (!paneElement) return defaultValue;
79
+ const value = parseInt(getComputedStyle(paneElement).getPropertyValue(cssVar), 10);
80
+ return value > 0 ? value : defaultValue;
81
81
  }
82
82
 
83
83
  // Helper to update ARIA slider attributes via direct DOM manipulation
@@ -321,7 +321,7 @@ function usePaneWidth(t0) {
321
321
  const crossedBreakpoint = lastViewportWidth < DEFAULT_PANE_MAX_WIDTH_DIFF_BREAKPOINT && currentViewportWidth >= DEFAULT_PANE_MAX_WIDTH_DIFF_BREAKPOINT || lastViewportWidth >= DEFAULT_PANE_MAX_WIDTH_DIFF_BREAKPOINT && currentViewportWidth < DEFAULT_PANE_MAX_WIDTH_DIFF_BREAKPOINT;
322
322
  lastViewportWidth = currentViewportWidth;
323
323
  if (crossedBreakpoint) {
324
- maxWidthDiffRef.current = getMaxWidthDiffFromViewport();
324
+ maxWidthDiffRef.current = getPaneMaxWidthDiff(paneRef.current, constrainToViewport);
325
325
  }
326
326
  const actualMax = getMaxPaneWidthRef.current();
327
327
  (_paneRef$current = paneRef.current) === null || _paneRef$current === void 0 ? void 0 : _paneRef$current.style.setProperty("--pane-max-width", `${actualMax}px`);
@@ -342,7 +342,7 @@ function usePaneWidth(t0) {
342
342
  }
343
343
  });
344
344
  };
345
- maxWidthDiffRef.current = getMaxWidthDiffFromViewport();
345
+ maxWidthDiffRef.current = getPaneMaxWidthDiff(paneRef.current, constrainToViewport);
346
346
  const initialMax = getMaxPaneWidthRef.current();
347
347
  setMaxPaneWidth(initialMax);
348
348
  (_paneRef$current3 = paneRef.current) === null || _paneRef$current3 === void 0 ? void 0 : _paneRef$current3.style.setProperty("--pane-max-width", `${initialMax}px`);
@@ -453,4 +453,4 @@ function usePaneWidth(t0) {
453
453
  return t14;
454
454
  }
455
455
 
456
- export { ARROW_KEY_STEP, DEFAULT_MAX_WIDTH_DIFF, DEFAULT_SIDEBAR_MAX_WIDTH_DIFF, SSR_DEFAULT_MAX_WIDTH, defaultPaneWidth, getDefaultPaneWidth, getMaxWidthDiffFromViewport, isCustomWidthOptions, isPaneWidth, updateAriaValues, usePaneWidth };
456
+ export { ARROW_KEY_STEP, DEFAULT_MAX_WIDTH_DIFF, DEFAULT_SIDEBAR_MAX_WIDTH_DIFF, SSR_DEFAULT_MAX_WIDTH, defaultPaneWidth, getDefaultPaneWidth, getPaneMaxWidthDiff, isCustomWidthOptions, isPaneWidth, updateAriaValues, usePaneWidth };
@@ -1 +1 @@
1
- {"version":3,"file":"SelectPanel.d.ts","sourceRoot":"","sources":["../../src/SelectPanel/SelectPanel.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAsC,KAAK,SAAS,EAAC,MAAM,wBAAwB,CAAA;AAC1F,OAAO,KAAK,EAAE,EAA+E,KAAK,GAAG,EAAC,MAAM,OAAO,CAAA;AACnH,OAAO,KAAK,EAAC,oBAAoB,EAAC,MAAM,oBAAoB,CAAA;AAE5D,OAAO,KAAK,EAAC,iCAAiC,EAAC,MAAM,oCAAoC,CAAA;AACzF,OAAO,KAAK,EAAC,uBAAuB,EAAC,MAAM,uBAAuB,CAAA;AAGlE,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,YAAY,CAAA;AAE5C,OAAO,KAAK,EAAY,SAAS,EAAC,MAAM,IAAI,CAAA;AAiB5C,OAAO,KAAK,EAAC,WAAW,EAAE,eAAe,EAAC,MAAM,iBAAiB,CAAA;AAiCjE,UAAU,0BAA0B;IAClC,QAAQ,EAAE,SAAS,GAAG,SAAS,CAAA;IAC/B,gBAAgB,EAAE,CAAC,QAAQ,EAAE,SAAS,GAAG,SAAS,KAAK,IAAI,CAAA;CAC5D;AAED,UAAU,yBAAyB;IACjC,QAAQ,EAAE,SAAS,EAAE,CAAA;IACrB,gBAA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AW,EACX,GAAG,SAAS,EACb,EAAE,gBAAgB,GAAG,GAAG,CAAC,OAAO,CAsvBhC;AAED,QAAA,MAAM,eAAe,EAAE,KAAK,CAAC,EAAE,CAAC,WAAW,CAM1C,CAAA;AAED,QAAA,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,eAAe,GAAG,WAAW,CAM1D,CAAA;AAED,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;CAItB,CAAA"}
@@ -133,6 +133,8 @@ function Panel({
133
133
  wide: false
134
134
  }, false);
135
135
  const [selectedOnSort, setSelectedOnSort] = useState([]);
136
+ const [prevItems, setPrevItems] = useState([]);
137
+ const [prevOpen, setPrevOpen] = useState(open);
136
138
  const initialHeightRef = useRef(0);
137
139
  const initialScaleRef = useRef(1);
138
140
  const noticeRef = useRef(null);
@@ -204,19 +206,6 @@ function Panel({
204
206
  resetSort();
205
207
  }
206
208
  }, [loadingManagedInternally, externalOnFilterChange, setInternalFilterValue, dataLoadedOnce, safeSetTimeout, safeClearTimeout, items.length, resetSort]);
207
-
208
- // Pre-compute a Set of item IDs in the current filtered view for O(1) lookups
209
- const itemsInViewSet = useMemo(() => {
210
- const set = new Set();
211
- for (const item of items) {
212
- if (item.id !== undefined) {
213
- set.add(item.id);
214
- } else {
215
- set.add(item);
216
- }
217
- }
218
- return set;
219
- }, [items]);
220
209
  const handleSelectAllChange = useCallback(checked => {
221
210
  // Exit early if not in multi-select mode
222
211
  if (!isMultiSelectVariant(selected)) {
@@ -224,20 +213,13 @@ function Panel({
224
213
  }
225
214
  const multiSelectOnChange = onSelectedChange;
226
215
  const selectedArray = selected;
227
-
228
- // Use Set for O(1) lookup instead of O(n) items.some()
229
- const selectedItemsNotInFilteredView = selectedArray.filter(selectedItem => {
230
- if (selectedItem.id !== undefined) {
231
- return !itemsInViewSet.has(selectedItem.id);
232
- }
233
- return !itemsInViewSet.has(selectedItem);
234
- });
216
+ const selectedItemsNotInFilteredView = selectedArray.filter(selectedItem => !items.some(item => areItemsEqual(item, selectedItem)));
235
217
  if (checked) {
236
218
  multiSelectOnChange([...selectedItemsNotInFilteredView, ...items]);
237
219
  } else {
238
220
  multiSelectOnChange(selectedItemsNotInFilteredView);
239
221
  }
240
- }, [items, itemsInViewSet, onSelectedChange, selected]);
222
+ }, [items, onSelectedChange, selected]);
241
223
 
242
224
  // disable body scroll when the panel is open on narrow screens
243
225
  useEffect(() => {
@@ -403,29 +385,10 @@ function Panel({
403
385
  });
404
386
  };
405
387
  }, [placeholder, renderAnchor, selected]);
406
-
407
- // Pre-compute a Set of selected item IDs/references for O(1) lookups
408
- // This optimizes isItemCurrentlySelected from O(m) to O(1) per call
409
- const selectedItemsSet = useMemo(() => {
410
- const set = new Set();
411
- if (isMultiSelectVariant(selected)) {
412
- for (const item of selected) {
413
- if (item.id !== undefined) {
414
- set.add(item.id);
415
- } else {
416
- set.add(item);
417
- }
418
- }
419
- }
420
- return set;
421
- }, [selected]);
422
388
  const isItemCurrentlySelected = useCallback(item => {
423
- // For multi-select, use the pre-computed Set for O(1) lookup
389
+ // For multi-select, we just need to check if the item is in the selected array
424
390
  if (isMultiSelectVariant(selected)) {
425
- if (item.id !== undefined) {
426
- return selectedItemsSet.has(item.id);
427
- }
428
- return selectedItemsSet.has(item);
391
+ return doesItemsIncludeItem(selected, item);
429
392
  }
430
393
 
431
394
  // For single-select modal, there is an intermediate state when the user has selected
@@ -436,24 +399,8 @@ function Panel({
436
399
 
437
400
  // For single-select anchored, we just need to check if the item is the selected item
438
401
  return (selected === null || selected === void 0 ? void 0 : selected.id) !== undefined ? selected.id === item.id : selected === item;
439
- }, [selected, selectedItemsSet, intermediateSelected, isSingleSelectModal]);
402
+ }, [selected, intermediateSelected, isSingleSelectModal]);
440
403
  const itemsToRender = useMemo(() => {
441
- // Pre-compute a Set of selected item IDs/references for O(1) lookups during sorting
442
- // This avoids O(m * k) work per comparison in the sort function
443
- const selectedOnSortSet = new Set();
444
- for (const item of selectedOnSort) {
445
- if (item.id !== undefined) {
446
- selectedOnSortSet.add(item.id);
447
- } else {
448
- selectedOnSortSet.add(item);
449
- }
450
- }
451
- const isSelectedForSort = item => {
452
- if (item.id !== undefined) {
453
- return selectedOnSortSet.has(item.id);
454
- }
455
- return selectedOnSortSet.has(item);
456
- };
457
404
  return items.map(item => {
458
405
  return {
459
406
  ...item,
@@ -490,39 +437,42 @@ function Panel({
490
437
  };
491
438
  }).sort((itemA, itemB) => {
492
439
  if (shouldOrderSelectedFirst) {
493
- const itemASelected = isSelectedForSort(itemA);
494
- const itemBSelected = isSelectedForSort(itemB);
440
+ // itemA is selected (for sorting purposes) if an object in selectedOnSort matches every property of itemA, except for the selected property
441
+ const itemASelected = selectedOnSort.some(item => Object.entries(item).every(([key, value]) => {
442
+ if (key === 'selected') {
443
+ return true;
444
+ }
445
+ return itemA[key] === value;
446
+ }));
447
+
448
+ // itemB is selected (for sorting purposes) if an object in selectedOnSort matches every property of itemA, except for the selected property
449
+ const itemBSelected = selectedOnSort.some(item => Object.entries(item).every(([key, value]) => {
450
+ if (key === 'selected') {
451
+ return true;
452
+ }
453
+ return itemB[key] === value;
454
+ }));
495
455
 
496
456
  // order selected items first
497
- if (itemASelected && !itemBSelected) {
457
+ if (itemASelected > itemBSelected) {
498
458
  return -1;
499
- } else if (!itemASelected && itemBSelected) {
459
+ } else if (itemASelected < itemBSelected) {
500
460
  return 1;
501
461
  }
502
462
  }
503
463
  return 0;
504
464
  });
505
465
  }, [onClose, onSelectedChange, items, selected, isItemCurrentlySelected, isSingleSelectModal, intermediateSelected, shouldOrderSelectedFirst, selectedOnSort]);
506
-
507
- // Track previous items and reset sort when items first load
508
- const prevItemsRef = useRef(items);
509
- useEffect(() => {
510
- if (prevItemsRef.current !== items) {
511
- if (prevItemsRef.current.length === 0 && items.length > 0) {
512
- resetSort();
513
- }
514
- prevItemsRef.current = items;
515
- }
516
- }, [items, resetSort]);
517
-
518
- // Reset sort when panel opens
519
- const prevOpenRef = useRef(open);
520
- useEffect(() => {
521
- if (prevOpenRef.current !== open) {
466
+ if (prevItems !== items) {
467
+ setPrevItems(items);
468
+ if (prevItems.length === 0 && items.length > 0) {
522
469
  resetSort();
523
- prevOpenRef.current = open;
524
470
  }
525
- }, [open, resetSort]);
471
+ }
472
+ if (open !== prevOpen) {
473
+ setPrevOpen(open);
474
+ resetSort();
475
+ }
526
476
  const focusTrapSettings = {
527
477
  initialFocusRef: inputRef || undefined
528
478
  };
@@ -24,6 +24,17 @@ export type TooltipProps = React.PropsWithChildren<{
24
24
  * @default false
25
25
  */
26
26
  _privateDisableTooltip?: boolean;
27
+ /**
28
+ * Private API for use internally only. Renders the tooltip popover element before
29
+ * the trigger in the DOM instead of after it.
30
+ *
31
+ * This is used by ActionList items to ensure the tooltip's popover `<span>` does not
32
+ * sit between the ActionListContent and its adjacent SubGroup sibling, which would
33
+ * break CSS adjacent sibling (`+`) selectors used for expand/collapse.
34
+ *
35
+ * @default false
36
+ */
37
+ _privateRenderBeforeTrigger?: boolean;
27
38
  }> & React.HTMLAttributes<HTMLElement>;
28
39
  export declare const TooltipContext: React.Context<{
29
40
  tooltipId?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"Tooltip.d.ts","sourceRoot":"","sources":["../../src/TooltipV2/Tooltip.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAiD,KAAK,yBAAyB,EAAC,MAAM,OAAO,CAAA;AAS3G,OAAO,EAAoD,KAAK,mBAAmB,EAAC,MAAM,mBAAmB,CAAA;AAG7G,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,gBAAgB,CAAA;AAE9C,MAAM,MAAM,gBAAgB,GAAG,IAAI,GAAG,GAAG,GAAG,IAAI,GAAG,GAAG,GAAG,IAAI,GAAG,GAAG,GAAG,IAAI,GAAG,GAAG,CAAA;AAChF,MAAM,MAAM,YAAY,GAAG,KAAK,CAAC,iBAAiB,CAAC;IACjD,SAAS,CAAC,EAAE,gBAAgB,CAAA;IAC5B,IAAI,EAAE,MAAM,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;;;;;;;OAQG;IACH,sBAAsB,CAAC,EAAE,OAAO,CAAA;IAChC;;;;;;;;;OASG;IACH,2BAA2B,CAAC,EAAE,OAAO,CAAA;CACtC,CAAC,GACA,KAAK,CAAC,cAAc,CAAC,WAAW,CAAC,CAAA;AAiEnC,eAAO,MAAM,cAAc;gBAAoC,MAAM;EAAM,CAAA;AAE3E,eAAO,MAAM,OAAO,EAAE,yBAAyB,CAC7C,KAAK,CAAC,eAAe,CAAC,YAAY,CAAC,GAAG,KAAK,CAAC,aAAa,CAAC,WAAW,CAAC,CACvE,GACC,UAuSD,CAAA"}
@@ -86,6 +86,7 @@ const Tooltip = /*#__PURE__*/React.forwardRef(({
86
86
  keybindingHint,
87
87
  delay = 'short',
88
88
  _privateDisableTooltip = false,
89
+ _privateRenderBeforeTrigger = false,
89
90
  ...rest
90
91
  }, forwardedRef) => {
91
92
  const tooltipId = useId(id);
@@ -196,112 +197,124 @@ const Tooltip = /*#__PURE__*/React.forwardRef(({
196
197
  }, [isPopoverOpen]);
197
198
  const isMacOS = useIsMacOS();
198
199
  const hasAriaLabel = 'aria-label' in rest;
199
- return /*#__PURE__*/jsx(TooltipContext.Provider, {
200
- value: value,
201
- children: /*#__PURE__*/jsxs(Fragment, {
202
- children: [/*#__PURE__*/React.isValidElement(child) &&
203
- /*#__PURE__*/
204
- // eslint-disable-next-line react-hooks/refs
205
- React.cloneElement(child, {
206
- // @ts-expect-error it needs a non nullable ref
207
- ref: triggerRef,
208
- // If it is a type description, we use tooltip to describe the trigger
209
- 'aria-describedby': (() => {
210
- // If tooltip is not a description type, keep the original aria-describedby
211
- if (type !== 'description') {
212
- return child.props['aria-describedby'];
213
- }
200
+ const tooltipPopover = /*#__PURE__*/jsx("span", {
201
+ className: clsx(className, classes.Tooltip),
202
+ ref: tooltipElRef,
203
+ "data-direction": calculatedDirection,
204
+ ...rest,
205
+ // Only need tooltip role if the tooltip is a description for supplementary information
206
+ role: type === 'description' ? 'tooltip' : undefined
207
+ // stop AT from announcing the tooltip twice: when it is a label type it will be announced with "aria-labelledby",when it is a description type it will be announced with "aria-describedby"
208
+ ,
209
+ "aria-hidden": true
210
+ // mouse leave and enter on the tooltip itself is needed to keep the tooltip open when the mouse is over the tooltip
211
+ ,
212
+ onMouseEnter: openTooltip,
213
+ onMouseLeave: closeTooltip
214
+ // If there is an aria-label prop, always assign the ID to the parent so the accessible label can be overridden
215
+ ,
216
+ id: hasAriaLabel || !keybindingHint ? tooltipId : undefined,
217
+ children: keybindingHint ? /*#__PURE__*/jsxs(Fragment, {
218
+ children: [/*#__PURE__*/jsxs("span", {
219
+ id: hasAriaLabel ? undefined : tooltipId,
220
+ children: [text, /*#__PURE__*/jsxs(VisuallyHidden, {
221
+ children: ["(", getAccessibleKeybindingHintString(keybindingHint, isMacOS), ")"]
222
+ })]
223
+ }), /*#__PURE__*/jsx("span", {
224
+ className: clsx(classes.KeybindingHintContainer, text && classes.HasTextBefore),
225
+ "aria-hidden": true,
226
+ children: /*#__PURE__*/jsx(KeybindingHint, {
227
+ keys: keybindingHint,
228
+ format: "condensed",
229
+ variant: "onEmphasis",
230
+ size: "small"
231
+ })
232
+ })]
233
+ }) : text
234
+ });
235
+ const triggerElement = /*#__PURE__*/React.isValidElement(child) &&
236
+ /*#__PURE__*/
237
+ // eslint-disable-next-line react-hooks/refs
238
+ React.cloneElement(child, {
239
+ // @ts-expect-error it needs a non nullable ref
240
+ ref: triggerRef,
241
+ // If it is a type description, we use tooltip to describe the trigger
242
+ 'aria-describedby': (() => {
243
+ // If tooltip is not a description type, keep the original aria-describedby
244
+ if (type !== 'description') {
245
+ return child.props['aria-describedby'];
246
+ }
214
247
 
215
- // If tooltip is a description type, append our tooltipId
216
- const existingDescribedBy = child.props['aria-describedby'];
217
- if (existingDescribedBy) {
218
- return `${existingDescribedBy} ${tooltipId}`;
219
- }
248
+ // When the tooltip is disabled, don't add its ID to aria-describedby
249
+ // to avoid an empty string polluting the accessible description
250
+ if (_privateDisableTooltip) {
251
+ return child.props['aria-describedby'];
252
+ }
220
253
 
221
- // If no existing aria-describedby, use our tooltipId
222
- return tooltipId;
223
- })(),
224
- // If it is a label type, we use tooltip to label the trigger
225
- 'aria-labelledby': type === 'label' ? tooltipId : child.props['aria-labelledby'],
226
- onBlur: event => {
227
- var _child$props$onBlur, _child$props;
228
- closeTooltip();
229
- (_child$props$onBlur = (_child$props = child.props).onBlur) === null || _child$props$onBlur === void 0 ? void 0 : _child$props$onBlur.call(_child$props, event);
230
- },
231
- onTouchEnd: event => {
232
- var _child$props$onTouchE, _child$props2;
233
- (_child$props$onTouchE = (_child$props2 = child.props).onTouchEnd) === null || _child$props$onTouchE === void 0 ? void 0 : _child$props$onTouchE.call(_child$props2, event);
254
+ // If tooltip is a description type, append our tooltipId
255
+ const existingDescribedBy = child.props['aria-describedby'];
256
+ if (existingDescribedBy) {
257
+ return `${existingDescribedBy} ${tooltipId}`;
258
+ }
234
259
 
235
- // Hide tooltips on tap to essentially disable them on touch devices;
236
- // this still allows viewing the tooltip on tap-and-hold
237
- safeSetTimeout(() => closeTooltip(), 10);
238
- },
239
- onFocus: event => {
240
- var _child$props$onFocus, _child$props3;
241
- // only show tooltip on :focus-visible, not on :focus
242
- try {
243
- if (!event.target.matches(':focus-visible')) return;
244
- } catch (_error) {
245
- // jsdom (jest) does not support `:focus-visible` yet and would throw an error
246
- // https://github.com/jsdom/jsdom/issues/3426
247
- }
248
- openTooltip();
249
- (_child$props$onFocus = (_child$props3 = child.props).onFocus) === null || _child$props$onFocus === void 0 ? void 0 : _child$props$onFocus.call(_child$props3, event);
250
- },
251
- onMouseOverCapture: event => {
252
- const delayTime = delayTimeMap[delay] || 50;
253
- // We use a `capture` event to ensure this is called first before
254
- // events that might cancel the opening timeout (like `onTouchEnd`)
255
- // show tooltip after mouse has been hovering for the specified delay time
256
- // (prevent showing tooltip when mouse is just passing through)
257
- openTimeoutRef.current = safeSetTimeout(() => {
258
- var _child$props$onMouseE, _child$props4;
259
- // if the mouse is already moved out, do not show the tooltip
260
- if (!openTimeoutRef.current) return;
261
- openTooltip();
262
- (_child$props$onMouseE = (_child$props4 = child.props).onMouseEnter) === null || _child$props$onMouseE === void 0 ? void 0 : _child$props$onMouseE.call(_child$props4, event);
263
- }, delayTime);
264
- },
265
- onMouseLeave: event => {
266
- var _child$props$onMouseL, _child$props5;
267
- closeTooltip();
268
- (_child$props$onMouseL = (_child$props5 = child.props).onMouseLeave) === null || _child$props$onMouseL === void 0 ? void 0 : _child$props$onMouseL.call(_child$props5, event);
269
- }
270
- }), /*#__PURE__*/jsx("span", {
271
- className: clsx(className, classes.Tooltip),
272
- ref: tooltipElRef,
273
- "data-direction": calculatedDirection,
274
- ...rest,
275
- // Only need tooltip role if the tooltip is a description for supplementary information
276
- role: type === 'description' ? 'tooltip' : undefined
277
- // stop AT from announcing the tooltip twice: when it is a label type it will be announced with "aria-labelledby",when it is a description type it will be announced with "aria-describedby"
278
- ,
279
- "aria-hidden": true
280
- // mouse leave and enter on the tooltip itself is needed to keep the tooltip open when the mouse is over the tooltip
281
- ,
282
- onMouseEnter: openTooltip,
283
- onMouseLeave: closeTooltip
284
- // If there is an aria-label prop, always assign the ID to the parent so the accessible label can be overridden
285
- ,
286
- id: hasAriaLabel || !keybindingHint ? tooltipId : undefined,
287
- children: keybindingHint ? /*#__PURE__*/jsxs(Fragment, {
288
- children: [/*#__PURE__*/jsxs("span", {
289
- id: hasAriaLabel ? undefined : tooltipId,
290
- children: [text, /*#__PURE__*/jsxs(VisuallyHidden, {
291
- children: ["(", getAccessibleKeybindingHintString(keybindingHint, isMacOS), ")"]
292
- })]
293
- }), /*#__PURE__*/jsx("span", {
294
- className: clsx(classes.KeybindingHintContainer, text && classes.HasTextBefore),
295
- "aria-hidden": true,
296
- children: /*#__PURE__*/jsx(KeybindingHint, {
297
- keys: keybindingHint,
298
- format: "condensed",
299
- variant: "onEmphasis",
300
- size: "small"
301
- })
302
- })]
303
- }) : text
304
- })]
260
+ // If no existing aria-describedby, use our tooltipId
261
+ return tooltipId;
262
+ })(),
263
+ // If it is a label type, we use tooltip to label the trigger
264
+ 'aria-labelledby': type === 'label' && !_privateDisableTooltip ? tooltipId : child.props['aria-labelledby'],
265
+ onBlur: event => {
266
+ var _child$props$onBlur, _child$props;
267
+ closeTooltip();
268
+ (_child$props$onBlur = (_child$props = child.props).onBlur) === null || _child$props$onBlur === void 0 ? void 0 : _child$props$onBlur.call(_child$props, event);
269
+ },
270
+ onTouchEnd: event => {
271
+ var _child$props$onTouchE, _child$props2;
272
+ (_child$props$onTouchE = (_child$props2 = child.props).onTouchEnd) === null || _child$props$onTouchE === void 0 ? void 0 : _child$props$onTouchE.call(_child$props2, event);
273
+
274
+ // Hide tooltips on tap to essentially disable them on touch devices;
275
+ // this still allows viewing the tooltip on tap-and-hold
276
+ safeSetTimeout(() => closeTooltip(), 10);
277
+ },
278
+ onFocus: event => {
279
+ var _child$props$onFocus, _child$props3;
280
+ // only show tooltip on :focus-visible, not on :focus
281
+ try {
282
+ if (!event.target.matches(':focus-visible')) return;
283
+ } catch (_error) {
284
+ // jsdom (jest) does not support `:focus-visible` yet and would throw an error
285
+ // https://github.com/jsdom/jsdom/issues/3426
286
+ }
287
+ openTooltip();
288
+ (_child$props$onFocus = (_child$props3 = child.props).onFocus) === null || _child$props$onFocus === void 0 ? void 0 : _child$props$onFocus.call(_child$props3, event);
289
+ },
290
+ onMouseOverCapture: event => {
291
+ const delayTime = delayTimeMap[delay] || 50;
292
+ // We use a `capture` event to ensure this is called first before
293
+ // events that might cancel the opening timeout (like `onTouchEnd`)
294
+ // show tooltip after mouse has been hovering for the specified delay time
295
+ // (prevent showing tooltip when mouse is just passing through)
296
+ openTimeoutRef.current = safeSetTimeout(() => {
297
+ var _child$props$onMouseE, _child$props4;
298
+ // if the mouse is already moved out, do not show the tooltip
299
+ if (!openTimeoutRef.current) return;
300
+ openTooltip();
301
+ (_child$props$onMouseE = (_child$props4 = child.props).onMouseEnter) === null || _child$props$onMouseE === void 0 ? void 0 : _child$props$onMouseE.call(_child$props4, event);
302
+ }, delayTime);
303
+ },
304
+ onMouseLeave: event => {
305
+ var _child$props$onMouseL, _child$props5;
306
+ closeTooltip();
307
+ (_child$props$onMouseL = (_child$props5 = child.props).onMouseLeave) === null || _child$props$onMouseL === void 0 ? void 0 : _child$props$onMouseL.call(_child$props5, event);
308
+ }
309
+ });
310
+ return /*#__PURE__*/jsx(TooltipContext.Provider, {
311
+ value: value,
312
+ children: /*#__PURE__*/jsx(Fragment, {
313
+ children: _privateRenderBeforeTrigger ? /*#__PURE__*/jsxs(Fragment, {
314
+ children: [tooltipPopover, triggerElement]
315
+ }) : /*#__PURE__*/jsxs(Fragment, {
316
+ children: [triggerElement, tooltipPopover]
317
+ })
305
318
  })
306
319
  });
307
320
  });
@@ -3244,8 +3244,8 @@
3244
3244
  "code": "() => {\n const [tokens, setTokens] = useState([...mockTokens])\n const onTokenRemove = (tokenId: string | number) => {\n setTokens(\n tokens.filter((token: { id: string | number }) => token.id !== tokenId),\n )\n }\n return (\n <div className={classes.GridContainer}>\n <FormControl>\n <FormControl.Label id=\"form-label\">\n TextInputWithTokens\n </FormControl.Label>\n <TextInputWithTokens onTokenRemove={onTokenRemove} tokens={tokens} />\n </FormControl>\n <FormControl>\n <FormControl.Label id=\"autocomplete-label\">\n Autocomplete\n </FormControl.Label>\n <Autocomplete>\n <Autocomplete.Input block />\n <Autocomplete.Overlay>\n <Autocomplete.Menu\n aria-labelledby=\"autocomplete-label\"\n items={[\n {\n text: 'css',\n id: '0',\n },\n {\n text: 'css-in-js',\n id: '1',\n },\n {\n text: 'styled-system',\n id: '2',\n },\n {\n text: 'javascript',\n id: '3',\n },\n {\n text: 'typescript',\n id: '4',\n },\n {\n text: 'react',\n id: '5',\n },\n {\n text: 'design-systems',\n id: '6',\n },\n ]}\n selectedItemIds={[]}\n />\n </Autocomplete.Overlay>\n </Autocomplete>\n </FormControl>\n <FormControl>\n <FormControl.Label>Select</FormControl.Label>\n <Select>\n <Select.Option value=\"figma\">Figma</Select.Option>\n <Select.Option value=\"css\">Primer CSS</Select.Option>\n <Select.Option value=\"prc\">Primer React components</Select.Option>\n <Select.Option value=\"pvc\">Primer ViewComponents</Select.Option>\n </Select>\n </FormControl>\n <FormControl>\n <FormControl.Label>Textarea</FormControl.Label>\n <Textarea />\n </FormControl>\n </div>\n )\n}"
3245
3245
  },
3246
3246
  {
3247
- "id": "components-formcontrol-features--with-custom-input",
3248
- "code": "() => {\n const [value, setValue] = React.useState('mona lisa')\n const [validationResult, setValidationResult] = React.useState('')\n const doesValueContainSpaces = (inputValue: string) => /\\s/g.test(inputValue)\n const handleInputChange = (e: {\n currentTarget: {\n value: React.SetStateAction<string>\n }\n }) => {\n setValue(e.currentTarget.value)\n }\n React.useEffect(() => {\n if (doesValueContainSpaces(value)) {\n setValidationResult('noSpaces')\n } else if (value) {\n setValidationResult('validName')\n }\n }, [value])\n return (\n <div className={classes.GridContainer}>\n <FormControl>\n <FormControl.Label htmlFor=\"custom-input\">\n GitHub handle\n </FormControl.Label>\n <CustomTextInput\n id=\"custom-input\"\n aria-describedby=\"custom-input-validation custom-input-caption\"\n aria-invalid={validationResult === 'noSpaces'}\n onChange={handleInputChange}\n />\n {validationResult === 'noSpaces' && (\n <FormControl.Validation id=\"custom-input-validation\" variant=\"error\">\n GitHub handles cannot contain spaces\n </FormControl.Validation>\n )}\n {validationResult === 'validName' && (\n <FormControl.Validation\n id=\"custom-input-validation\"\n variant=\"success\"\n >\n Valid name\n </FormControl.Validation>\n )}\n <FormControl.Caption id=\"custom-input-caption\">\n With or without &quot;@&quot;. For example &quot;monalisa&quot; or\n &quot;@monalisa&quot;\n </FormControl.Caption>\n </FormControl>\n\n <CheckboxGroup>\n <CheckboxGroup.Label>Checkboxes</CheckboxGroup.Label>\n <FormControl layout=\"horizontal\">\n <CustomCheckboxInput\n id=\"custom-checkbox-one\"\n aria-describedby=\"custom-checkbox-one-caption\"\n value=\"checkOne\"\n />\n <FormControl.Label htmlFor=\"custom-checkbox-one\">\n Checkbox one\n </FormControl.Label>\n <FormControl.Caption id=\"custom-checkbox-one-caption\">\n Hint text for checkbox one\n </FormControl.Caption>\n </FormControl>\n <FormControl layout=\"horizontal\">\n <CustomCheckboxInput\n id=\"custom-checkbox-two\"\n aria-describedby=\"custom-checkbox-two-caption\"\n value=\"checkTwo\"\n />\n <FormControl.Label htmlFor=\"custom-checkbox-two\">\n Checkbox two\n </FormControl.Label>\n <FormControl.Caption id=\"custom-checkbox-two-caption\">\n Hint text for checkbox two\n </FormControl.Caption>\n </FormControl>\n </CheckboxGroup>\n </div>\n )\n}"
3247
+ "id": "components-formcontrol-features--form-control-with-custom-input",
3248
+ "code": "() => {\n const [value, setValue] = React.useState('mona lisa')\n const [validationResult, setValidationResult] = React.useState('')\n const doesValueContainSpaces = (inputValue: string) => /\\s/g.test(inputValue)\n const handleInputChange = (e: {\n currentTarget: {\n value: React.SetStateAction<string>\n }\n }) => {\n setValue(e.currentTarget.value)\n }\n React.useEffect(() => {\n if (doesValueContainSpaces(value)) {\n setValidationResult('noSpaces')\n } else if (value) {\n setValidationResult('validName')\n }\n }, [value])\n return (\n <div className={classes.GridContainer}>\n <FormControl>\n <FormControl.Label htmlFor=\"custom-input\">\n GitHub handle\n </FormControl.Label>\n <CustomTextInput\n id=\"custom-input\"\n aria-describedby=\"custom-input-caption custom-input-validation\"\n aria-invalid={validationResult === 'noSpaces'}\n onChange={handleInputChange}\n />\n {validationResult === 'noSpaces' && (\n <FormControl.Validation id=\"custom-input-validation\" variant=\"error\">\n GitHub handles cannot contain spaces\n </FormControl.Validation>\n )}\n {validationResult === 'validName' && (\n <FormControl.Validation\n id=\"custom-input-validation\"\n variant=\"success\"\n >\n Valid name\n </FormControl.Validation>\n )}\n <FormControl.Caption id=\"custom-input-caption\">\n With or without &quot;@&quot;. For example &quot;monalisa&quot; or\n &quot;@monalisa&quot;\n </FormControl.Caption>\n </FormControl>\n\n <CheckboxGroup>\n <CheckboxGroup.Label>Checkboxes</CheckboxGroup.Label>\n <FormControl layout=\"horizontal\">\n <CustomCheckboxInput\n id=\"custom-checkbox-one\"\n aria-describedby=\"custom-checkbox-one-caption\"\n value=\"checkOne\"\n />\n <FormControl.Label htmlFor=\"custom-checkbox-one\">\n Checkbox one\n </FormControl.Label>\n <FormControl.Caption id=\"custom-checkbox-one-caption\">\n Hint text for checkbox one\n </FormControl.Caption>\n </FormControl>\n <FormControl layout=\"horizontal\">\n <CustomCheckboxInput\n id=\"custom-checkbox-two\"\n aria-describedby=\"custom-checkbox-two-caption\"\n value=\"checkTwo\"\n />\n <FormControl.Label htmlFor=\"custom-checkbox-two\">\n Checkbox two\n </FormControl.Label>\n <FormControl.Caption id=\"custom-checkbox-two-caption\">\n Hint text for checkbox two\n </FormControl.Caption>\n </FormControl>\n </CheckboxGroup>\n </div>\n )\n}"
3249
3249
  },
3250
3250
  {
3251
3251
  "id": "components-formcontrol-features--with-checkbox-and-radio-inputs",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@primer/react",
3
3
  "type": "module",
4
- "version": "0.0.0-20260223192626",
4
+ "version": "0.0.0-20260223201426",
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",
@@ -170,7 +170,7 @@
170
170
  "react-is": "18.3.1",
171
171
  "recast": "0.23.7",
172
172
  "rimraf": "5.0.5",
173
- "rollup": "4.59.0",
173
+ "rollup": "4.56.0",
174
174
  "rollup-plugin-import-css": "^0.0.0",
175
175
  "storybook": "^10.1.11",
176
176
  "terser": "5.36.0",