@lumx/react 2.2.12-alpha.2 → 2.2.14

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.
Files changed (37) hide show
  1. package/esm/_internal/Checkbox2.js +3 -1
  2. package/esm/_internal/Checkbox2.js.map +1 -1
  3. package/esm/_internal/CommentBlock.js +12 -5
  4. package/esm/_internal/CommentBlock.js.map +1 -1
  5. package/esm/_internal/Dropdown2.js +5 -2
  6. package/esm/_internal/Dropdown2.js.map +1 -1
  7. package/esm/_internal/List2.js +11 -2
  8. package/esm/_internal/List2.js.map +1 -1
  9. package/esm/_internal/Popover2.js +69 -4
  10. package/esm/_internal/Popover2.js.map +1 -1
  11. package/esm/_internal/RadioGroup.js +3 -1
  12. package/esm/_internal/RadioGroup.js.map +1 -1
  13. package/esm/_internal/Slides.js +1 -24
  14. package/esm/_internal/Slides.js.map +1 -1
  15. package/esm/_internal/Tooltip2.js +1 -3
  16. package/esm/_internal/Tooltip2.js.map +1 -1
  17. package/esm/_internal/comment-block.js +8 -0
  18. package/esm/_internal/comment-block.js.map +1 -1
  19. package/package.json +4 -4
  20. package/src/components/autocomplete/__snapshots__/Autocomplete.test.tsx.snap +4 -0
  21. package/src/components/autocomplete/__snapshots__/AutocompleteMultiple.test.tsx.snap +1 -0
  22. package/src/components/checkbox/Checkbox.tsx +4 -0
  23. package/src/components/comment-block/CommentBlock.stories.tsx +7 -4
  24. package/src/components/comment-block/CommentBlock.tsx +13 -3
  25. package/src/components/comment-block/__snapshots__/CommentBlock.test.tsx.snap +10 -5
  26. package/src/components/dialog/__snapshots__/Dialog.test.tsx.snap +1 -0
  27. package/src/components/dropdown/Dropdown.tsx +5 -0
  28. package/src/components/dropdown/__snapshots__/Dropdown.test.tsx.snap +1 -0
  29. package/src/components/list/List.tsx +12 -2
  30. package/src/components/list/__snapshots__/List.test.tsx.snap +5 -5
  31. package/src/components/popover/Popover.tsx +42 -2
  32. package/src/components/radio-button/RadioButton.tsx +4 -0
  33. package/src/components/select/__snapshots__/Select.test.tsx.snap +1 -0
  34. package/src/components/select/__snapshots__/SelectMultiple.test.tsx.snap +2 -0
  35. package/src/components/tooltip/useTooltipOpen.tsx +0 -1
  36. package/src/stories/generated/Toolbar/Demos.stories.tsx +1 -0
  37. package/types.d.ts +13 -1
@@ -2114,6 +2114,30 @@ var usePopper = function usePopper(referenceElement, popperElement, options) {
2114
2114
  };
2115
2115
  };
2116
2116
 
2117
+ /**
2118
+ * Hook that allows to control when there is a focus event within a given element, meaning
2119
+ * that any element within the given target will trigger the focus in and focus out events.
2120
+ * @param options - UseFocusWithinOptions
2121
+ */
2122
+ var useFocusWithin = function useFocusWithin(_ref) {
2123
+ var element = _ref.element,
2124
+ onFocusIn = _ref.onFocusIn,
2125
+ onFocusOut = _ref.onFocusOut;
2126
+ useEffect(function () {
2127
+ if (element) {
2128
+ element.addEventListener('focusin', onFocusIn);
2129
+ element.addEventListener('focusout', onFocusOut);
2130
+ }
2131
+
2132
+ return function () {
2133
+ if (element) {
2134
+ element.removeEventListener('focusin', onFocusIn);
2135
+ element.removeEventListener('focusout', onFocusOut);
2136
+ }
2137
+ };
2138
+ }, [onFocusIn, element, onFocusOut]);
2139
+ };
2140
+
2117
2141
  /**
2118
2142
  * Different possible placements for the popover.
2119
2143
  */
