@instructure/ui-modal 10.16.1-snapshot-0 → 10.16.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.
- package/CHANGELOG.md +1 -1
- package/es/Modal/ModalBody/__new-tests__/ModalBody.test.js +21 -12
- package/es/Modal/ModalBody/index.js +10 -6
- package/es/Modal/ModalFooter/__new-tests__/ModalFooter.test.js +8 -5
- package/es/Modal/ModalFooter/index.js +8 -7
- package/es/Modal/ModalHeader/__new-tests__/ModalHeader.test.js +19 -12
- package/es/Modal/ModalHeader/index.js +10 -9
- package/es/Modal/__new-tests__/Modal.test.js +185 -97
- package/es/Modal/index.js +33 -25
- package/lib/Modal/ModalBody/__new-tests__/ModalBody.test.js +22 -13
- package/lib/Modal/ModalBody/index.js +9 -5
- package/lib/Modal/ModalFooter/__new-tests__/ModalFooter.test.js +9 -6
- package/lib/Modal/ModalFooter/index.js +7 -6
- package/lib/Modal/ModalHeader/__new-tests__/ModalHeader.test.js +20 -13
- package/lib/Modal/ModalHeader/index.js +9 -9
- package/lib/Modal/__new-tests__/Modal.test.js +185 -97
- package/lib/Modal/index.js +32 -24
- package/package.json +19 -19
- package/src/Modal/ModalBody/__new-tests__/ModalBody.test.tsx +0 -2
- package/src/Modal/ModalBody/index.tsx +1 -2
- package/src/Modal/ModalFooter/__new-tests__/ModalFooter.test.tsx +0 -2
- package/src/Modal/ModalFooter/index.tsx +1 -2
- package/src/Modal/ModalHeader/__new-tests__/ModalHeader.test.tsx +0 -2
- package/src/Modal/ModalHeader/index.tsx +4 -5
- package/src/Modal/__new-tests__/Modal.test.tsx +3 -5
- package/src/Modal/index.tsx +1 -2
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/Modal/ModalBody/__new-tests__/ModalBody.test.d.ts.map +1 -1
- package/types/Modal/ModalBody/index.d.ts +1 -3
- package/types/Modal/ModalBody/index.d.ts.map +1 -1
- package/types/Modal/ModalFooter/__new-tests__/ModalFooter.test.d.ts.map +1 -1
- package/types/Modal/ModalFooter/index.d.ts +1 -3
- package/types/Modal/ModalFooter/index.d.ts.map +1 -1
- package/types/Modal/ModalHeader/__new-tests__/ModalHeader.test.d.ts.map +1 -1
- package/types/Modal/ModalHeader/index.d.ts +2 -4
- package/types/Modal/ModalHeader/index.d.ts.map +1 -1
- package/types/Modal/index.d.ts +2 -4
- package/types/Modal/index.d.ts.map +1 -1
|
@@ -25,13 +25,14 @@ var _Modal, _Modal2, _Modal$Body, _Modal3, _Modal4, _View, _Modal5, _Modal$Body2
|
|
|
25
25
|
* SOFTWARE.
|
|
26
26
|
*/
|
|
27
27
|
|
|
28
|
-
import
|
|
28
|
+
import { Component } from 'react';
|
|
29
29
|
import { render, waitFor } from '@testing-library/react';
|
|
30
30
|
import { vi } from 'vitest';
|
|
31
31
|
import userEvent from '@testing-library/user-event';
|
|
32
32
|
import '@testing-library/jest-dom';
|
|
33
33
|
import { Modal } from '../index';
|
|
34
34
|
import { View } from '@instructure/ui-view';
|
|
35
|
+
import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
35
36
|
describe('<Modal />', () => {
|
|
36
37
|
let consoleWarningMock;
|
|
37
38
|
let consoleErrorMock;
|
|
@@ -56,25 +57,31 @@ describe('<Modal />', () => {
|
|
|
56
57
|
window.scroll = originalScroll;
|
|
57
58
|
});
|
|
58
59
|
it('should render nothing and have a node with no parent when closed', () => {
|
|
59
|
-
const _render = render(_Modal || (_Modal =
|
|
60
|
+
const _render = render(_Modal || (_Modal = _jsx(Modal, {
|
|
60
61
|
label: "Modal Dialog",
|
|
61
|
-
shouldReturnFocus: false
|
|
62
|
-
|
|
62
|
+
shouldReturnFocus: false,
|
|
63
|
+
children: _jsx(Modal.Body, {
|
|
64
|
+
children: "Foo Bar Baz"
|
|
65
|
+
})
|
|
66
|
+
}))),
|
|
63
67
|
container = _render.container;
|
|
64
68
|
expect(container.firstChild).not.toBeInTheDocument();
|
|
65
69
|
});
|
|
66
70
|
it('should apply theme overrides when open', async () => {
|
|
67
71
|
const testFont = 'test-font';
|
|
68
72
|
const bodyText = 'Modal-body-text';
|
|
69
|
-
const _render2 = render(
|
|
73
|
+
const _render2 = render(_jsx(Modal, {
|
|
70
74
|
open: true,
|
|
71
75
|
size: "small",
|
|
72
76
|
label: "Modal Dialog",
|
|
73
77
|
shouldReturnFocus: false,
|
|
74
78
|
themeOverride: {
|
|
75
79
|
fontFamily: testFont
|
|
76
|
-
}
|
|
77
|
-
|
|
80
|
+
},
|
|
81
|
+
children: _jsx(Modal.Body, {
|
|
82
|
+
children: bodyText
|
|
83
|
+
})
|
|
84
|
+
})),
|
|
78
85
|
findByText = _render2.findByText,
|
|
79
86
|
findByRole = _render2.findByRole;
|
|
80
87
|
const modalBody = await findByText(bodyText);
|
|
@@ -84,12 +91,15 @@ describe('<Modal />', () => {
|
|
|
84
91
|
expect(dialogStyle.fontFamily).toBe(testFont);
|
|
85
92
|
});
|
|
86
93
|
it('should render its own positioning context if constrained to parent', async () => {
|
|
87
|
-
const _render3 = render(_Modal2 || (_Modal2 =
|
|
94
|
+
const _render3 = render(_Modal2 || (_Modal2 = _jsx(Modal, {
|
|
88
95
|
open: true,
|
|
89
96
|
label: "Modal Dialog",
|
|
90
97
|
shouldReturnFocus: false,
|
|
91
|
-
constrain: "parent"
|
|
92
|
-
|
|
98
|
+
constrain: "parent",
|
|
99
|
+
children: _jsx(Modal.Body, {
|
|
100
|
+
children: "Foo Bar Baz"
|
|
101
|
+
})
|
|
102
|
+
}))),
|
|
93
103
|
findByRole = _render3.findByRole;
|
|
94
104
|
const dialog = await findByRole('dialog');
|
|
95
105
|
const constrain = document.querySelector("[class*='constrainContext']");
|
|
@@ -97,19 +107,23 @@ describe('<Modal />', () => {
|
|
|
97
107
|
expect(constrain).toBeInTheDocument();
|
|
98
108
|
});
|
|
99
109
|
it("should not inherit its parent's font color", async () => {
|
|
100
|
-
const _render4 = render(
|
|
110
|
+
const _render4 = render(_jsx("div", {
|
|
101
111
|
style: {
|
|
102
112
|
color: 'rgb(255, 255, 255)'
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
+
},
|
|
114
|
+
children: _jsx(Modal, {
|
|
115
|
+
open: true,
|
|
116
|
+
label: "Modal Dialog",
|
|
117
|
+
shouldReturnFocus: false,
|
|
118
|
+
constrain: "parent",
|
|
119
|
+
themeOverride: {
|
|
120
|
+
textColor: 'rgb(0, 0, 0)'
|
|
121
|
+
},
|
|
122
|
+
children: _Modal$Body || (_Modal$Body = _jsx(Modal.Body, {
|
|
123
|
+
children: "Foo Bar Baz"
|
|
124
|
+
}))
|
|
125
|
+
})
|
|
126
|
+
})),
|
|
113
127
|
findByRole = _render4.findByRole;
|
|
114
128
|
const dialog = await findByRole('dialog');
|
|
115
129
|
const dialogStyle = window.getComputedStyle(dialog);
|
|
@@ -117,43 +131,57 @@ describe('<Modal />', () => {
|
|
|
117
131
|
expect(dialogStyle.color).toBe('rgb(0, 0, 0)');
|
|
118
132
|
});
|
|
119
133
|
it('should pass `as` prop to the dialog', async () => {
|
|
120
|
-
const _render5 = render(_Modal3 || (_Modal3 =
|
|
134
|
+
const _render5 = render(_Modal3 || (_Modal3 = _jsx(Modal, {
|
|
121
135
|
open: true,
|
|
122
136
|
label: "Modal Dialog",
|
|
123
|
-
shouldReturnFocus: false
|
|
124
|
-
|
|
137
|
+
shouldReturnFocus: false,
|
|
138
|
+
children: _jsx(Modal.Body, {
|
|
139
|
+
children: "Foo Bar Baz"
|
|
140
|
+
})
|
|
141
|
+
}))),
|
|
125
142
|
findByRole = _render5.findByRole,
|
|
126
143
|
rerender = _render5.rerender;
|
|
127
144
|
const dialog = await findByRole('dialog');
|
|
128
145
|
expect(dialog).toBeInTheDocument();
|
|
129
146
|
expect(dialog.tagName).toBe('SPAN');
|
|
130
|
-
rerender(_Modal4 || (_Modal4 =
|
|
147
|
+
rerender(_Modal4 || (_Modal4 = _jsx(Modal, {
|
|
131
148
|
as: "form",
|
|
132
149
|
open: true,
|
|
133
150
|
label: "Modal Dialog",
|
|
134
|
-
shouldReturnFocus: false
|
|
135
|
-
|
|
151
|
+
shouldReturnFocus: false,
|
|
152
|
+
children: _jsx(Modal.Body, {
|
|
153
|
+
children: "Foo Bar Baz"
|
|
154
|
+
})
|
|
155
|
+
})));
|
|
136
156
|
const dialogForm = await findByRole('dialog');
|
|
137
157
|
expect(dialogForm.tagName).toBe('FORM');
|
|
138
158
|
});
|
|
139
159
|
it('should handle null children', async () => {
|
|
140
160
|
const bodyText = 'Modal-body-text';
|
|
141
|
-
const _render6 = render(
|
|
161
|
+
const _render6 = render(_jsxs(Modal, {
|
|
142
162
|
open: true,
|
|
143
163
|
label: "Modal Dialog",
|
|
144
|
-
shouldReturnFocus: false
|
|
145
|
-
|
|
164
|
+
shouldReturnFocus: false,
|
|
165
|
+
children: [null, _jsx(Modal.Body, {
|
|
166
|
+
children: bodyText
|
|
167
|
+
}), null]
|
|
168
|
+
})),
|
|
146
169
|
findByText = _render6.findByText;
|
|
147
170
|
const modalBody = await findByText(bodyText);
|
|
148
171
|
expect(modalBody).toBeInTheDocument();
|
|
149
172
|
});
|
|
150
173
|
it('should handle custom children', async () => {
|
|
151
174
|
const bodyText = 'Modal-body-text';
|
|
152
|
-
const _render7 = render(
|
|
175
|
+
const _render7 = render(_jsxs(Modal, {
|
|
153
176
|
open: true,
|
|
154
177
|
label: "Modal Dialog",
|
|
155
|
-
shouldReturnFocus: false
|
|
156
|
-
|
|
178
|
+
shouldReturnFocus: false,
|
|
179
|
+
children: [_View || (_View = _jsx(View, {
|
|
180
|
+
children: "This is a custom child"
|
|
181
|
+
})), _jsx(Modal.Body, {
|
|
182
|
+
children: bodyText
|
|
183
|
+
})]
|
|
184
|
+
})),
|
|
157
185
|
findByText = _render7.findByText;
|
|
158
186
|
const modalBody = await findByText(bodyText);
|
|
159
187
|
const customChild = await findByText('This is a custom child');
|
|
@@ -161,11 +189,14 @@ describe('<Modal />', () => {
|
|
|
161
189
|
expect(customChild).toBeInTheDocument();
|
|
162
190
|
});
|
|
163
191
|
it('should apply the aria attributes', async () => {
|
|
164
|
-
const _render8 = render(_Modal5 || (_Modal5 =
|
|
192
|
+
const _render8 = render(_Modal5 || (_Modal5 = _jsx(Modal, {
|
|
165
193
|
open: true,
|
|
166
194
|
label: "Modal Dialog",
|
|
167
|
-
shouldReturnFocus: false
|
|
168
|
-
|
|
195
|
+
shouldReturnFocus: false,
|
|
196
|
+
children: _jsx(Modal.Body, {
|
|
197
|
+
children: "Foo Bar Baz"
|
|
198
|
+
})
|
|
199
|
+
}))),
|
|
169
200
|
findByRole = _render8.findByRole;
|
|
170
201
|
const dialog = await findByRole('dialog');
|
|
171
202
|
expect(dialog).toBeInTheDocument();
|
|
@@ -175,15 +206,18 @@ describe('<Modal />', () => {
|
|
|
175
206
|
const onEnter = vi.fn();
|
|
176
207
|
const onEntering = vi.fn();
|
|
177
208
|
const onEntered = vi.fn();
|
|
178
|
-
const _render9 = render(
|
|
209
|
+
const _render9 = render(_jsx(Modal, {
|
|
179
210
|
open: true,
|
|
180
211
|
onEnter: onEnter,
|
|
181
212
|
onEntering: onEntering,
|
|
182
213
|
onEntered: onEntered,
|
|
183
214
|
transition: "fade",
|
|
184
215
|
label: "Modal Dialog",
|
|
185
|
-
shouldReturnFocus: false
|
|
186
|
-
|
|
216
|
+
shouldReturnFocus: false,
|
|
217
|
+
children: _Modal$Body2 || (_Modal$Body2 = _jsx(Modal.Body, {
|
|
218
|
+
children: "Foo Bar Baz"
|
|
219
|
+
}))
|
|
220
|
+
})),
|
|
187
221
|
findByRole = _render9.findByRole;
|
|
188
222
|
const dialog = await findByRole('dialog');
|
|
189
223
|
expect(dialog).toBeInTheDocument();
|
|
@@ -195,12 +229,15 @@ describe('<Modal />', () => {
|
|
|
195
229
|
});
|
|
196
230
|
it('should support onOpen prop', async () => {
|
|
197
231
|
const onOpen = vi.fn();
|
|
198
|
-
const _render10 = render(
|
|
232
|
+
const _render10 = render(_jsx(Modal, {
|
|
199
233
|
open: true,
|
|
200
234
|
onOpen: onOpen,
|
|
201
235
|
label: "Modal Dialog",
|
|
202
|
-
shouldReturnFocus: false
|
|
203
|
-
|
|
236
|
+
shouldReturnFocus: false,
|
|
237
|
+
children: _Modal$Body3 || (_Modal$Body3 = _jsx(Modal.Body, {
|
|
238
|
+
children: "Foo Bar Baz"
|
|
239
|
+
}))
|
|
240
|
+
})),
|
|
204
241
|
findByRole = _render10.findByRole;
|
|
205
242
|
const dialog = await findByRole('dialog');
|
|
206
243
|
expect(dialog).toBeInTheDocument();
|
|
@@ -210,34 +247,43 @@ describe('<Modal />', () => {
|
|
|
210
247
|
});
|
|
211
248
|
it('should support onClose prop', async () => {
|
|
212
249
|
const onClose = vi.fn();
|
|
213
|
-
const _render11 = render(
|
|
250
|
+
const _render11 = render(_jsx(Modal, {
|
|
214
251
|
open: true,
|
|
215
252
|
onClose: onClose,
|
|
216
253
|
label: "Modal Dialog",
|
|
217
|
-
shouldReturnFocus: false
|
|
218
|
-
|
|
254
|
+
shouldReturnFocus: false,
|
|
255
|
+
children: _Modal$Body4 || (_Modal$Body4 = _jsx(Modal.Body, {
|
|
256
|
+
children: "Foo Bar Baz"
|
|
257
|
+
}))
|
|
258
|
+
})),
|
|
219
259
|
findByRole = _render11.findByRole,
|
|
220
260
|
rerender = _render11.rerender;
|
|
221
261
|
const dialog = await findByRole('dialog');
|
|
222
262
|
expect(dialog).toBeInTheDocument();
|
|
223
|
-
rerender(
|
|
263
|
+
rerender(_jsx(Modal, {
|
|
224
264
|
open: false,
|
|
225
265
|
onClose: onClose,
|
|
226
266
|
label: "Modal Dialog",
|
|
227
|
-
shouldReturnFocus: false
|
|
228
|
-
|
|
267
|
+
shouldReturnFocus: false,
|
|
268
|
+
children: _Modal$Body5 || (_Modal$Body5 = _jsx(Modal.Body, {
|
|
269
|
+
children: "Foo Bar Baz"
|
|
270
|
+
}))
|
|
271
|
+
}));
|
|
229
272
|
await waitFor(() => {
|
|
230
273
|
expect(onClose).toHaveBeenCalled();
|
|
231
274
|
});
|
|
232
275
|
});
|
|
233
276
|
it('should dismiss when overlay clicked by default', async () => {
|
|
234
277
|
const onDismiss = vi.fn();
|
|
235
|
-
const _render12 = render(
|
|
278
|
+
const _render12 = render(_jsx(Modal, {
|
|
236
279
|
open: true,
|
|
237
280
|
onDismiss: onDismiss,
|
|
238
281
|
label: "Modal Dialog",
|
|
239
|
-
shouldReturnFocus: false
|
|
240
|
-
|
|
282
|
+
shouldReturnFocus: false,
|
|
283
|
+
children: _Modal$Body6 || (_Modal$Body6 = _jsx(Modal.Body, {
|
|
284
|
+
children: "Modal Text"
|
|
285
|
+
}))
|
|
286
|
+
})),
|
|
241
287
|
findByText = _render12.findByText;
|
|
242
288
|
const modalBody = await findByText('Modal Text');
|
|
243
289
|
expect(modalBody).toBeInTheDocument();
|
|
@@ -249,16 +295,24 @@ describe('<Modal />', () => {
|
|
|
249
295
|
it('should NOT dismiss when overlay clicked with shouldCloseOnDocumentClick=false', async () => {
|
|
250
296
|
const onDismiss = vi.fn();
|
|
251
297
|
const onClickOuter = vi.fn();
|
|
252
|
-
const _render13 = render(
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
298
|
+
const _render13 = render(_jsxs("div", {
|
|
299
|
+
children: [_jsx("button", {
|
|
300
|
+
"data-testid": "outer-element",
|
|
301
|
+
onClick: onClickOuter,
|
|
302
|
+
children: "for dismiss"
|
|
303
|
+
}), _jsx(Modal, {
|
|
304
|
+
open: true,
|
|
305
|
+
onDismiss: onDismiss,
|
|
306
|
+
label: "Modal Dialog",
|
|
307
|
+
shouldReturnFocus: false,
|
|
308
|
+
shouldCloseOnDocumentClick: false,
|
|
309
|
+
children: _Modal$Body7 || (_Modal$Body7 = _jsxs(Modal.Body, {
|
|
310
|
+
children: ["Foo Bar Baz ", _jsx("button", {
|
|
311
|
+
children: "click me"
|
|
312
|
+
})]
|
|
313
|
+
}))
|
|
314
|
+
})]
|
|
315
|
+
})),
|
|
262
316
|
findByRole = _render13.findByRole,
|
|
263
317
|
getByTestId = _render13.getByTestId;
|
|
264
318
|
const dialog = await findByRole('dialog');
|
|
@@ -271,22 +325,36 @@ describe('<Modal />', () => {
|
|
|
271
325
|
});
|
|
272
326
|
});
|
|
273
327
|
it('should render children', async () => {
|
|
274
|
-
const _render14 = render(_Modal6 || (_Modal6 =
|
|
328
|
+
const _render14 = render(_Modal6 || (_Modal6 = _jsx(Modal, {
|
|
275
329
|
open: true,
|
|
276
330
|
label: "Modal Dialog",
|
|
277
|
-
shouldReturnFocus: false
|
|
278
|
-
|
|
331
|
+
shouldReturnFocus: false,
|
|
332
|
+
children: _jsx(Modal.Body, {
|
|
333
|
+
children: _jsx("button", {
|
|
334
|
+
children: "Cancel"
|
|
335
|
+
})
|
|
336
|
+
})
|
|
337
|
+
}))),
|
|
279
338
|
findByText = _render14.findByText;
|
|
280
339
|
const cancelButton = await findByText('Cancel');
|
|
281
340
|
expect(cancelButton).toBeInTheDocument();
|
|
282
341
|
});
|
|
283
342
|
describe('children validation', () => {
|
|
284
343
|
it('should pass validation when children are valid', async () => {
|
|
285
|
-
const _render15 = render(_Modal7 || (_Modal7 =
|
|
344
|
+
const _render15 = render(_Modal7 || (_Modal7 = _jsxs(Modal, {
|
|
286
345
|
open: true,
|
|
287
346
|
label: "Modal Dialog",
|
|
288
|
-
shouldReturnFocus: false
|
|
289
|
-
|
|
347
|
+
shouldReturnFocus: false,
|
|
348
|
+
children: [_jsx(Modal.Header, {
|
|
349
|
+
children: "Hello World"
|
|
350
|
+
}), _jsx(Modal.Body, {
|
|
351
|
+
children: "Foo Bar Baz"
|
|
352
|
+
}), _jsx(Modal.Footer, {
|
|
353
|
+
children: _jsx("button", {
|
|
354
|
+
children: "Cancel"
|
|
355
|
+
})
|
|
356
|
+
})]
|
|
357
|
+
}))),
|
|
290
358
|
findByRole = _render15.findByRole;
|
|
291
359
|
const dialog = await findByRole('dialog');
|
|
292
360
|
expect(dialog).toBeInTheDocument();
|
|
@@ -296,18 +364,22 @@ describe('<Modal />', () => {
|
|
|
296
364
|
let headerRef = null;
|
|
297
365
|
let bodyRef = null;
|
|
298
366
|
let footerRef = null;
|
|
299
|
-
const _render16 = render(
|
|
367
|
+
const _render16 = render(_jsxs(Modal, {
|
|
300
368
|
open: true,
|
|
301
369
|
label: "Dark Modal",
|
|
302
370
|
shouldReturnFocus: false,
|
|
303
|
-
variant: "inverse"
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
371
|
+
variant: "inverse",
|
|
372
|
+
children: [_jsx(Modal.Header, {
|
|
373
|
+
ref: el => headerRef = el,
|
|
374
|
+
children: "header"
|
|
375
|
+
}), _jsx(Modal.Body, {
|
|
376
|
+
ref: el => bodyRef = el,
|
|
377
|
+
children: "body"
|
|
378
|
+
}), _jsx(Modal.Footer, {
|
|
379
|
+
ref: el => footerRef = el,
|
|
380
|
+
children: "footer"
|
|
381
|
+
})]
|
|
382
|
+
})),
|
|
311
383
|
findByRole = _render16.findByRole;
|
|
312
384
|
const dialog = await findByRole('dialog');
|
|
313
385
|
expect(dialog).toBeInTheDocument();
|
|
@@ -317,14 +389,16 @@ describe('<Modal />', () => {
|
|
|
317
389
|
});
|
|
318
390
|
it('should pass overflow to Modal.Body', async () => {
|
|
319
391
|
let bodyRef = null;
|
|
320
|
-
const _render17 = render(
|
|
392
|
+
const _render17 = render(_jsx(Modal, {
|
|
321
393
|
open: true,
|
|
322
394
|
label: "Modal",
|
|
323
395
|
shouldReturnFocus: false,
|
|
324
|
-
overflow: "fit"
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
396
|
+
overflow: "fit",
|
|
397
|
+
children: _jsx(Modal.Body, {
|
|
398
|
+
ref: el => bodyRef = el,
|
|
399
|
+
children: "body"
|
|
400
|
+
})
|
|
401
|
+
})),
|
|
328
402
|
findByRole = _render17.findByRole;
|
|
329
403
|
const dialog = await findByRole('dialog');
|
|
330
404
|
expect(dialog).toBeInTheDocument();
|
|
@@ -333,24 +407,38 @@ describe('<Modal />', () => {
|
|
|
333
407
|
});
|
|
334
408
|
describe('managed focus', () => {
|
|
335
409
|
var _ModalExample2;
|
|
336
|
-
class ModalExample extends
|
|
410
|
+
class ModalExample extends Component {
|
|
337
411
|
render() {
|
|
338
412
|
const _this$props = this.props,
|
|
339
413
|
label = _this$props.label,
|
|
340
414
|
props = _objectWithoutProperties(_this$props, _excluded);
|
|
341
|
-
return
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
415
|
+
return _jsxs("div", {
|
|
416
|
+
children: [_input || (_input = _jsx("input", {
|
|
417
|
+
type: "text"
|
|
418
|
+
})), _jsxs(Modal, {
|
|
419
|
+
label: label,
|
|
420
|
+
...props,
|
|
421
|
+
children: [_Modal$Header || (_Modal$Header = _jsx(Modal.Header, {
|
|
422
|
+
children: _jsx("button", {
|
|
423
|
+
children: "Close"
|
|
424
|
+
})
|
|
425
|
+
})), _Modal$Body8 || (_Modal$Body8 = _jsxs(Modal.Body, {
|
|
426
|
+
children: [_jsx("input", {
|
|
427
|
+
type: "text",
|
|
428
|
+
id: "input-one",
|
|
429
|
+
"data-testid": "input-first"
|
|
430
|
+
}), _jsx("input", {
|
|
431
|
+
type: "text",
|
|
432
|
+
id: "input-two",
|
|
433
|
+
"data-testid": "input-second"
|
|
434
|
+
})]
|
|
435
|
+
})), _Modal$Footer || (_Modal$Footer = _jsx(Modal.Footer, {
|
|
436
|
+
children: _jsx("button", {
|
|
437
|
+
children: "Cancel"
|
|
438
|
+
})
|
|
439
|
+
}))]
|
|
440
|
+
})]
|
|
441
|
+
});
|
|
354
442
|
}
|
|
355
443
|
}
|
|
356
444
|
ModalExample.displayName = "ModalExample";
|
|
@@ -359,7 +447,7 @@ describe('<Modal />', () => {
|
|
|
359
447
|
...Modal.propTypes
|
|
360
448
|
};
|
|
361
449
|
it('should focus closeButton by default', async () => {
|
|
362
|
-
const _render18 = render(_ModalExample2 || (_ModalExample2 =
|
|
450
|
+
const _render18 = render(_ModalExample2 || (_ModalExample2 = _jsx(ModalExample, {
|
|
363
451
|
open: true,
|
|
364
452
|
label: "A Modal"
|
|
365
453
|
}))),
|
|
@@ -371,7 +459,7 @@ describe('<Modal />', () => {
|
|
|
371
459
|
});
|
|
372
460
|
});
|
|
373
461
|
it('should take a prop for finding default focus', async () => {
|
|
374
|
-
const _render19 = render(
|
|
462
|
+
const _render19 = render(_jsx(ModalExample, {
|
|
375
463
|
open: true,
|
|
376
464
|
label: "A Modal",
|
|
377
465
|
defaultFocusElement: () => document.getElementById('input-one')
|
package/es/Modal/index.js
CHANGED
|
@@ -25,7 +25,6 @@ var _dec, _dec2, _class, _Modal;
|
|
|
25
25
|
* SOFTWARE.
|
|
26
26
|
*/
|
|
27
27
|
|
|
28
|
-
/** @jsx jsx */
|
|
29
28
|
import { Children, Component, isValidElement } from 'react';
|
|
30
29
|
import { passthroughProps, safeCloneElement } from '@instructure/ui-react-utils';
|
|
31
30
|
import { createChainedFunction } from '@instructure/ui-utils';
|
|
@@ -38,10 +37,11 @@ import { Mask } from '@instructure/ui-overlays';
|
|
|
38
37
|
import { ModalHeader } from './ModalHeader';
|
|
39
38
|
import { ModalBody } from './ModalBody';
|
|
40
39
|
import { ModalFooter } from './ModalFooter';
|
|
41
|
-
import { withStyle
|
|
40
|
+
import { withStyle } from '@instructure/emotion';
|
|
42
41
|
import generateStyle from './styles';
|
|
43
42
|
import generateComponentTheme from './theme';
|
|
44
43
|
import { propTypes, allowedProps } from './props';
|
|
44
|
+
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
45
45
|
/**
|
|
46
46
|
---
|
|
47
47
|
category: components
|
|
@@ -172,9 +172,10 @@ let Modal = (_dec = withStyle(generateStyle, generateComponentTheme), _dec2 = te
|
|
|
172
172
|
|
|
173
173
|
// Adds the <div> to the beginning of the filteredChildren array
|
|
174
174
|
if (headerAndBody.length > 0) {
|
|
175
|
-
filteredChildren.unshift(
|
|
176
|
-
css: styles === null || styles === void 0 ? void 0 : styles.joinedHeaderAndBody
|
|
177
|
-
|
|
175
|
+
filteredChildren.unshift(_jsx("div", {
|
|
176
|
+
css: styles === null || styles === void 0 ? void 0 : styles.joinedHeaderAndBody,
|
|
177
|
+
children: headerAndBody
|
|
178
|
+
}));
|
|
178
179
|
}
|
|
179
180
|
return Children.map(filteredChildren, child => {
|
|
180
181
|
if (!child) return; // ignore null, falsy children
|
|
@@ -204,7 +205,8 @@ let Modal = (_dec = withStyle(generateStyle, generateComponentTheme), _dec2 = te
|
|
|
204
205
|
as = _this$props5.as,
|
|
205
206
|
styles = _this$props5.styles;
|
|
206
207
|
const isFullScreen = size === 'fullscreen';
|
|
207
|
-
const dialog =
|
|
208
|
+
const dialog = _jsx(Dialog, {
|
|
209
|
+
...passthroughProps(props),
|
|
208
210
|
as: as,
|
|
209
211
|
open: true,
|
|
210
212
|
label: label,
|
|
@@ -218,15 +220,18 @@ let Modal = (_dec = withStyle(generateStyle, generateComponentTheme), _dec2 = te
|
|
|
218
220
|
css: styles === null || styles === void 0 ? void 0 : styles.modal,
|
|
219
221
|
ref: this.contentRef
|
|
220
222
|
// aria-modal="true" see VO bug https://bugs.webkit.org/show_bug.cgi?id=174667
|
|
221
|
-
|
|
222
|
-
|
|
223
|
+
,
|
|
224
|
+
children: this.renderChildren()
|
|
225
|
+
});
|
|
226
|
+
return _jsx(Mask, {
|
|
223
227
|
placement: this.maskPlacement,
|
|
224
228
|
fullscreen: constrain === 'window',
|
|
225
229
|
themeOverride: isFullScreen ? {
|
|
226
230
|
borderRadius: '0em',
|
|
227
231
|
borderWidth: '0em'
|
|
228
|
-
} : {}
|
|
229
|
-
|
|
232
|
+
} : {},
|
|
233
|
+
children: dialog
|
|
234
|
+
});
|
|
230
235
|
}
|
|
231
236
|
render() {
|
|
232
237
|
var _this$props$styles;
|
|
@@ -247,24 +252,27 @@ let Modal = (_dec = withStyle(generateStyle, generateComponentTheme), _dec2 = te
|
|
|
247
252
|
overflow = _this$props6.overflow,
|
|
248
253
|
passthroughProps = _objectWithoutProperties(_this$props6, _excluded);
|
|
249
254
|
const portalIsOpen = this.state.open || this.state.transitioning;
|
|
250
|
-
return
|
|
255
|
+
return _jsx(Portal, {
|
|
251
256
|
mountNode: mountNode,
|
|
252
257
|
insertAt: insertAt,
|
|
253
258
|
open: portalIsOpen,
|
|
254
|
-
onOpen: this.handlePortalOpen
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
259
|
+
onOpen: this.handlePortalOpen,
|
|
260
|
+
children: _jsx(Transition, {
|
|
261
|
+
in: open,
|
|
262
|
+
transitionOnMount: true,
|
|
263
|
+
type: transition,
|
|
264
|
+
onEnter: onEnter,
|
|
265
|
+
onEntering: onEntering,
|
|
266
|
+
onEntered: createChainedFunction(this.handleTransitionComplete, onEntered, onOpen),
|
|
267
|
+
onExit: onExit,
|
|
268
|
+
onExiting: onExiting,
|
|
269
|
+
onExited: createChainedFunction(this.handleTransitionComplete, onExited, onClose),
|
|
270
|
+
children: constrain === 'parent' ? _jsx("span", {
|
|
271
|
+
css: (_this$props$styles = this.props.styles) === null || _this$props$styles === void 0 ? void 0 : _this$props$styles.constrainContext,
|
|
272
|
+
children: this.renderDialog(passthroughProps)
|
|
273
|
+
}) : this.renderDialog(passthroughProps)
|
|
274
|
+
})
|
|
275
|
+
});
|
|
268
276
|
}
|
|
269
277
|
}, _Modal.displayName = "Modal", _Modal.componentId = 'Modal', _Modal.propTypes = propTypes, _Modal.allowedProps = allowedProps, _Modal.defaultProps = {
|
|
270
278
|
open: false,
|