@deque/cauldron-react 7.4.0 → 7.5.0-canary.b12b7518

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.
@@ -13,7 +13,14 @@ interface ActionMenuListProps {
13
13
  * (`<li>`) in the documented `TopBar`/`MenuBar` nesting — so the `ref` and
14
14
  * spread handlers type against the actual element without casts.
15
15
  */
16
- export type ActionMenuTriggerProps<E extends HTMLElement = HTMLButtonElement> = Pick<React.HTMLAttributes<E>, 'children' | 'id' | 'onClick' | 'onKeyDown' | 'aria-expanded' | 'aria-haspopup' | 'aria-controls'> & {
16
+ export type ActionMenuTriggerProps<E extends HTMLElement = HTMLButtonElement> = Pick<React.HTMLAttributes<E>, 'children' | 'id' | 'onClick' | 'onKeyDown' | 'aria-labelledby' | 'aria-expanded' | 'aria-haspopup' | 'aria-controls'> & {
17
+ /**
18
+ * Id for the element wrapping the trigger's visible label, e.g.
19
+ * `<span id={labelId}>Menu</span>`. Only provided with `renderInTrigger`,
20
+ * where the trigger contains the menu and would otherwise be named after
21
+ * every item in it. Not a DOM attribute — destructure it out of the props.
22
+ */
23
+ labelId?: string;
17
24
  ref: React.RefObject<E | null>;
18
25
  };
19
26
  export type ActionMenuTriggerFunction<E extends HTMLElement = HTMLButtonElement> = (props: ActionMenuTriggerProps<E>, open: boolean) => React.ReactElement;
package/lib/index.js CHANGED
@@ -1659,7 +1659,11 @@ var DialogContent = function (_a) {
1659
1659
  'text--align-left': align === 'left',
1660
1660
  'text--align-center': align === 'center',
1661
1661
  'text--align-right': align === 'right'
1662
- }), tabIndex: (context === null || context === void 0 ? void 0 : context.scrollable) ? -1 : undefined }, other), children));
1662
+ }),
1663
+ // A keyboard user can only scroll this region if it is tabbable (WCAG
1664
+ // 2.1.1). The rule allows that on role="tabpanel" only. See #680.
1665
+ // eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex
1666
+ tabIndex: (context === null || context === void 0 ? void 0 : context.scrollable) ? 0 : undefined }, other), children));
1663
1667
  };
1664
1668
  DialogContent.displayName = 'DialogContent';
