@kaizen/components 1.81.0 → 1.81.1

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.
@@ -0,0 +1,11 @@
1
+ 'use strict';
2
+
3
+ var reactAriaComponents = require('react-aria-components');
4
+ Object.keys(reactAriaComponents).forEach(function (k) {
5
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
6
+ enumerable: true,
7
+ get: function () {
8
+ return reactAriaComponents[k];
9
+ }
10
+ });
11
+ });
@@ -0,0 +1,11 @@
1
+ 'use strict';
2
+
3
+ var reactAria = require('react-aria');
4
+ Object.keys(reactAria).forEach(function (k) {
5
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
6
+ enumerable: true,
7
+ get: function () {
8
+ return reactAria[k];
9
+ }
10
+ });
11
+ });
@@ -4,7 +4,7 @@ var React = require('react');
4
4
  var ReactDOM = require('react-dom');
5
5
  var react = require('@headlessui/react');
6
6
  var classnames = require('classnames');
7
- var FocusLock = require('react-focus-lock');
7
+ var reactFocusOn = require('react-focus-on');
8
8
  var useIsClientReady = require('../../utils/useIsClientReady/useIsClientReady.cjs');
9
9
  var console = require('../util/console.cjs');
10
10
  var ModalContext = require('./context/ModalContext.cjs');
@@ -16,7 +16,6 @@ function _interopDefault(e) {
16
16
  }
17
17
  var React__default = /*#__PURE__*/_interopDefault(React);
18
18
  var classnames__default = /*#__PURE__*/_interopDefault(classnames);
