@pingux/astro 1.15.0-alpha.0 → 1.15.0-alpha.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.
@@ -58,7 +58,7 @@ var _hooks = require("../../hooks");
|
|
58
58
|
|
59
59
|
var _react2 = require("@emotion/react");
|
60
60
|
|
61
|
-
var _excluded = ["className", "closeButton", "hasCloseButton", "id", "isClosedOnBlur", "isDismissable", "isKeyboardDismissDisabled", "isOpen", "role", "title", "onClose", "shouldCloseOnInteractOutside", "children", "contentProps", "containerProps"];
|
61
|
+
var _excluded = ["className", "closeButton", "hasAutoFocus", "hasCloseButton", "id", "isClosedOnBlur", "isDismissable", "isKeyboardDismissDisabled", "isOpen", "role", "title", "onClose", "shouldCloseOnInteractOutside", "children", "contentProps", "containerProps"];
|
62
62
|
|
63
63
|
function _getRequireWildcardCache(nodeInterop) { if (typeof _WeakMap !== "function") return null; var cacheBabelInterop = new _WeakMap(); var cacheNodeInterop = new _WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
64
64
|
|
@@ -71,6 +71,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
71
71
|
var Modal = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
72
72
|
var className = props.className,
|
73
73
|
closeButton = props.closeButton,
|
74
|
+
hasAutoFocus = props.hasAutoFocus,
|
74
75
|
hasCloseButton = props.hasCloseButton,
|
75
76
|
id = props.id,
|
76
77
|
isClosedOnBlur = props.isClosedOnBlur,
|
@@ -136,11 +137,12 @@ var Modal = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
136
137
|
}, others, containerProps), (0, _react2.jsx)(_focus.FocusScope, {
|
137
138
|
contain: true,
|
138
139
|
restoreFocus: true,
|
139
|
-
autoFocus:
|
140
|
+
autoFocus: hasAutoFocus
|
140
141
|
}, (0, _react2.jsx)(_Box["default"], (0, _extends2["default"])({
|
141
142
|
variant: "modal.content"
|
142
143
|
}, propsContentProps, overlayProps, dialogProps, modalProps, {
|
143
|
-
ref: modalRef
|
144
|
+
ref: modalRef,
|
145
|
+
"aria-modal": true
|
144
146
|
}), hasCloseButton && (closeButton !== null && closeButton !== void 0 ? closeButton : (0, _react2.jsx)(_IconButton["default"], {
|
145
147
|
"aria-label": "Close modal window",
|
146
148
|
"data-id": "icon-button__close-modal-window",
|
@@ -160,6 +162,9 @@ Modal.propTypes = {
|
|
160
162
|
/** The element's unique identifier. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/id). */
|
161
163
|
id: _propTypes["default"].string,
|
162
164
|
|
165
|
+
/** Whether to auto focus the first focusable element in the focus scope on mount. */
|
166
|
+
hasAutoFocus: _propTypes["default"].bool,
|
167
|
+
|
163
168
|
/** Whether the modal has a visible close button. */
|
164
169
|
hasCloseButton: _propTypes["default"].bool,
|
165
170
|
|
@@ -27,7 +27,8 @@ var getComponent = function getComponent() {
|
|
27
27
|
(0, _testAxe["default"])(getComponent);
|
28
28
|
test('default modal', function () {
|
29
29
|
getComponent();
|
30
|
-
expect(_testWrapper.screen.queryByRole('dialog')).toBeInTheDocument();
|
30
|
+
expect(_testWrapper.screen.queryByRole('dialog')).toBeInTheDocument();
|
31
|
+
expect(_testWrapper.screen.queryByRole('dialog')).toHaveAttribute('aria-modal', 'true'); // Close button not rendered by default
|
31
32
|
|
32
33
|
expect(_testWrapper.screen.queryByRole('button')).not.toBeInTheDocument();
|
33
34
|
});
|
@@ -199,4 +200,23 @@ test('should render a custom close button if hasCloseButton is true and custom b
|
|
199
200
|
});
|
200
201
|
expect(_testWrapper.screen.queryByRole('button')).not.toBeInTheDocument();
|
201
202
|
expect(_testWrapper.screen.queryByTestId('test')).toBeInTheDocument();
|
203
|
+
});
|
204
|
+
test('shouldn\'t auto focus the first tabbable element', function () {
|
205
|
+
getComponent({
|
206
|
+
hasCloseButton: true
|
207
|
+
});
|
208
|
+
|
209
|
+
var button = _testWrapper.screen.queryByRole('button');
|
210
|
+
|
211
|
+
expect(button).not.toHaveFocus();
|
212
|
+
});
|
213
|
+
test('should auto focus the first tabbable element if "hasAutoFocus" is true', function () {
|
214
|
+
getComponent({
|
215
|
+
hasCloseButton: true,
|
216
|
+
hasAutoFocus: true
|
217
|
+
});
|
218
|
+
|
219
|
+
var button = _testWrapper.screen.queryByRole('button');
|
220
|
+
|
221
|
+
expect(button).toHaveFocus();
|
202
222
|
});
|
@@ -9,7 +9,7 @@ import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys";
|
|
9
9
|
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
10
10
|
import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
11
11
|
import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
|
12
|
-
var _excluded = ["className", "closeButton", "hasCloseButton", "id", "isClosedOnBlur", "isDismissable", "isKeyboardDismissDisabled", "isOpen", "role", "title", "onClose", "shouldCloseOnInteractOutside", "children", "contentProps", "containerProps"];
|
12
|
+
var _excluded = ["className", "closeButton", "hasAutoFocus", "hasCloseButton", "id", "isClosedOnBlur", "isDismissable", "isKeyboardDismissDisabled", "isOpen", "role", "title", "onClose", "shouldCloseOnInteractOutside", "children", "contentProps", "containerProps"];
|
13
13
|
|
14
14
|
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
15
15
|
|
@@ -30,6 +30,7 @@ import { jsx as ___EmotionJSX } from "@emotion/react";
|
|
30
30
|
var Modal = /*#__PURE__*/forwardRef(function (props, ref) {
|
31
31
|
var className = props.className,
|
32
32
|
closeButton = props.closeButton,
|
33
|
+
hasAutoFocus = props.hasAutoFocus,
|
33
34
|
hasCloseButton = props.hasCloseButton,
|
34
35
|
id = props.id,
|
35
36
|
isClosedOnBlur = props.isClosedOnBlur,
|
@@ -95,11 +96,12 @@ var Modal = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
95
96
|
}, others, containerProps), ___EmotionJSX(FocusScope, {
|
96
97
|
contain: true,
|
97
98
|
restoreFocus: true,
|
98
|
-
autoFocus:
|
99
|
+
autoFocus: hasAutoFocus
|
99
100
|
}, ___EmotionJSX(Box, _extends({
|
100
101
|
variant: "modal.content"
|
101
102
|
}, propsContentProps, overlayProps, dialogProps, modalProps, {
|
102
|
-
ref: modalRef
|
103
|
+
ref: modalRef,
|
104
|
+
"aria-modal": true
|
103
105
|
}), hasCloseButton && (closeButton !== null && closeButton !== void 0 ? closeButton : ___EmotionJSX(IconButton, {
|
104
106
|
"aria-label": "Close modal window",
|
105
107
|
"data-id": "icon-button__close-modal-window",
|
@@ -119,6 +121,9 @@ Modal.propTypes = {
|
|
119
121
|
/** The element's unique identifier. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/id). */
|
120
122
|
id: PropTypes.string,
|
121
123
|
|
124
|
+
/** Whether to auto focus the first focusable element in the focus scope on mount. */
|
125
|
+
hasAutoFocus: PropTypes.bool,
|
126
|
+
|
122
127
|
/** Whether the modal has a visible close button. */
|
123
128
|
hasCloseButton: PropTypes.bool,
|
124
129
|
|
@@ -18,7 +18,8 @@ var getComponent = function getComponent() {
|
|
18
18
|
axeTest(getComponent);
|
19
19
|
test('default modal', function () {
|
20
20
|
getComponent();
|
21
|
-
expect(screen.queryByRole('dialog')).toBeInTheDocument();
|
21
|
+
expect(screen.queryByRole('dialog')).toBeInTheDocument();
|
22
|
+
expect(screen.queryByRole('dialog')).toHaveAttribute('aria-modal', 'true'); // Close button not rendered by default
|
22
23
|
|
23
24
|
expect(screen.queryByRole('button')).not.toBeInTheDocument();
|
24
25
|
});
|
@@ -169,4 +170,19 @@ test('should render a custom close button if hasCloseButton is true and custom b
|
|
169
170
|
});
|
170
171
|
expect(screen.queryByRole('button')).not.toBeInTheDocument();
|
171
172
|
expect(screen.queryByTestId('test')).toBeInTheDocument();
|
173
|
+
});
|
174
|
+
test('shouldn\'t auto focus the first tabbable element', function () {
|
175
|
+
getComponent({
|
176
|
+
hasCloseButton: true
|
177
|
+
});
|
178
|
+
var button = screen.queryByRole('button');
|
179
|
+
expect(button).not.toHaveFocus();
|
180
|
+
});
|
181
|
+
test('should auto focus the first tabbable element if "hasAutoFocus" is true', function () {
|
182
|
+
getComponent({
|
183
|
+
hasCloseButton: true,
|
184
|
+
hasAutoFocus: true
|
185
|
+
});
|
186
|
+
var button = screen.queryByRole('button');
|
187
|
+
expect(button).toHaveFocus();
|
172
188
|
});
|