@instructure/ui-dialog 8.46.2-snapshot-8 → 8.46.2-snapshot-9
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/CHANGELOG.md +1 -1
- package/es/Dialog/__new-tests__/Dialog.test.js +479 -0
- package/lib/Dialog/__new-tests__/Dialog.test.js +482 -0
- package/package.json +12 -10
- package/src/Dialog/__new-tests__/Dialog.test.tsx +557 -0
- package/tsconfig.build.json +1 -2
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/Dialog/__new-tests__/Dialog.test.d.ts +2 -0
- package/types/Dialog/__new-tests__/Dialog.test.d.ts.map +1 -0
|
@@ -0,0 +1,482 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
5
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
6
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
7
|
+
var _react2 = require("@testing-library/react");
|
|
8
|
+
var _userEvent = require("@testing-library/user-event");
|
|
9
|
+
require("@testing-library/jest-dom");
|
|
10
|
+
var _index = require("../index");
|
|
11
|
+
var _button, _div, _div2, _DialogExample, _DialogExample2, _DialogExample3, _div3, _div4, _DialogExample4, _DialogExample5, _DialogExample6, _DialogExample7, _DialogExample8;
|
|
12
|
+
/*
|
|
13
|
+
* The MIT License (MIT)
|
|
14
|
+
*
|
|
15
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
16
|
+
*
|
|
17
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
18
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
19
|
+
* in the Software without restriction, including without limitation the rights
|
|
20
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
21
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
22
|
+
* furnished to do so, subject to the following conditions:
|
|
23
|
+
*
|
|
24
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
25
|
+
* copies or substantial portions of the Software.
|
|
26
|
+
*
|
|
27
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
28
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
29
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
30
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
31
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
32
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
33
|
+
* SOFTWARE.
|
|
34
|
+
*/
|
|
35
|
+
const TEST_TEXT = 'test-text';
|
|
36
|
+
const TEST_LABEL = 'test-label';
|
|
37
|
+
const renderDialog = props => {
|
|
38
|
+
const allProps = {
|
|
39
|
+
open: true,
|
|
40
|
+
label: TEST_LABEL,
|
|
41
|
+
...props
|
|
42
|
+
};
|
|
43
|
+
return (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Dialog, allProps, _button || (_button = /*#__PURE__*/_react.default.createElement("button", null, TEST_TEXT))));
|
|
44
|
+
};
|
|
45
|
+
const DialogExample = /*#__PURE__*/(0, _react.forwardRef)((props, ref) => {
|
|
46
|
+
const inputRef = (0, _react.useRef)(null);
|
|
47
|
+
const dialogRef = (0, _react.useRef)(null);
|
|
48
|
+
(0, _react.useEffect)(() => {
|
|
49
|
+
if (!props.open) {
|
|
50
|
+
inputRef.current.focus();
|
|
51
|
+
}
|
|
52
|
+
}, [props.open]);
|
|
53
|
+
(0, _react.useImperativeHandle)(ref, () => ({
|
|
54
|
+
focusDialog: () => dialogRef.current.focus(),
|
|
55
|
+
blurDialog: () => dialogRef.current.blur()
|
|
56
|
+
}));
|
|
57
|
+
return /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement("input", {
|
|
58
|
+
"data-testid": "input-trigger",
|
|
59
|
+
type: "text",
|
|
60
|
+
ref: inputRef
|
|
61
|
+
}), /*#__PURE__*/_react.default.createElement(_index.Dialog, Object.assign({
|
|
62
|
+
shouldContainFocus: true,
|
|
63
|
+
shouldReturnFocus: true,
|
|
64
|
+
label: TEST_LABEL
|
|
65
|
+
}, props, {
|
|
66
|
+
ref: dialogRef
|
|
67
|
+
}), props.children || _div || (_div = /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement("input", {
|
|
68
|
+
type: "text",
|
|
69
|
+
"data-testid": "input-one"
|
|
70
|
+
}), /*#__PURE__*/_react.default.createElement("input", {
|
|
71
|
+
type: "text",
|
|
72
|
+
"data-testid": "input-two"
|
|
73
|
+
})))));
|
|
74
|
+
});
|
|
75
|
+
DialogExample.displayName = 'DialogExample';
|
|
76
|
+
const NestedDialogExample = props => {
|
|
77
|
+
const _useState = (0, _react.useState)(false),
|
|
78
|
+
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
79
|
+
nestedOpen = _useState2[0],
|
|
80
|
+
setNestedOpen = _useState2[1];
|
|
81
|
+
const handleTriggerClick = () => setNestedOpen(true);
|
|
82
|
+
return /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement(_index.Dialog, Object.assign({
|
|
83
|
+
open: true,
|
|
84
|
+
shouldReturnFocus: true,
|
|
85
|
+
label: TEST_LABEL
|
|
86
|
+
}, props), /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement("input", {
|
|
87
|
+
onClick: handleTriggerClick,
|
|
88
|
+
type: "text",
|
|
89
|
+
"data-testid": "nested-input-one"
|
|
90
|
+
}), /*#__PURE__*/_react.default.createElement("input", {
|
|
91
|
+
onClick: handleTriggerClick,
|
|
92
|
+
type: "text",
|
|
93
|
+
"data-testid": "nested-input-two"
|
|
94
|
+
})), /*#__PURE__*/_react.default.createElement(_index.Dialog, {
|
|
95
|
+
open: nestedOpen,
|
|
96
|
+
label: TEST_LABEL
|
|
97
|
+
}, TEST_TEXT))));
|
|
98
|
+
};
|
|
99
|
+
NestedDialogExample.displayName = 'NestedDialogExample';
|
|
100
|
+
describe('<Dialog />', () => {
|
|
101
|
+
it('should render nothing when closed', () => {
|
|
102
|
+
const _renderDialog = renderDialog({
|
|
103
|
+
open: false
|
|
104
|
+
}),
|
|
105
|
+
container = _renderDialog.container;
|
|
106
|
+
expect(container.firstChild).not.toBeInTheDocument();
|
|
107
|
+
});
|
|
108
|
+
it('should render children when open', async () => {
|
|
109
|
+
const _renderDialog2 = renderDialog({
|
|
110
|
+
open: true
|
|
111
|
+
}),
|
|
112
|
+
container = _renderDialog2.container;
|
|
113
|
+
expect(container.firstChild).toBeInTheDocument();
|
|
114
|
+
expect(container.firstChild).toHaveTextContent(TEST_TEXT);
|
|
115
|
+
});
|
|
116
|
+
it('should apply the a11y attributes', () => {
|
|
117
|
+
const _renderDialog3 = renderDialog({
|
|
118
|
+
label: TEST_LABEL
|
|
119
|
+
}),
|
|
120
|
+
getByRole = _renderDialog3.getByRole,
|
|
121
|
+
getByLabelText = _renderDialog3.getByLabelText;
|
|
122
|
+
const dialog = getByRole('dialog');
|
|
123
|
+
const label = getByLabelText(TEST_LABEL);
|
|
124
|
+
expect(dialog).toBeInTheDocument();
|
|
125
|
+
expect(label).toBeInTheDocument();
|
|
126
|
+
});
|
|
127
|
+
it('should apply the role attributes, if explicitly passed', () => {
|
|
128
|
+
const _renderDialog4 = renderDialog({
|
|
129
|
+
label: TEST_LABEL,
|
|
130
|
+
role: 'region'
|
|
131
|
+
}),
|
|
132
|
+
getByRole = _renderDialog4.getByRole,
|
|
133
|
+
getByLabelText = _renderDialog4.getByLabelText;
|
|
134
|
+
const regionRole = getByRole('region');
|
|
135
|
+
const label = getByLabelText(TEST_LABEL);
|
|
136
|
+
expect(regionRole).toBeInTheDocument();
|
|
137
|
+
expect(label).toBeInTheDocument();
|
|
138
|
+
});
|
|
139
|
+
it('should call onDismiss prop when Esc key pressed', async () => {
|
|
140
|
+
const onDismiss = jest.fn();
|
|
141
|
+
const _renderDialog5 = renderDialog({
|
|
142
|
+
onDismiss
|
|
143
|
+
}),
|
|
144
|
+
getByRole = _renderDialog5.getByRole;
|
|
145
|
+
const dialog = getByRole('dialog');
|
|
146
|
+
await (0, _react2.waitFor)(() => {
|
|
147
|
+
_react2.fireEvent.keyUp(dialog, {
|
|
148
|
+
key: 'Escape',
|
|
149
|
+
code: 'Escape',
|
|
150
|
+
keyCode: 27,
|
|
151
|
+
charCode: 27
|
|
152
|
+
});
|
|
153
|
+
expect(onDismiss).toHaveBeenCalled();
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
it('should call onDismiss prop when the document is clicked', async () => {
|
|
157
|
+
const onDismiss = jest.fn();
|
|
158
|
+
renderDialog({
|
|
159
|
+
onDismiss,
|
|
160
|
+
shouldCloseOnDocumentClick: true
|
|
161
|
+
});
|
|
162
|
+
await (0, _react2.waitFor)(() => {
|
|
163
|
+
_react2.fireEvent.click(document);
|
|
164
|
+
expect(onDismiss).toHaveBeenCalled();
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
describe('managed focus', () => {
|
|
168
|
+
it('should provide focus method', async () => {
|
|
169
|
+
const _render = (0, _react2.render)( /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement(DialogExample, {
|
|
170
|
+
open: true,
|
|
171
|
+
contentElement: () => getByTestId('non-tabbable')
|
|
172
|
+
}, TEST_TEXT), _div2 || (_div2 = /*#__PURE__*/_react.default.createElement("div", {
|
|
173
|
+
tabIndex: -1,
|
|
174
|
+
"data-testid": "non-tabbable"
|
|
175
|
+
}, TEST_TEXT)))),
|
|
176
|
+
getByTestId = _render.getByTestId;
|
|
177
|
+
const nonTabbableContent = getByTestId('non-tabbable');
|
|
178
|
+
await (0, _react2.waitFor)(() => {
|
|
179
|
+
_userEvent.userEvent.tab();
|
|
180
|
+
expect(document.activeElement).toBe(nonTabbableContent);
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
it('should warn when trying to focus or blur a closed dialog', () => {
|
|
184
|
+
const consoleError = jest.spyOn(console, 'error').mockImplementation(() => {});
|
|
185
|
+
let ref;
|
|
186
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(DialogExample, {
|
|
187
|
+
open: false,
|
|
188
|
+
ref: el => ref = el
|
|
189
|
+
}));
|
|
190
|
+
ref.focusDialog();
|
|
191
|
+
expect(consoleError.mock.calls[0][0]).toBe("Warning: [Dialog] Can't focus a Dialog that isn't open.");
|
|
192
|
+
ref.blurDialog();
|
|
193
|
+
expect(consoleError.mock.calls[1][0]).toBe("Warning: [Dialog] Can't blur a Dialog that isn't open.");
|
|
194
|
+
consoleError.mockRestore();
|
|
195
|
+
});
|
|
196
|
+
it('should focus the first tabbable element by default', async () => {
|
|
197
|
+
const _render2 = (0, _react2.render)(_DialogExample || (_DialogExample = /*#__PURE__*/_react.default.createElement(DialogExample, {
|
|
198
|
+
open: true
|
|
199
|
+
}))),
|
|
200
|
+
getByTestId = _render2.getByTestId;
|
|
201
|
+
const inputOne = getByTestId('input-one');
|
|
202
|
+
await (0, _react2.waitFor)(() => {
|
|
203
|
+
expect(document.activeElement).toBe(inputOne);
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
it('should focus the first tabbable element when open prop becomes true', async () => {
|
|
207
|
+
const _render3 = (0, _react2.render)(_DialogExample2 || (_DialogExample2 = /*#__PURE__*/_react.default.createElement(DialogExample, {
|
|
208
|
+
open: false
|
|
209
|
+
}))),
|
|
210
|
+
rerender = _render3.rerender,
|
|
211
|
+
getByTestId = _render3.getByTestId;
|
|
212
|
+
const inputTrigger = getByTestId('input-trigger');
|
|
213
|
+
await (0, _react2.waitFor)(() => {
|
|
214
|
+
expect(document.activeElement).toBe(inputTrigger);
|
|
215
|
+
});
|
|
216
|
+
rerender(_DialogExample3 || (_DialogExample3 = /*#__PURE__*/_react.default.createElement(DialogExample, {
|
|
217
|
+
open: true
|
|
218
|
+
})));
|
|
219
|
+
const inputOne = getByTestId('input-one');
|
|
220
|
+
await (0, _react2.waitFor)(() => {
|
|
221
|
+
expect(document.activeElement).toBe(inputOne);
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
it('should take a prop for finding default focus', async () => {
|
|
225
|
+
const _render4 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(DialogExample, {
|
|
226
|
+
open: true,
|
|
227
|
+
defaultFocusElement: () => getByTestId('input-two')
|
|
228
|
+
})),
|
|
229
|
+
getByTestId = _render4.getByTestId;
|
|
230
|
+
const inputTwo = getByTestId('input-two');
|
|
231
|
+
await (0, _react2.waitFor)(() => {
|
|
232
|
+
expect(document.activeElement).toBe(inputTwo);
|
|
233
|
+
});
|
|
234
|
+
});
|
|
235
|
+
it('should still focus the defaultFocusElement when it is focusable but not tabbable', async () => {
|
|
236
|
+
const _render5 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(DialogExample, {
|
|
237
|
+
open: true,
|
|
238
|
+
defaultFocusElement: () => getByTestId('non-tabbable')
|
|
239
|
+
}, _div3 || (_div3 = /*#__PURE__*/_react.default.createElement("div", {
|
|
240
|
+
tabIndex: -1,
|
|
241
|
+
"data-testid": "non-tabbable"
|
|
242
|
+
}, TEST_TEXT)))),
|
|
243
|
+
getByTestId = _render5.getByTestId;
|
|
244
|
+
const nonTabbableContent = getByTestId('non-tabbable');
|
|
245
|
+
await (0, _react2.waitFor)(() => {
|
|
246
|
+
expect(document.activeElement).toBe(nonTabbableContent);
|
|
247
|
+
});
|
|
248
|
+
});
|
|
249
|
+
it('should focus the contentElement by default if focusable and no defaultFocusElement is provided', async () => {
|
|
250
|
+
const _render6 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement(DialogExample, {
|
|
251
|
+
open: true,
|
|
252
|
+
contentElement: () => getByTestId('non-tabbable')
|
|
253
|
+
}, TEST_TEXT), _div4 || (_div4 = /*#__PURE__*/_react.default.createElement("div", {
|
|
254
|
+
tabIndex: -1,
|
|
255
|
+
"data-testid": "non-tabbable"
|
|
256
|
+
}, TEST_TEXT)))),
|
|
257
|
+
getByTestId = _render6.getByTestId;
|
|
258
|
+
const nonTabbableContent = getByTestId('non-tabbable');
|
|
259
|
+
await (0, _react2.waitFor)(() => {
|
|
260
|
+
expect(document.activeElement).toBe(nonTabbableContent);
|
|
261
|
+
});
|
|
262
|
+
});
|
|
263
|
+
it('should focus the document body if there is no defaultFocusElement, tabbable elements, or focusable contentElement', async () => {
|
|
264
|
+
const _render7 = (0, _react2.render)(_DialogExample4 || (_DialogExample4 = /*#__PURE__*/_react.default.createElement(DialogExample, {
|
|
265
|
+
open: false
|
|
266
|
+
}, TEST_TEXT))),
|
|
267
|
+
rerender = _render7.rerender,
|
|
268
|
+
getByTestId = _render7.getByTestId;
|
|
269
|
+
const inputTrigger = getByTestId('input-trigger');
|
|
270
|
+
inputTrigger.focus();
|
|
271
|
+
rerender(_DialogExample5 || (_DialogExample5 = /*#__PURE__*/_react.default.createElement(DialogExample, {
|
|
272
|
+
open: true
|
|
273
|
+
}, TEST_TEXT)));
|
|
274
|
+
await (0, _react2.waitFor)(() => {
|
|
275
|
+
expect(document.activeElement).toBe(document.body);
|
|
276
|
+
});
|
|
277
|
+
});
|
|
278
|
+
it('should return focus', async () => {
|
|
279
|
+
const _render8 = (0, _react2.render)(_DialogExample6 || (_DialogExample6 = /*#__PURE__*/_react.default.createElement(DialogExample, {
|
|
280
|
+
open: false
|
|
281
|
+
}))),
|
|
282
|
+
rerender = _render8.rerender,
|
|
283
|
+
getByTestId = _render8.getByTestId;
|
|
284
|
+
expect(document.activeElement).toBe(getByTestId('input-trigger'));
|
|
285
|
+
rerender(_DialogExample7 || (_DialogExample7 = /*#__PURE__*/_react.default.createElement(DialogExample, {
|
|
286
|
+
open: true
|
|
287
|
+
})));
|
|
288
|
+
await (0, _react2.waitFor)(() => {
|
|
289
|
+
expect(document.activeElement).toBe(getByTestId('input-one'));
|
|
290
|
+
});
|
|
291
|
+
rerender(_DialogExample8 || (_DialogExample8 = /*#__PURE__*/_react.default.createElement(DialogExample, {
|
|
292
|
+
open: false
|
|
293
|
+
})));
|
|
294
|
+
await (0, _react2.waitFor)(() => {
|
|
295
|
+
expect(document.activeElement).toBe(getByTestId('input-trigger'));
|
|
296
|
+
});
|
|
297
|
+
});
|
|
298
|
+
describe('when focus leaves the first and last tabbable', () => {
|
|
299
|
+
it(`should NOT call onBlur when shouldContainFocus=true and tab pressing last tabbable`, async () => {
|
|
300
|
+
const onBlur = jest.fn();
|
|
301
|
+
const _render9 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(DialogExample, {
|
|
302
|
+
open: true,
|
|
303
|
+
onBlur: onBlur,
|
|
304
|
+
shouldContainFocus: true,
|
|
305
|
+
defaultFocusElement: () => getByTestId('input-two')
|
|
306
|
+
})),
|
|
307
|
+
getByTestId = _render9.getByTestId;
|
|
308
|
+
const inputOne = getByTestId('input-one');
|
|
309
|
+
const inputTwo = getByTestId('input-two');
|
|
310
|
+
await (0, _react2.waitFor)(() => {
|
|
311
|
+
expect(document.activeElement).toBe(inputTwo);
|
|
312
|
+
});
|
|
313
|
+
await (0, _react2.waitFor)(() => {
|
|
314
|
+
_userEvent.userEvent.tab();
|
|
315
|
+
expect(onBlur).not.toHaveBeenCalled();
|
|
316
|
+
expect(document.activeElement).toBe(inputOne);
|
|
317
|
+
});
|
|
318
|
+
});
|
|
319
|
+
it('should NOT call onBlur when shouldContainFocus=true and Shift+Tab pressing first tabbable', async () => {
|
|
320
|
+
const onBlur = jest.fn();
|
|
321
|
+
const _render10 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(DialogExample, {
|
|
322
|
+
open: true,
|
|
323
|
+
shouldContainFocus: true,
|
|
324
|
+
defaultFocusElement: () => getByTestId('input-one'),
|
|
325
|
+
onBlur: onBlur
|
|
326
|
+
})),
|
|
327
|
+
getByTestId = _render10.getByTestId;
|
|
328
|
+
const inputOne = getByTestId('input-one');
|
|
329
|
+
const inputTwo = getByTestId('input-two');
|
|
330
|
+
await (0, _react2.waitFor)(() => {
|
|
331
|
+
expect(document.activeElement).toBe(inputOne);
|
|
332
|
+
_react2.fireEvent.keyDown(inputOne, {
|
|
333
|
+
key: 'Tab',
|
|
334
|
+
code: 'Tab',
|
|
335
|
+
keyCode: 9,
|
|
336
|
+
charCode: 9,
|
|
337
|
+
shiftKey: true
|
|
338
|
+
});
|
|
339
|
+
expect(onBlur).not.toHaveBeenCalled();
|
|
340
|
+
expect(document.activeElement).toBe(inputTwo);
|
|
341
|
+
});
|
|
342
|
+
});
|
|
343
|
+
it('should call onBlur when shouldContainFocus=false and tab pressing last tabbable', async () => {
|
|
344
|
+
const onBlur = jest.fn();
|
|
345
|
+
const _render11 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(DialogExample, {
|
|
346
|
+
open: true,
|
|
347
|
+
shouldContainFocus: false,
|
|
348
|
+
defaultFocusElement: () => getByTestId('input-two'),
|
|
349
|
+
onBlur: onBlur
|
|
350
|
+
})),
|
|
351
|
+
getByTestId = _render11.getByTestId;
|
|
352
|
+
const inputTwo = getByTestId('input-two');
|
|
353
|
+
inputTwo.focus();
|
|
354
|
+
await (0, _react2.waitFor)(() => {
|
|
355
|
+
expect(document.activeElement).toBe(inputTwo);
|
|
356
|
+
_react2.fireEvent.keyDown(inputTwo, {
|
|
357
|
+
key: 'Tab',
|
|
358
|
+
code: 'Tab',
|
|
359
|
+
keyCode: 9,
|
|
360
|
+
charCode: 9
|
|
361
|
+
});
|
|
362
|
+
expect(onBlur).toHaveBeenCalled();
|
|
363
|
+
});
|
|
364
|
+
});
|
|
365
|
+
it('should call onBlur when shouldContainFocus=false and pressing Shift+Tab on the first tabbable', async () => {
|
|
366
|
+
const onBlur = jest.fn();
|
|
367
|
+
const _render12 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(DialogExample, {
|
|
368
|
+
open: true,
|
|
369
|
+
shouldContainFocus: false,
|
|
370
|
+
defaultFocusElement: () => getByTestId('input-one'),
|
|
371
|
+
onBlur: onBlur
|
|
372
|
+
})),
|
|
373
|
+
getByTestId = _render12.getByTestId;
|
|
374
|
+
const inputOne = getByTestId('input-one');
|
|
375
|
+
inputOne.focus();
|
|
376
|
+
await (0, _react2.waitFor)(() => {
|
|
377
|
+
expect(document.activeElement).toBe(inputOne);
|
|
378
|
+
_react2.fireEvent.keyDown(inputOne, {
|
|
379
|
+
key: 'Tab',
|
|
380
|
+
code: 'Tab',
|
|
381
|
+
keyCode: 9,
|
|
382
|
+
charCode: 9,
|
|
383
|
+
shiftKey: true
|
|
384
|
+
});
|
|
385
|
+
expect(onBlur).toHaveBeenCalled();
|
|
386
|
+
});
|
|
387
|
+
});
|
|
388
|
+
describe('when launching a dialog w/out focusable content from another dialog', () => {
|
|
389
|
+
it(`should contain focus when last tabbable element triggers dialog w/out focusable content`, async () => {
|
|
390
|
+
const onBlur = jest.fn();
|
|
391
|
+
const _render13 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(NestedDialogExample, {
|
|
392
|
+
onBlur: onBlur,
|
|
393
|
+
shouldContainFocus: true,
|
|
394
|
+
defaultFocusElement: () => getByTestId('nested-input-two')
|
|
395
|
+
})),
|
|
396
|
+
getByTestId = _render13.getByTestId;
|
|
397
|
+
const inputOne = getByTestId('nested-input-one');
|
|
398
|
+
const inputTwo = getByTestId('nested-input-two');
|
|
399
|
+
await (0, _react2.waitFor)(() => {
|
|
400
|
+
_userEvent.userEvent.click(inputTwo);
|
|
401
|
+
expect(document.activeElement).toBe(inputTwo);
|
|
402
|
+
_react2.fireEvent.keyDown(inputTwo, {
|
|
403
|
+
key: 'Tab',
|
|
404
|
+
code: 'Tab',
|
|
405
|
+
keyCode: 9,
|
|
406
|
+
charCode: 9
|
|
407
|
+
});
|
|
408
|
+
expect(onBlur).not.toHaveBeenCalled();
|
|
409
|
+
expect(document.activeElement).toBe(inputOne);
|
|
410
|
+
});
|
|
411
|
+
});
|
|
412
|
+
it('should contain focus when first tabbable element triggers dialog w/out focusable content', async () => {
|
|
413
|
+
const onBlur = jest.fn();
|
|
414
|
+
const _render14 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(NestedDialogExample, {
|
|
415
|
+
onBlur: onBlur,
|
|
416
|
+
shouldContainFocus: true,
|
|
417
|
+
defaultFocusElement: () => getByTestId('nested-input-one')
|
|
418
|
+
})),
|
|
419
|
+
getByTestId = _render14.getByTestId;
|
|
420
|
+
const inputOne = getByTestId('nested-input-one');
|
|
421
|
+
const inputTwo = getByTestId('nested-input-two');
|
|
422
|
+
await (0, _react2.waitFor)(() => {
|
|
423
|
+
_userEvent.userEvent.click(inputOne);
|
|
424
|
+
expect(document.activeElement).toBe(inputOne);
|
|
425
|
+
_react2.fireEvent.keyDown(inputOne, {
|
|
426
|
+
key: 'Tab',
|
|
427
|
+
code: 'Tab',
|
|
428
|
+
keyCode: 9,
|
|
429
|
+
charCode: 9,
|
|
430
|
+
shiftKey: true
|
|
431
|
+
});
|
|
432
|
+
expect(onBlur).not.toHaveBeenCalled();
|
|
433
|
+
expect(document.activeElement).toBe(inputTwo);
|
|
434
|
+
});
|
|
435
|
+
});
|
|
436
|
+
it(`should call onBlur when shouldContainFocus=false and last tabbable element triggers dialog w/out focusable content`, async () => {
|
|
437
|
+
const onBlur = jest.fn();
|
|
438
|
+
const _render15 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(NestedDialogExample, {
|
|
439
|
+
onBlur: onBlur,
|
|
440
|
+
shouldContainFocus: false,
|
|
441
|
+
defaultFocusElement: () => getByTestId('nested-input-two')
|
|
442
|
+
})),
|
|
443
|
+
getByTestId = _render15.getByTestId;
|
|
444
|
+
const inputTwo = getByTestId('nested-input-two');
|
|
445
|
+
await (0, _react2.waitFor)(() => {
|
|
446
|
+
_userEvent.userEvent.click(inputTwo);
|
|
447
|
+
expect(document.activeElement).toBe(inputTwo);
|
|
448
|
+
_react2.fireEvent.keyDown(inputTwo, {
|
|
449
|
+
key: 'Tab',
|
|
450
|
+
code: 'Tab',
|
|
451
|
+
keyCode: 9,
|
|
452
|
+
charCode: 9
|
|
453
|
+
});
|
|
454
|
+
expect(onBlur).toHaveBeenCalled();
|
|
455
|
+
});
|
|
456
|
+
});
|
|
457
|
+
it(`should call onBlur when shouldContainFocus=false and first tabbable element triggers dialog w/out focusable content`, async () => {
|
|
458
|
+
const onBlur = jest.fn();
|
|
459
|
+
const _render16 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(NestedDialogExample, {
|
|
460
|
+
onBlur: onBlur,
|
|
461
|
+
shouldContainFocus: false,
|
|
462
|
+
defaultFocusElement: () => getByTestId('nested-input-one')
|
|
463
|
+
})),
|
|
464
|
+
getByTestId = _render16.getByTestId;
|
|
465
|
+
const inputOne = getByTestId('nested-input-one');
|
|
466
|
+
await (0, _react2.waitFor)(() => {
|
|
467
|
+
_userEvent.userEvent.click(inputOne);
|
|
468
|
+
expect(document.activeElement).toBe(inputOne);
|
|
469
|
+
_react2.fireEvent.keyDown(inputOne, {
|
|
470
|
+
key: 'Tab',
|
|
471
|
+
code: 'Tab',
|
|
472
|
+
keyCode: 9,
|
|
473
|
+
charCode: 9,
|
|
474
|
+
shiftKey: true
|
|
475
|
+
});
|
|
476
|
+
expect(onBlur).toHaveBeenCalled();
|
|
477
|
+
});
|
|
478
|
+
});
|
|
479
|
+
});
|
|
480
|
+
});
|
|
481
|
+
});
|
|
482
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@instructure/ui-dialog",
|
|
3
|
-
"version": "8.46.2-snapshot-
|
|
3
|
+
"version": "8.46.2-snapshot-9",
|
|
4
4
|
"description": "A utility component for managing keyboard accessibility and screen reader behavior",
|
|
5
5
|
"author": "Instructure, Inc. Engineering and Product Design",
|
|
6
6
|
"module": "./es/index.js",
|
|
@@ -24,18 +24,20 @@
|
|
|
24
24
|
"license": "MIT",
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@babel/runtime": "^7.23.2",
|
|
27
|
-
"@instructure/shared-types": "8.46.2-snapshot-
|
|
28
|
-
"@instructure/ui-a11y-utils": "8.46.2-snapshot-
|
|
29
|
-
"@instructure/ui-dom-utils": "8.46.2-snapshot-
|
|
30
|
-
"@instructure/ui-react-utils": "8.46.2-snapshot-
|
|
31
|
-
"@instructure/ui-testable": "8.46.2-snapshot-
|
|
27
|
+
"@instructure/shared-types": "8.46.2-snapshot-9",
|
|
28
|
+
"@instructure/ui-a11y-utils": "8.46.2-snapshot-9",
|
|
29
|
+
"@instructure/ui-dom-utils": "8.46.2-snapshot-9",
|
|
30
|
+
"@instructure/ui-react-utils": "8.46.2-snapshot-9",
|
|
31
|
+
"@instructure/ui-testable": "8.46.2-snapshot-9",
|
|
32
32
|
"prop-types": "^15.8.1"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@instructure/console": "8.46.2-snapshot-
|
|
36
|
-
"@instructure/ui-babel-preset": "8.46.2-snapshot-
|
|
37
|
-
"@instructure/ui-prop-types": "8.46.2-snapshot-
|
|
38
|
-
"@
|
|
35
|
+
"@instructure/console": "8.46.2-snapshot-9",
|
|
36
|
+
"@instructure/ui-babel-preset": "8.46.2-snapshot-9",
|
|
37
|
+
"@instructure/ui-prop-types": "8.46.2-snapshot-9",
|
|
38
|
+
"@testing-library/jest-dom": "^6.1.4",
|
|
39
|
+
"@testing-library/react": "^14.0.0",
|
|
40
|
+
"@testing-library/user-event": "^14.5.1"
|
|
39
41
|
},
|
|
40
42
|
"peerDependencies": {
|
|
41
43
|
"react": ">=16.8 <=18"
|