@@ -2275,7 +2299,9 @@ var Popover = forwardRef(function (props, ref) {
2275
2299
  style = props.style,
2276
2300
  usePortal = props.usePortal,
2277
2301
  zIndex = props.zIndex,
2278
- forwardedProps = _objectWithoutProperties(props, ["anchorRef", "boundaryRef", "children", "className", "closeOnClickAway", "closeOnEscape", "elevation", "fitToAnchorWidth", "fitWithinViewportHeight", "focusElement", "hasArrow", "isOpen", "offset", "onClose", "placement", "style", "usePortal", "zIndex"]); // eslint-disable-next-line react-hooks/rules-of-hooks
2302
+ _props$focusAnchorOnC = props.focusAnchorOnClose,
2303
+ focusAnchorOnClose = _props$focusAnchorOnC === void 0 ? true : _props$focusAnchorOnC,
2304
+ forwardedProps = _objectWithoutProperties(props, ["anchorRef", "boundaryRef", "children", "className", "closeOnClickAway", "closeOnEscape", "elevation", "fitToAnchorWidth", "fitWithinViewportHeight", "focusElement", "hasArrow", "isOpen", "offset", "onClose", "placement", "style", "usePortal", "zIndex", "focusAnchorOnClose"]); // eslint-disable-next-line react-hooks/rules-of-hooks
2279
2305
 
2280
2306
 
2281
2307
  var _useState = useState(),
@@ -2291,6 +2317,45 @@ var Popover = forwardRef(function (props, ref) {
2291
2317
 
2292
2318
 
2293
2319
  var clickAwayRef = useRef(null);
2320
+ /**
2321
+ * Track whether the focus is currently set in the
2322
+ * popover.
2323
+ * */
2324
+ // eslint-disable-next-line react-hooks/rules-of-hooks
2325
+
2326
+ var isFocusedWithin = useRef(false); // eslint-disable-next-line react-hooks/rules-of-hooks
2327
+
2328
+ useFocusWithin({
2329
+ element: popperElement || null,
2330
+ onFocusIn: function onFocusIn() {
2331
+ isFocusedWithin.current = true;
2332
+ },
2333
+ onFocusOut: function onFocusOut() {
2334
+ isFocusedWithin.current = false;
2335
+ }
2336
+ });
2337
+ /** Action on close */
2338
+
2339
+ var handleClose = function handleClose() {
2340
+ if (!onClose) {
2341
+ return;
2342
+ }
2343
+ /**
2344
+ * If the focus is currently within the popover
2345
+ * when the popover closes, reset the focus back to the anchor element
2346
+ * unless specifically requested not to.
2347
+ */
2348
+
2349
+
2350
+ if (isFocusedWithin.current && focusAnchorOnClose) {
2351
+ var _anchorRef$current;
2352
+
2353
+ (_anchorRef$current = anchorRef.current) === null || _anchorRef$current === void 0 ? void 0 : _anchorRef$current.focus();
2354
+ }
2355
+
2356
+ onClose();
2357
+ };
2358
+
2294
2359
  var modifiers = [];
2295
2360
  var actualOffset = [(_ref5 = offset === null || offset === void 0 ? void 0 : offset.along) !== null && _ref5 !== void 0 ? _ref5 : 0, ((_ref6 = offset === null || offset === void 0 ? void 0 : offset.away) !== null && _ref6 !== void 0 ? _ref6 : 0) + (hasArrow ? ARROW_SIZE : 0)];
2296
2361
  modifiers.push({
@@ -2365,7 +2430,7 @@ var Popover = forwardRef(function (props, ref) {
2365
2430
  return newStyles;
2366
2431
  }, [style, styles.popper, zIndex, fitWithinViewportHeight]); // eslint-disable-next-line react-hooks/rules-of-hooks
2367
2432
 
2368
- useCallbackOnEscape(onClose, isOpen && closeOnEscape); // eslint-disable-next-line react-hooks/rules-of-hooks
2433
+ useCallbackOnEscape(handleClose, isOpen && closeOnEscape); // eslint-disable-next-line react-hooks/rules-of-hooks
2369
2434
 
2370
2435
  useFocus(focusElement === null || focusElement === void 0 ? void 0 : focusElement.current, isOpen && ((_ref8 = state === null || state === void 0 ? void 0 : (_state$rects = state.rects) === null || _state$rects === void 0 ? void 0 : (_state$rects$popper2 = _state$rects.popper) === null || _state$rects$popper2 === void 0 ? void 0 : _state$rects$popper2.y) !== null && _ref8 !== void 0 ? _ref8 : -1) >= 0); // eslint-disable-next-line react-hooks/rules-of-hooks
2371
2436
 
@@ -2379,7 +2444,7 @@ var Popover = forwardRef(function (props, ref) {
2379
2444
  })),
2380
2445
  style: popoverStyle
2381
2446
  }, attributes.popper), React.createElement(ClickAwayProvider, {
2382
- callback: closeOnClickAway && onClose,
2447
+ callback: closeOnClickAway && handleClose,
2383
2448
  refs: clickAwayRefs
2384
2449
  }, hasArrow && React.createElement("div", {
2385
2450
  ref: setArrowElement,
@@ -2391,5 +2456,5 @@ Popover.displayName = COMPONENT_NAME;
2391
2456
  Popover.className = CLASSNAME;
2392
2457
  Popover.defaultProps = DEFAULT_PROPS;
2393
2458
 
2394
- export { Placement as P, Popover as a, usePopper as b, useFocus as u };
2459
+ export { Placement as P, Popover as a, useFocusWithin as b, usePopper as c, useFocus as u };
2395
2460
  //# sourceMappingURL=Popover2.js.map