@moda/om 21.6.10 → 21.6.12

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.esm.js CHANGED
@@ -9991,6 +9991,13 @@ var ChevronUp12 = function ChevronUp12(_a) {
9991
9991
  };
9992
9992
  ChevronUp12.displayName = 'ChevronUp12';
9993
9993
 
9994
+ var FormControlContext = /*#__PURE__*/createContext({
9995
+ displaysError: false
9996
+ });
9997
+ var useFormControlContext = function useFormControlContext() {
9998
+ return useContext(FormControlContext);
9999
+ };
10000
+
9994
10001
  var dist$1 = {};
9995
10002
 
9996
10003
  var mapCursorToMax = {};
@@ -10824,6 +10831,8 @@ var Select = function Select(_ref) {
10824
10831
  _ref$smallMobileText = _ref.smallMobileText,
10825
10832
  smallMobileText = _ref$smallMobileText === void 0 ? false : _ref$smallMobileText,
10826
10833
  rest = _objectWithoutProperties(_ref, _excluded$j);
10834
+ var _useFormControlContex = useFormControlContext(),
10835
+ errorDisplayedByParent = _useFormControlContex.displaysError;
10827
10836
  var _useSelect = useSelect({
10828
10837
  value: value,
10829
10838
  defaultValue: defaultValue
@@ -10943,7 +10952,7 @@ var Select = function Select(_ref) {
10943
10952
  type: 'CLOSE'
10944
10953
  });
10945
10954
  }
10946
- })), typeof error === 'string' && /*#__PURE__*/React__default.createElement("div", {
10955
+ })), typeof error === 'string' && !errorDisplayedByParent && /*#__PURE__*/React__default.createElement("div", {
10947
10956
  role: "status",
10948
10957
  "aria-live": "polite",
10949
10958
  "aria-atomic": "true",
@@ -11150,7 +11159,14 @@ var Field = /*#__PURE__*/React__default.forwardRef(function (_ref, ref) {
11150
11159
  label = _ref.label,
11151
11160
  placeholder = _ref.placeholder,
11152
11161
  rest = _objectWithoutProperties(_ref, _excluded$h);
11153
- return /*#__PURE__*/React__default.createElement("label", {
11162
+ var fieldContextValue = useMemo(function () {
11163
+ return {
11164
+ displaysError: Boolean(error)
11165
+ };
11166
+ }, [error]);
11167
+ return /*#__PURE__*/React__default.createElement(FormControlContext.Provider, {
11168
+ value: fieldContextValue
11169
+ }, /*#__PURE__*/React__default.createElement("label", {
11154
11170
  className: classNames('Field', className)
11155
11171
  }, label && /*#__PURE__*/React__default.createElement("span", {
11156
11172
  className: "Field__label"
@@ -11173,7 +11189,7 @@ var Field = /*#__PURE__*/React__default.forwardRef(function (_ref, ref) {
11173
11189
  className: "Field__icon"
11174
11190
  }, /*#__PURE__*/React__default.createElement(Warning16, null)))), error && /*#__PURE__*/React__default.createElement("span", {
11175
11191
  className: "Field__error"
11176
- }, error));
11192
+ }, error)));
11177
11193
  });
11178
11194
  Field.displayName = 'Field';
11179
11195
 
@@ -12315,7 +12331,7 @@ var PasswordInput = /*#__PURE__*/forwardRef(function (_ref, ref) {
12315
12331
  });
12316
12332
  PasswordInput.displayName = 'PasswordInput';
12317
12333
 
12318
- var _excluded$9 = ["className", "children", "content", "open", "anchor", "zIndex", "autoPreview", "smoothTransitioning"];
12334
+ var _excluded$9 = ["className", "children", "content", "open", "anchor", "zIndex", "autoPreview", "smoothTransitioning", "role", "aria-label", "aria-labelledby", "popoverId", "openOnFocus", "closeOnEscape", "onClose", "autoFocus"];
12319
12335
  var POPOVER_MOUSEOUT_DELAY_MS = 200;
12320
12336
  var THREE_QUARTER_SECOND_DELAY = 750;
12321
12337
  var ONE_SECOND_DELAY = 1000;
@@ -12341,6 +12357,17 @@ var Popover = function Popover(_ref) {
12341
12357
  autoPreview = _ref$autoPreview === void 0 ? false : _ref$autoPreview,
12342
12358
  _ref$smoothTransition = _ref.smoothTransitioning,
12343
12359
  smoothTransitioning = _ref$smoothTransition === void 0 ? false : _ref$smoothTransition,
12360
+ role = _ref.role,
12361
+ ariaLabel = _ref['aria-label'],
12362
+ ariaLabelledby = _ref['aria-labelledby'],
12363
+ popoverId = _ref.popoverId,
12364
+ _ref$openOnFocus = _ref.openOnFocus,
12365
+ openOnFocus = _ref$openOnFocus === void 0 ? false : _ref$openOnFocus,
12366
+ _ref$closeOnEscape = _ref.closeOnEscape,
12367
+ closeOnEscape = _ref$closeOnEscape === void 0 ? true : _ref$closeOnEscape,
12368
+ onClose = _ref.onClose,
12369
+ _ref$autoFocus = _ref.autoFocus,
12370
+ autoFocus = _ref$autoFocus === void 0 ? false : _ref$autoFocus,
12344
12371
  rest = _objectWithoutProperties(_ref, _excluded$9);
12345
12372
  var _useState = useState(function () {
12346
12373
  if (open && smoothTransitioning) {
@@ -12358,6 +12385,7 @@ var Popover = function Popover(_ref) {
12358
12385
  mode = _useState2[0],
12359
12386
  setMode = _useState2[1];
12360
12387
  var timeout = useRef(null);
12388
+ var contentRef = useRef(null);
12361
12389
  var handleOpen = useCallback(function () {
12362
12390
  if (smoothTransitioning) setMode(Mode.Opening);
12363
12391
  if (!smoothTransitioning) setMode(Mode.Open);
@@ -12376,6 +12404,27 @@ var Popover = function Popover(_ref) {
12376
12404
  if (open) return;
12377
12405
  timeout.current = setTimeout(handleClose, POPOVER_MOUSEOUT_DELAY_MS);
12378
12406
  }, [handleClose, open]);
12407
+ var handleKeyDown = useCallback(function (event) {
12408
+ if (closeOnEscape && event.key === 'Escape') {
12409
+ onClose === null || onClose === void 0 || onClose();
12410
+ handleClose();
12411
+ event.preventDefault();
12412
+ }
12413
+ }, [closeOnEscape, onClose, handleClose]);
12414
+ var handleFocus = useCallback(function () {
12415
+ if (openOnFocus && open === undefined) {
12416
+ if (timeout.current) clearTimeout(timeout.current);
12417
+ handleOpen();
12418
+ }
12419
+ }, [openOnFocus, open, handleOpen]);
12420
+ var handleBlur = useCallback(function (event) {
12421
+ if (openOnFocus && open === undefined) {
12422
+ // Only close if focus moved outside the popover entirely
12423
+ if (!event.currentTarget.contains(event.relatedTarget)) {
12424
+ timeout.current = setTimeout(handleClose, POPOVER_MOUSEOUT_DELAY_MS);
12425
+ }
12426
+ }
12427
+ }, [openOnFocus, open, handleClose]);
12379
12428
  useEffect(function () {
12380
12429
  if (mode !== Mode.Closing) return;
12381
12430
  var closingTimeout = setTimeout(function () {
@@ -12419,10 +12468,18 @@ var Popover = function Popover(_ref) {
12419
12468
  }
12420
12469
  }, [handleClose, handleOpen, open]);
12421
12470
  var isOpen = mode === Mode.AutoOpen || mode === Mode.Opening || mode === Mode.Open || mode === Mode.Closing;
12471
+ useEffect(function () {
12472
+ if (autoFocus && isOpen && contentRef.current) {
12473
+ contentRef.current.focus();
12474
+ }
12475
+ }, [autoFocus, isOpen]);
12422
12476
  return /*#__PURE__*/React__default.createElement("div", _extends$1({
12423
12477
  className: classNames("Popover Popover--anchor-".concat(anchor), className),
12424
12478
  onMouseEnter: handleMouseEnter,
12425
- onMouseLeave: handleMouseLeave
12479
+ onMouseLeave: handleMouseLeave,
12480
+ onKeyDown: handleKeyDown,
12481
+ onFocus: handleFocus,
12482
+ onBlur: handleBlur
12426
12483
  }, rest), /*#__PURE__*/React__default.createElement("span", {
12427
12484
  className: "Popover__trigger"
12428
12485
  }, isOpen && /*#__PURE__*/React__default.createElement("div", {
@@ -12432,10 +12489,17 @@ var Popover = function Popover(_ref) {
12432
12489
  })
12433
12490
  }, /*#__PURE__*/React__default.createElement("div", {
12434
12491
  className: "Popover__caret",
12492
+ "aria-hidden": "true",
12435
12493
  style: {
12436
12494
  zIndex: zIndex != null ? zIndex + 1 : undefined
12437
12495
  }
12438
12496
  }), /*#__PURE__*/React__default.createElement("div", {
12497
+ ref: contentRef,
12498
+ id: popoverId,
12499
+ role: role,
12500
+ "aria-label": ariaLabel,
12501
+ "aria-labelledby": ariaLabelledby,
12502
+ tabIndex: autoFocus ? -1 : undefined,
12439
12503
  className: "Popover__content",
12440
12504
  style: {
12441
12505
  zIndex: zIndex
@@ -12727,4 +12791,4 @@ var Utilities = {
12727
12791
  States: States
12728
12792
  };
12729
12793
 
12730
- export { ArcWindow, AspectRatioBox, Badge, Bradley, Brancusi, Breadcrumb, Breadcrumbs, Breakpoint, BreakpointContext, BreakpointProvider, Button, Checkbox, Circle, Clickable, ColorSwatch, ConfirmProvider, Constrain, ControlLink, CreditCardNumberInput, DEFAULT_PRODUCT_ASPECT_HEIGHT, DEFAULT_PRODUCT_ASPECT_RATIO, DEFAULT_PRODUCT_ASPECT_WIDTH, DefinitionList, Dialog, Diamond, Divider, ExceedConstrain, Expandable, Field, FocusOn, Field as Input, Keyhole, Label, LineAboveDivider, Loading, LoadingBalls, LoadingItems1, LoadingItems2, LoadingItems3, LoadingItems4, LoadingItems5, LoadingItemsLavenderBlue1, LoadingItemsLavenderBlue2, LoadingItemsLavenderBlue3, LoadingItemsLavenderBlue4, LoadingItemsLavenderBlue5, LoadingShapes, LoadingShapesLavenderBlue, LoadingShapesPinkGreen, Mirror, Modal, ModalOverlay, MultiSelect, NoLineDivider, Oval, Overlay, POPOVER_MOUSEOUT_DELAY_MS, Paginator, PasswordInput, Popover, PromoBanner, RadioButton, SKU_COLORS, SearchInput, Select, SelectableButton, SlidingPane, Stack, Tab, TabList, TabPanel, TabPanels, Tabs, Tag, Text, TextInput, Textarea, Toast, Triangle, TwoLineDivider, UNMOUNT_DELAY_MS, Utilities, VerticalDivider, Window, discriminate, tokens, useBreakpoint, useClickOutside, useConfirm, useKeyboardListNavigation, useUpdateEffect };
12794
+ export { ArcWindow, AspectRatioBox, Badge, Bradley, Brancusi, Breadcrumb, Breadcrumbs, Breakpoint, BreakpointContext, BreakpointProvider, Button, Checkbox, Circle, Clickable, ColorSwatch, ConfirmProvider, Constrain, ControlLink, CreditCardNumberInput, DEFAULT_PRODUCT_ASPECT_HEIGHT, DEFAULT_PRODUCT_ASPECT_RATIO, DEFAULT_PRODUCT_ASPECT_WIDTH, DefinitionList, Dialog, Diamond, Divider, ExceedConstrain, Expandable, Field, FocusOn, FormControlContext, Field as Input, Keyhole, Label, LineAboveDivider, Loading, LoadingBalls, LoadingItems1, LoadingItems2, LoadingItems3, LoadingItems4, LoadingItems5, LoadingItemsLavenderBlue1, LoadingItemsLavenderBlue2, LoadingItemsLavenderBlue3, LoadingItemsLavenderBlue4, LoadingItemsLavenderBlue5, LoadingShapes, LoadingShapesLavenderBlue, LoadingShapesPinkGreen, Mirror, Modal, ModalOverlay, MultiSelect, NoLineDivider, Oval, Overlay, POPOVER_MOUSEOUT_DELAY_MS, Paginator, PasswordInput, Popover, PromoBanner, RadioButton, SKU_COLORS, SearchInput, Select, SelectableButton, SlidingPane, Stack, Tab, TabList, TabPanel, TabPanels, Tabs, Tag, Text, TextInput, Textarea, Toast, Triangle, TwoLineDivider, UNMOUNT_DELAY_MS, Utilities, VerticalDivider, Window, discriminate, tokens, useBreakpoint, useClickOutside, useConfirm, useFormControlContext, useKeyboardListNavigation, useUpdateEffect };