19
- var FocusLock__default = /*#__PURE__*/_interopDefault(FocusLock);
20
19
  var GenericModal = function (_a) {
21
20
  var propsId = _a.id,
22
21
  children = _a.children,
@@ -33,87 +32,60 @@ var GenericModal = function (_a) {
33
32
  var labelledByID = React.useId();
34
33
  var describedByID = React.useId();
35
34
  var isClientReady = useIsClientReady.useIsClientReady();
36
- var _c = React.useState(null),
37
- scrollLayer = _c[0],
38
- setScrollLayer = _c[1];
39
- var _d = React.useState(null),
40
- modalLayer = _d[0],
41
- setModalLayer = _d[1];
35
+ var scrollLayerRef = React.useRef(null);
36
+ var modalLayerRef = React.useRef(null);
42
37
  var scrollModalToTop = function () {
43
38
  // If we have a really long modal, the autofocus could land on an element down below
44
39
  // causing the modal to scroll down and skipping over the content near the modal's top.
45
40
  // Ensure that when the modal opens, we are at the top of its content.
46
41
  requestAnimationFrame(function () {
47
- if (!scrollLayer) return;
48
- scrollLayer.scrollTop = 0;
42
+ var scrollElement = scrollLayerRef.current;
43
+ // This little verbose of a check but this ensures that the element is attached to the DOM as it animates in. This additional check aims to avoid race conditions
44
+ if (!(scrollElement === null || scrollElement === void 0 ? void 0 : scrollElement.isConnected)) return;
45
+ scrollElement.scrollTop = 0;
49
46
  });
50
47
  };
51
- var outsideModalClickHandler = function (event) {
52
- if (event.target === scrollLayer || event.target === modalLayer) {
53
- onOutsideModalClick === null || onOutsideModalClick === void 0 ? void 0 : onOutsideModalClick(event);
48
+ var a11yWarn = function () {
49
+ if (!isClientReady) return;
50
+ // Ensure that consumers have provided an element that labels the modal
51
+ // to meet ARIA accessibility guidelines.
52
+ if (!document.getElementById(labelledByID)) {
53
+ console.warn("When using the Modal component, you must provide a label for the modal.\n Make sure you have a <ModalAccessibleLabel /> component with content that labels the modal.");
54
54
  }
55
55
  };
56
56
  var focusOnAccessibleLabel = function () {
57
57
  if (!isClientReady) return;
58
+ var modalElement = modalLayerRef.current;
59
+ if (!(modalElement === null || modalElement === void 0 ? void 0 : modalElement.isConnected)) return;
58
60
  // Check if focus already exists within the modal
59
- if (modalLayer === null || modalLayer === void 0 ? void 0 : modalLayer.contains(document.activeElement)) {
61
+ if (modalElement.contains(document.activeElement)) {
60
62
  return;
61
63
  }
62
64
  var labelElement = document.getElementById(labelledByID);
63
- labelElement === null || labelElement === void 0 ? void 0 : labelElement.focus();
64
- };
65
- var a11yWarn = function () {
66
- if (!isClientReady) return;
67
- // Ensure that consumers have provided an element that labels the modal
68
- // to meet ARIA accessibility guidelines.
69
- if (!document.getElementById(labelledByID)) {
70
- console.warn("When using the Modal component, you must provide a label for the modal.\n Make sure you have a <ModalAccessibleLabel /> component with content that labels the modal.");
65
+ if (labelElement === null || labelElement === void 0 ? void 0 : labelElement.isConnected) {
66
+ labelElement.focus();
71
67
  }
72
68
  };
73
- var preventBodyScroll = function () {
74
- var _a;
75
- if (!isClientReady) return;
76
- var hasScrollbar = window.innerWidth > document.documentElement.clientWidth;
77
- var scrollStyles = [GenericModal_module.unscrollable];
78
- if (hasScrollbar) {
79
- scrollStyles.push(GenericModal_module.pseudoScrollbar);
69
+ var onEscapeKeyHandler = function (e) {
70
+ if (e instanceof KeyboardEvent) {
71
+ onEscapeKeyup === null || onEscapeKeyup === void 0 ? void 0 : onEscapeKeyup(e);
80
72
  }
81
- (_a = document.documentElement.classList).add.apply(_a, scrollStyles);
82
73
  };
83
74
  var onAfterEnterHandler = function () {
84
75
  scrollModalToTop();
85
- if (modalLayer) {
76
+ var modalElement = modalLayerRef.current;
77
+ if (modalElement) {
86
78
  onAfterEnter === null || onAfterEnter === void 0 ? void 0 : onAfterEnter();
87
79
  focusOnAccessibleLabel();
88
80
  a11yWarn();
89
81
  }
90
82
  };
91
- var escapeKeyHandler = React.useCallback(function (event) {
92
- if (event.key === 'Escape') {
93
- onEscapeKeyup === null || onEscapeKeyup === void 0 ? void 0 : onEscapeKeyup(event);
94
- }
95
- }, [onEscapeKeyup]);
96
- var onBeforeEnterHandler = function () {
97
- preventBodyScroll();
98
- if (onEscapeKeyup && isClientReady) {
99
- document.addEventListener('keyup', escapeKeyHandler);
83
+ var outsideModalClickHandler = function (e) {
84
+ if (e.target === scrollLayerRef.current || e.target === modalLayerRef.current) {
85
+ onOutsideModalClick === null || onOutsideModalClick === void 0 ? void 0 : onOutsideModalClick(e);
100
86
  }
101
87
  };
102
- var cleanUpAfterClose = React.useCallback(function () {
103
- if (!isClientReady) return;
104
- document.documentElement.classList.remove(GenericModal_module.unscrollable, GenericModal_module.pseudoScrollbar);
105
- if (onEscapeKeyup) {
106
- document.removeEventListener('keyup', escapeKeyHandler);
107
- }
108
- }, [escapeKeyHandler, onEscapeKeyup, isClientReady]);
109
- /* Ensure sure add-on styles (e.g. unscrollable) and key event is cleaned up when the modal is unmounted*/
110
- React.useEffect(function () {
111
- return function () {
112
- return cleanUpAfterClose();
113
- };
114
- }, [cleanUpAfterClose]);
115
88
  var onAfterLeaveHandler = function () {
116
- cleanUpAfterClose();
117
89
  propsOnAfterLeave === null || propsOnAfterLeave === void 0 ? void 0 : propsOnAfterLeave();
118
90
  };
119
91
  // Don't render portal during SSR
@@ -123,7 +95,6 @@ var GenericModal = function (_a) {
123
95
  return ReactDOM.createPortal(React__default.default.createElement(react.Transition, {
124
96
  appear: true,
125
97
  show: isOpen,
126
- beforeEnter: onBeforeEnterHandler,
127
98
  afterEnter: onAfterEnterHandler,
128
99
  afterLeave: onAfterLeaveHandler,
129
100
  "data-generic-modal-transition-wrapper": true,
@@ -131,9 +102,10 @@ var GenericModal = function (_a) {
131
102
  leave: GenericModal_module.animatingLeave,
132
103
  as: "div",
133
104
  className: classnames__default.default(GenericModal_module.transitionLayer, className)
134
- }, React__default.default.createElement(FocusLock__default.default, {
135
- disabled: focusLockDisabled,
105
+ }, React__default.default.createElement(reactFocusOn.FocusOn, {
106
+ focusLock: focusLockDisabled,
136
107
  returnFocus: true,
108
+ onEscapeKey: onEscapeKeyHandler,
137
109
  // Disabling false positive
138
110
  // eslint-disable-next-line jsx-a11y/no-autofocus
139
111
  autoFocus: false
@@ -141,11 +113,9 @@ var GenericModal = function (_a) {
141
113
  className: GenericModal_module.backdropLayer
142
114
  }), React__default.default.createElement("div", {
143
115
  className: GenericModal_module.scrollLayer,
144
- ref: function (scrollLayerRef) {
145
- setScrollLayer(scrollLayerRef);
146
- },
147
- onClick: outsideModalClickHandler,
148
- "data-testid": "".concat(id, "-scrollLayer")
116
+ ref: scrollLayerRef,
117
+ "data-testid": "".concat(id, "-scrollLayer"),
118
+ onClick: outsideModalClickHandler
149
119
  }, React__default.default.createElement(ModalContext.ModalContext.Provider, {
150
120
  value: {
151
121
  labelledByID: labelledByID,
@@ -156,9 +126,7 @@ var GenericModal = function (_a) {
156
126
  className: GenericModal_module.modalLayer,
157
127
  "aria-labelledby": labelledByID,
158
128
  "aria-describedby": describedByID,
159
- ref: function (modalLayerRef) {
160
- return setModalLayer(modalLayerRef);
161
- },
129
+ ref: modalLayerRef,
162
130
  "data-testid": id
163
131
  }, children))))), document.body);
164
132
  };
@@ -6,8 +6,6 @@ var styles = {
6
6
  "modalLayer": "GenericModal-module_modalLayer__WfD1U",
7
7
  "transitionLayer": "GenericModal-module_transitionLayer__zTH-C",
8
8
  "animatingEnter": "GenericModal-module_animatingEnter__P3wuk",
9
- "animatingLeave": "GenericModal-module_animatingLeave__rNkKX",
10
- "unscrollable": "GenericModal-module_unscrollable__HjRaW",
11
- "pseudoScrollbar": "GenericModal-module_pseudoScrollbar__BhRqh"
9
+ "animatingLeave": "GenericModal-module_animatingLeave__rNkKX"
12
10
  };
13
11
  module.exports = styles;
@@ -0,0 +1 @@
1
+ export * from 'react-aria-components';
@@ -0,0 +1 @@
1
+ export * from 'react-aria';
@@ -1,8 +1,8 @@
1
- import React, { useId, useState, useCallback, useEffect } from 'react';
1
+ import React, { useId, useRef } from 'react';
2
2
  import { createPortal } from 'react-dom';
3
3
  import { Transition } from '@headlessui/react';
4
4
  import classnames from 'classnames';
5
- import FocusLock from 'react-focus-lock';
5
+ import { FocusOn } from 'react-focus-on';
6
6
  import { useIsClientReady } from '../../utils/useIsClientReady/useIsClientReady.mjs';
7
7
  import { warn } from '../util/console.mjs';
8
8
  import { ModalContext } from './context/ModalContext.mjs';
@@ -24,87 +24,60 @@ const GenericModal = /*#__PURE__*/function () {
24
24
  var labelledByID = useId();
25
25
  var describedByID = useId();
26
26
  var isClientReady = useIsClientReady();
27
- var _c = useState(null),
28
- scrollLayer = _c[0],
29
- setScrollLayer = _c[1];
30
- var _d = useState(null),
31
- modalLayer = _d[0],
32
- setModalLayer = _d[1];
27
+ var scrollLayerRef = useRef(null);
28
+ var modalLayerRef = useRef(null);
33
29
  var scrollModalToTop = function () {
34
30
  // If we have a really long modal, the autofocus could land on an element down below
35
31
  // causing the modal to scroll down and skipping over the content near the modal's top.
36
32
  // Ensure that when the modal opens, we are at the top of its content.
37
33
  requestAnimationFrame(function () {
38
- if (!scrollLayer) return;
39
- scrollLayer.scrollTop = 0;
34
+ var scrollElement = scrollLayerRef.current;
35
+ // This little verbose of a check but this ensures that the element is attached to the DOM as it animates in. This additional check aims to avoid race conditions
36
+ if (!(scrollElement === null || scrollElement === void 0 ? void 0 : scrollElement.isConnected)) return;
37
+ scrollElement.scrollTop = 0;
40
38
  });
41
39
  };
42
- var outsideModalClickHandler = function (event) {
43
- if (event.target === scrollLayer || event.target === modalLayer) {
44
- onOutsideModalClick === null || onOutsideModalClick === void 0 ? void 0 : onOutsideModalClick(event);
40
+ var a11yWarn = function () {
41
+ if (!isClientReady) return;
42
+ // Ensure that consumers have provided an element that labels the modal
43
+ // to meet ARIA accessibility guidelines.
44
+ if (!document.getElementById(labelledByID)) {
45
+ warn("When using the Modal component, you must provide a label for the modal.\n Make sure you have a <ModalAccessibleLabel /> component with content that labels the modal.");
45
46
  }
46
47
  };
47
48
  var focusOnAccessibleLabel = function () {
48
49
  if (!isClientReady) return;
50
+ var modalElement = modalLayerRef.current;
51
+ if (!(modalElement === null || modalElement === void 0 ? void 0 : modalElement.isConnected)) return;
49
52
  // Check if focus already exists within the modal
50
- if (modalLayer === null || modalLayer === void 0 ? void 0 : modalLayer.contains(document.activeElement)) {
53
+ if (modalElement.contains(document.activeElement)) {
51
54
  return;
52
55
  }
53
56
  var labelElement = document.getElementById(labelledByID);
54
- labelElement === null || labelElement === void 0 ? void 0 : labelElement.focus();
55
- };
56
- var a11yWarn = function () {
57
- if (!isClientReady) return;
58
- // Ensure that consumers have provided an element that labels the modal
59
- // to meet ARIA accessibility guidelines.
60
- if (!document.getElementById(labelledByID)) {
61
- warn("When using the Modal component, you must provide a label for the modal.\n Make sure you have a <ModalAccessibleLabel /> component with content that labels the modal.");
57
+ if (labelElement === null || labelElement === void 0 ? void 0 : labelElement.isConnected) {
58
+ labelElement.focus();
62
59
  }
63
60
  };
64
- var preventBodyScroll = function () {
65
- var _a;
66
- if (!isClientReady) return;
67
- var hasScrollbar = window.innerWidth > document.documentElement.clientWidth;
68
- var scrollStyles = [styles.unscrollable];
69
- if (hasScrollbar) {
70
- scrollStyles.push(styles.pseudoScrollbar);
61
+ var onEscapeKeyHandler = function (e) {
62
+ if (e instanceof KeyboardEvent) {
63
+ onEscapeKeyup === null || onEscapeKeyup === void 0 ? void 0 : onEscapeKeyup(e);
71
64
  }
72
- (_a = document.documentElement.classList).add.apply(_a, scrollStyles);
73
65
  };
74
66
  var onAfterEnterHandler = function () {
75
67
  scrollModalToTop();
76
- if (modalLayer) {
68
+ var modalElement = modalLayerRef.current;
69
+ if (modalElement) {
77
70
  onAfterEnter === null || onAfterEnter === void 0 ? void 0 : onAfterEnter();
78
71
  focusOnAccessibleLabel();
79
72
  a11yWarn();
80
73
  }
81
74
  };
82
- var escapeKeyHandler = useCallback(function (event) {
83
- if (event.key === 'Escape') {
84
- onEscapeKeyup === null || onEscapeKeyup === void 0 ? void 0 : onEscapeKeyup(event);
85
- }
86
- }, [onEscapeKeyup]);
87
- var onBeforeEnterHandler = function () {
88
- preventBodyScroll();
89
- if (onEscapeKeyup && isClientReady) {
90
- document.addEventListener('keyup', escapeKeyHandler);
75
+ var outsideModalClickHandler = function (e) {
76
+ if (e.target === scrollLayerRef.current || e.target === modalLayerRef.current) {
77
+ onOutsideModalClick === null || onOutsideModalClick === void 0 ? void 0 : onOutsideModalClick(e);
91
78
  }
92
79
  };
93
- var cleanUpAfterClose = useCallback(function () {
94
- if (!isClientReady) return;
95
- document.documentElement.classList.remove(styles.unscrollable, styles.pseudoScrollbar);
96
- if (onEscapeKeyup) {
97
- document.removeEventListener('keyup', escapeKeyHandler);
98
- }
99
- }, [escapeKeyHandler, onEscapeKeyup, isClientReady]);
100
- /* Ensure sure add-on styles (e.g. unscrollable) and key event is cleaned up when the modal is unmounted*/
101
- useEffect(function () {
102
- return function () {
103
- return cleanUpAfterClose();
104
- };
105
- }, [cleanUpAfterClose]);
106
80
  var onAfterLeaveHandler = function () {
107
- cleanUpAfterClose();
108
81
  propsOnAfterLeave === null || propsOnAfterLeave === void 0 ? void 0 : propsOnAfterLeave();
109
82
  };
110
83
  // Don't render portal during SSR
@@ -114,7 +87,6 @@ const GenericModal = /*#__PURE__*/function () {
114
87
  return /*#__PURE__*/createPortal(/*#__PURE__*/React.createElement(Transition, {
115
88
  appear: true,
116
89
  show: isOpen,
117
- beforeEnter: onBeforeEnterHandler,
118
90
  afterEnter: onAfterEnterHandler,
119
91
  afterLeave: onAfterLeaveHandler,
120
92
  "data-generic-modal-transition-wrapper": true,
@@ -122,9 +94,10 @@ const GenericModal = /*#__PURE__*/function () {
122
94
  leave: styles.animatingLeave,
123
95
  as: "div",
124
96
  className: classnames(styles.transitionLayer, className)
125
- }, /*#__PURE__*/React.createElement(FocusLock, {
126
- disabled: focusLockDisabled,
97
+ }, /*#__PURE__*/React.createElement(FocusOn, {
98
+ focusLock: focusLockDisabled,
127
99
  returnFocus: true,
100
+ onEscapeKey: onEscapeKeyHandler,
128
101
  // Disabling false positive
129
102
  // eslint-disable-next-line jsx-a11y/no-autofocus
130
103
  autoFocus: false
@@ -132,11 +105,9 @@ const GenericModal = /*#__PURE__*/function () {
132
105
  className: styles.backdropLayer
133
106
  }), /*#__PURE__*/React.createElement("div", {
134
107
  className: styles.scrollLayer,
135
- ref: function (scrollLayerRef) {
136
- setScrollLayer(scrollLayerRef);
137
- },
138
- onClick: outsideModalClickHandler,
139
- "data-testid": "".concat(id, "-scrollLayer")
108
+ ref: scrollLayerRef,
109
+ "data-testid": "".concat(id, "-scrollLayer"),
110
+ onClick: outsideModalClickHandler
140
111
  }, /*#__PURE__*/React.createElement(ModalContext.Provider, {
141
112
  value: {
142
113
  labelledByID: labelledByID,
@@ -147,9 +118,7 @@ const GenericModal = /*#__PURE__*/function () {
147
118
  className: styles.modalLayer,
148
119
  "aria-labelledby": labelledByID,
149
120
  "aria-describedby": describedByID,
150
- ref: function (modalLayerRef) {
151
- return setModalLayer(modalLayerRef);
152
- },
121
+ ref: modalLayerRef,
153
122
  "data-testid": id
154
123
  }, children))))), document.body);
155
124
  };
@@ -4,8 +4,6 @@ var styles = {
4
4
  "modalLayer": "GenericModal-module_modalLayer__WfD1U",
5
5
  "transitionLayer": "GenericModal-module_transitionLayer__zTH-C",
6
6
  "animatingEnter": "GenericModal-module_animatingEnter__P3wuk",
7
- "animatingLeave": "GenericModal-module_animatingLeave__rNkKX",
8
- "unscrollable": "GenericModal-module_unscrollable__HjRaW",
9
- "pseudoScrollbar": "GenericModal-module_pseudoScrollbar__BhRqh"
7
+ "animatingLeave": "GenericModal-module_animatingLeave__rNkKX"
10
8
  };
11
9
  export { styles as default };