@moda/om 21.6.11 → 21.7.0

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/dist/index.cjs.js CHANGED
@@ -12351,7 +12351,7 @@ var PasswordInput = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
12351
12351
  });
12352
12352
  PasswordInput.displayName = 'PasswordInput';
12353
12353
 
12354
- var _excluded$9 = ["className", "children", "content", "open", "anchor", "zIndex", "autoPreview", "smoothTransitioning"];
12354
+ var _excluded$9 = ["className", "children", "content", "open", "anchor", "zIndex", "autoPreview", "smoothTransitioning", "role", "aria-label", "aria-labelledby", "popoverId", "openOnFocus", "closeOnEscape", "onClose", "autoFocus"];
12355
12355
  var POPOVER_MOUSEOUT_DELAY_MS = 200;
12356
12356
  var THREE_QUARTER_SECOND_DELAY = 750;
12357
12357
  var ONE_SECOND_DELAY = 1000;
@@ -12377,6 +12377,17 @@ var Popover = function Popover(_ref) {
12377
12377
  autoPreview = _ref$autoPreview === void 0 ? false : _ref$autoPreview,
12378
12378
  _ref$smoothTransition = _ref.smoothTransitioning,
12379
12379
  smoothTransitioning = _ref$smoothTransition === void 0 ? false : _ref$smoothTransition,
12380
+ role = _ref.role,
12381
+ ariaLabel = _ref['aria-label'],
12382
+ ariaLabelledby = _ref['aria-labelledby'],
12383
+ popoverId = _ref.popoverId,
12384
+ _ref$openOnFocus = _ref.openOnFocus,
12385
+ openOnFocus = _ref$openOnFocus === void 0 ? false : _ref$openOnFocus,
12386
+ _ref$closeOnEscape = _ref.closeOnEscape,
12387
+ closeOnEscape = _ref$closeOnEscape === void 0 ? true : _ref$closeOnEscape,
12388
+ onClose = _ref.onClose,
12389
+ _ref$autoFocus = _ref.autoFocus,
12390
+ autoFocus = _ref$autoFocus === void 0 ? false : _ref$autoFocus,
12380
12391
  rest = _objectWithoutProperties(_ref, _excluded$9);
12381
12392
  var _useState = React.useState(function () {
12382
12393
  if (open && smoothTransitioning) {
@@ -12394,6 +12405,7 @@ var Popover = function Popover(_ref) {
12394
12405
  mode = _useState2[0],
12395
12406
  setMode = _useState2[1];
12396
12407
  var timeout = React.useRef(null);
12408
+ var contentRef = React.useRef(null);
12397
12409
  var handleOpen = React.useCallback(function () {
12398
12410
  if (smoothTransitioning) setMode(Mode.Opening);
12399
12411
  if (!smoothTransitioning) setMode(Mode.Open);
@@ -12412,6 +12424,27 @@ var Popover = function Popover(_ref) {
12412
12424
  if (open) return;
12413
12425
  timeout.current = setTimeout(handleClose, POPOVER_MOUSEOUT_DELAY_MS);
12414
12426
  }, [handleClose, open]);
12427
+ var handleKeyDown = React.useCallback(function (event) {
12428
+ if (closeOnEscape && event.key === 'Escape') {
12429
+ onClose === null || onClose === void 0 || onClose();
12430
+ handleClose();
12431
+ event.preventDefault();
12432
+ }
12433
+ }, [closeOnEscape, onClose, handleClose]);
12434
+ var handleFocus = React.useCallback(function () {
12435
+ if (openOnFocus && open === undefined) {
12436
+ if (timeout.current) clearTimeout(timeout.current);
12437
+ handleOpen();
12438
+ }
12439
+ }, [openOnFocus, open, handleOpen]);
12440
+ var handleBlur = React.useCallback(function (event) {
12441
+ if (openOnFocus && open === undefined) {
12442
+ // Only close if focus moved outside the popover entirely
12443
+ if (!event.currentTarget.contains(event.relatedTarget)) {
12444
+ timeout.current = setTimeout(handleClose, POPOVER_MOUSEOUT_DELAY_MS);
12445
+ }
12446
+ }
12447
+ }, [openOnFocus, open, handleClose]);
12415
12448
  React.useEffect(function () {
12416
12449
  if (mode !== Mode.Closing) return;
12417
12450
  var closingTimeout = setTimeout(function () {
@@ -12455,10 +12488,18 @@ var Popover = function Popover(_ref) {
12455
12488
  }
12456
12489
  }, [handleClose, handleOpen, open]);
12457
12490
  var isOpen = mode === Mode.AutoOpen || mode === Mode.Opening || mode === Mode.Open || mode === Mode.Closing;
12491
+ React.useEffect(function () {
12492
+ if (autoFocus && isOpen && contentRef.current) {
12493
+ contentRef.current.focus();
12494
+ }
12495
+ }, [autoFocus, isOpen]);
12458
12496
  return /*#__PURE__*/React.createElement("div", _extends$1({
12459
12497
  className: classNames("Popover Popover--anchor-".concat(anchor), className),
12460
12498
  onMouseEnter: handleMouseEnter,
12461
- onMouseLeave: handleMouseLeave
12499
+ onMouseLeave: handleMouseLeave,
12500
+ onKeyDown: handleKeyDown,
12501
+ onFocus: handleFocus,
12502
+ onBlur: handleBlur
12462
12503
  }, rest), /*#__PURE__*/React.createElement("span", {
12463
12504
  className: "Popover__trigger"
12464
12505
  }, isOpen && /*#__PURE__*/React.createElement("div", {
@@ -12468,10 +12509,17 @@ var Popover = function Popover(_ref) {
12468
12509
  })
12469
12510
  }, /*#__PURE__*/React.createElement("div", {
12470
12511
  className: "Popover__caret",
12512
+ "aria-hidden": "true",
12471
12513
  style: {
12472
12514
  zIndex: zIndex != null ? zIndex + 1 : undefined
12473
12515
  }
12474
12516
  }), /*#__PURE__*/React.createElement("div", {
12517
+ ref: contentRef,
12518
+ id: popoverId,
12519
+ role: role,
12520
+ "aria-label": ariaLabel,
12521
+ "aria-labelledby": ariaLabelledby,
12522
+ tabIndex: autoFocus ? -1 : undefined,
12475
12523
  className: "Popover__content",
12476
12524
  style: {
12477
12525
  zIndex: zIndex
@@ -12549,13 +12597,15 @@ var SelectableButton = function SelectableButton(_ref) {
12549
12597
  }, rest), /*#__PURE__*/React.createElement("span", null, children));
12550
12598
  };
12551
12599
 
12552
- var _excluded$5 = ["className", "title", "visible", "children", "onClose"];
12600
+ var _excluded$5 = ["className", "title", "visible", "children", "onClose", "autoFocus"];
12553
12601
  var SlidingPane = function SlidingPane(_ref) {
12554
12602
  var className = _ref.className,
12555
12603
  title = _ref.title,
12556
12604
  visible = _ref.visible,
12557
12605
  children = _ref.children,
12558
12606
  onClose = _ref.onClose,
12607
+ _ref$autoFocus = _ref.autoFocus,
12608
+ autoFocus = _ref$autoFocus === void 0 ? true : _ref$autoFocus,
12559
12609
  rest = _objectWithoutProperties(_ref, _excluded$5);
12560
12610
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
12561
12611
  className: classNames('SlidingPane__overlay', {
@@ -12564,6 +12614,7 @@ var SlidingPane = function SlidingPane(_ref) {
12564
12614
  onClick: onClose
12565
12615
  }), /*#__PURE__*/React.createElement(FocusOn, {
12566
12616
  enabled: visible,
12617
+ autoFocus: autoFocus,
12567
12618
  onClickOutside: onClose,
12568
12619
  onEscapeKey: onClose
12569
12620
  }, /*#__PURE__*/React.createElement("div", _extends$1({