1665
1669
  var DialogFooter = function (_a) {
@@ -5341,8 +5345,9 @@ var ActionMenuComponent = React.forwardRef(function (_a, ref) {
5341
5345
  var actionMenuRef = useSharedRef(ref);
5342
5346
  var _f = actionMenuList.props, actionListRef = _f.ref, actionListOnAction = _f.onAction;
5343
5347
  var actionMenuListRef = useSharedRef(actionListRef !== null && actionListRef !== void 0 ? actionListRef : null);
5344
- var _g = tslib.__read(nextId.useId(1, 'menu-trigger'), 1), triggerId = _g[0];
5345
- var _h = tslib.__read(nextId.useId(1, 'menu'), 1), menuId = _h[0];
5348
+ var _g = tslib.__read(nextId.useId(1, 'menu-label'), 1), labelId = _g[0];
5349
+ var _h = tslib.__read(nextId.useId(1, 'menu-trigger'), 1), triggerId = _h[0];
5350
+ var _j = tslib.__read(nextId.useId(1, 'menu'), 1), menuId = _j[0];
5346
5351
  var handleTriggerClick = React.useCallback(function (event) {
5347
5352
  // istanbul ignore else
5348
5353
  if (!event.defaultPrevented) {
@@ -5411,18 +5416,41 @@ var ActionMenuComponent = React.forwardRef(function (_a, ref) {
5411
5416
  (_b = triggerRef.current) === null || _b === void 0 ? void 0 : _b.focus();
5412
5417
  }
5413
5418
  }, [open]);
5419
+ // Triggers predating `labelId` render no label element. Since
5420
+ // `aria-labelledby` is not chained, naming the menu with such a trigger
5421
+ // would resolve back to the menu's own items, so it is left unnamed.
5422
+ var _k = tslib.__read(React.useState(false), 2), hasLabelElement = _k[0], setHasLabelElement = _k[1];
5423
+ React.useEffect(function () {
5424
+ setHasLabelElement(renderInTrigger ? !!document.getElementById(labelId) : false);
5425
+ }, [renderInTrigger, labelId]);
5426
+ React.useEffect(function () {
5427
+ // istanbul ignore next
5428
+ if (renderInTrigger &&
5429
+ !document.getElementById(labelId) &&
5430
+ process.env.NODE_ENV !== 'production') {
5431
+ console.warn("renderInTrigger should render id=\"".concat(labelId, "\" on the element wrapping the trigger's visible label, otherwise the trigger and the menu are named after the entire submenu."));
5432
+ }
5433
+ }, [renderInTrigger, labelId]);
5434
+ var labelledBy = triggerId;
5435
+ if (renderInTrigger) {
5436
+ labelledBy = hasLabelElement ? labelId : undefined;
5437
+ }
5414
5438
  var hidden = renderInTrigger && !open;
5415
5439
  var overlay = (React__default["default"].createElement(AnchoredOverlay, tslib.__assign({ ref: actionMenuRef, role: "presentation", className: classNames__default["default"]('ActionMenu', className), open: open, onOpenChange: setOpen, target: triggerRef, placement: placement, offset: 4, portal: portal, style: tslib.__assign({ display: !open ? 'none' : undefined }, style), "aria-hidden": hidden, onBlur: handleOverlayBlur }, props), React__default["default"].cloneElement(actionMenuList, {
5416
5440
  ref: actionMenuListRef,
5417
5441
  id: menuId,
5418
5442
  role: 'menu',
5419
5443
  onAction: handleAction,
5420
- 'aria-labelledby': triggerId,
5444
+ // aria-labelledby is not chained, so pointing at a trigger that
5445
+ // contains this menu would resolve to the menu's own items.
5446
+ 'aria-labelledby': labelledBy,
5421
5447
  focusStrategy: focusStrategy,
5422
5448
  focusDisabledOptions: true,
5423
5449
  hidden: hidden
5424
5450
  })));
5425
- var triggerProps = React.useMemo(function () {
5451
+ // Spread onto a prerendered trigger element below, so this must stay
5452
+ // DOM-safe: no labelId.
5453
+ var baseTriggerProps = React.useMemo(function () {
5426
5454
  return {
5427
5455
  ref: triggerRef,
5428
5456
  id: triggerId,
@@ -5432,7 +5460,7 @@ var ActionMenuComponent = React.forwardRef(function (_a, ref) {
5432
5460
  'aria-haspopup': 'menu',
5433
5461
  'aria-controls': menuId
5434
5462
  };
5435
- }, [handleTriggerClick, open, menuId]);
5463
+ }, [handleTriggerClick, handleTriggerKeyDown, open, triggerId, menuId]);
5436
5464
  if (renderInTrigger) {
5437
5465
  // istanbul ignore next
5438
5466
  if (portal && process.env.NODE_ENV !== 'production') {
@@ -5442,11 +5470,14 @@ var ActionMenuComponent = React.forwardRef(function (_a, ref) {
5442
5470
  if (React__default["default"].isValidElement(trigger)) {
5443
5471
  console.warn('renderInTrigger requires the use of a trigger function, rather than a prerendered trigger ReactElement.');
5444
5472
  }
5445
- triggerProps.children = overlay;
5446
5473
  }
5474
+ // Derived rather than mutated onto the memoized object, so that toggling
5475
+ // `renderInTrigger` off cannot leave a stale `children` behind.
5476
+ var triggerProps = renderInTrigger
5477
+ ? tslib.__assign(tslib.__assign({}, baseTriggerProps), { children: overlay, 'aria-labelledby': labelledBy }) : baseTriggerProps;
5447
5478
  var actionMenuTrigger = React__default["default"].isValidElement(trigger)
5448
5479
  ? React__default["default"].cloneElement(trigger, triggerProps)
5449
- : trigger(tslib.__assign(tslib.__assign({}, triggerProps), { children: overlay }), open);
5480
+ : trigger(tslib.__assign(tslib.__assign(tslib.__assign({}, triggerProps), { children: overlay }), (renderInTrigger && { labelId: labelId })), open);
5450
5481
  return (React__default["default"].createElement(React__default["default"].Fragment, null,
5451
5482
  React__default["default"].createElement(ClickOutsideListener$1, { onClickOutside: handleClickOutside, mouseEvent: open ? undefined : false, touchEvent: open ? undefined : false, target: triggerProps.ref }, actionMenuTrigger),
5452
5483
  renderInTrigger ? null : overlay));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deque/cauldron-react",
3
- "version": "7.4.0",
3
+ "version": "7.5.0-canary.b12b7518",
4
4
  "license": "MPL-2.0",
5
5
  "description": "Fully accessible react components library for Deque Cauldron",
6
6
  "homepage": "https://cauldron.dequelabs.com/",