@instructure/ui-focusable 10.16.1-snapshot-0 → 10.16.1-snapshot-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/Focusable/__new-tests__/Focusable.test.js +140 -76
- package/lib/Focusable/__new-tests__/Focusable.test.js +140 -77
- package/package.json +8 -8
- package/src/Focusable/__new-tests__/Focusable.test.tsx +1 -1
- package/src/Focusable/index.tsx +1 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/Focusable/index.d.ts +6 -6
- package/types/Focusable/index.d.ts.map +1 -1
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
4
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
5
|
-
var _react =
|
|
4
|
+
var _react = require("react");
|
|
6
5
|
var _react2 = require("@testing-library/react");
|
|
7
6
|
var _userEvent = _interopRequireDefault(require("@testing-library/user-event"));
|
|
8
7
|
var _vitest = require("vitest");
|
|
9
8
|
require("@testing-library/jest-dom");
|
|
10
9
|
var _index = require("../index");
|
|
10
|
+
var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
11
11
|
var _button, _button2, _input, _a, _a2, _button3, _button4, _span, _span2, _span3, _span4, _button5, _button6;
|
|
12
12
|
/*
|
|
13
13
|
* The MIT License (MIT)
|
|
@@ -45,18 +45,25 @@ describe('<Focusable />', () => {
|
|
|
45
45
|
consoleErrorMock.mockRestore();
|
|
46
46
|
});
|
|
47
47
|
it('should render', async () => {
|
|
48
|
-
(0, _react2.render)(
|
|
48
|
+
(0, _react2.render)((0, _jsxRuntime.jsx)(_index.Focusable, {
|
|
49
|
+
children: () => _button || (_button = (0, _jsxRuntime.jsx)("button", {
|
|
50
|
+
children: "hello world"
|
|
51
|
+
}))
|
|
52
|
+
}));
|
|
49
53
|
const button = _react2.screen.getByRole('button');
|
|
50
54
|
expect(button).toBeInTheDocument();
|
|
51
55
|
expect(button).toHaveTextContent('hello world');
|
|
52
56
|
});
|
|
53
57
|
it('should call children function with focused when element receives focus', async () => {
|
|
54
58
|
const renderSpy = _vitest.vi.fn();
|
|
55
|
-
(0, _react2.render)(
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
59
|
+
(0, _react2.render)((0, _jsxRuntime.jsx)(_index.Focusable, {
|
|
60
|
+
children: args => {
|
|
61
|
+
renderSpy(args);
|
|
62
|
+
return _button2 || (_button2 = (0, _jsxRuntime.jsx)("button", {
|
|
63
|
+
type: "button",
|
|
64
|
+
children: "foo"
|
|
65
|
+
}));
|
|
66
|
+
}
|
|
60
67
|
}));
|
|
61
68
|
const focusable = _react2.screen.getByRole('button');
|
|
62
69
|
await (0, _react2.waitFor)(() => {
|
|
@@ -86,12 +93,15 @@ describe('<Focusable />', () => {
|
|
|
86
93
|
it('should handle conditionally rendered focus elements', async () => {
|
|
87
94
|
const renderSpy = _vitest.vi.fn(({
|
|
88
95
|
focused
|
|
89
|
-
}) =>
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
96
|
+
}) => (0, _jsxRuntime.jsx)("div", {
|
|
97
|
+
children: focused ? _input || (_input = (0, _jsxRuntime.jsx)("input", {
|
|
98
|
+
type: "text"
|
|
99
|
+
})) : _a || (_a = (0, _jsxRuntime.jsx)("a", {
|
|
100
|
+
href: "http://focus.net",
|
|
101
|
+
children: "Click"
|
|
102
|
+
}))
|
|
103
|
+
}));
|
|
104
|
+
(0, _react2.render)((0, _jsxRuntime.jsx)(_index.Focusable, {
|
|
95
105
|
render: renderSpy
|
|
96
106
|
}));
|
|
97
107
|
const firstFocusable = _react2.screen.getByText('Click');
|
|
@@ -122,10 +132,11 @@ describe('<Focusable />', () => {
|
|
|
122
132
|
});
|
|
123
133
|
});
|
|
124
134
|
it('should maintain focus when the focus element changes', async () => {
|
|
125
|
-
const renderSpy = _vitest.vi.fn(() => _a2 || (_a2 =
|
|
126
|
-
href: "http://focus.net"
|
|
127
|
-
|
|
128
|
-
|
|
135
|
+
const renderSpy = _vitest.vi.fn(() => _a2 || (_a2 = (0, _jsxRuntime.jsx)("a", {
|
|
136
|
+
href: "http://focus.net",
|
|
137
|
+
children: "Click"
|
|
138
|
+
})));
|
|
139
|
+
const _render = (0, _react2.render)((0, _jsxRuntime.jsx)(_index.Focusable, {
|
|
129
140
|
render: renderSpy
|
|
130
141
|
})),
|
|
131
142
|
rerender = _render.rerender;
|
|
@@ -140,8 +151,10 @@ describe('<Focusable />', () => {
|
|
|
140
151
|
});
|
|
141
152
|
|
|
142
153
|
// Set prop: render
|
|
143
|
-
const nextRenderSpy = _vitest.vi.fn(() => _button3 || (_button3 =
|
|
144
|
-
|
|
154
|
+
const nextRenderSpy = _vitest.vi.fn(() => _button3 || (_button3 = (0, _jsxRuntime.jsx)("button", {
|
|
155
|
+
children: "Click"
|
|
156
|
+
})));
|
|
157
|
+
rerender((0, _jsxRuntime.jsx)(_index.Focusable, {
|
|
145
158
|
render: nextRenderSpy
|
|
146
159
|
}));
|
|
147
160
|
const nextFocusable = _react2.screen.getByText('Click');
|
|
@@ -157,9 +170,13 @@ describe('<Focusable />', () => {
|
|
|
157
170
|
});
|
|
158
171
|
it('should update the focus element correctly', async () => {
|
|
159
172
|
const renderSpy = _vitest.vi.fn();
|
|
160
|
-
const _render2 = (0, _react2.render)(
|
|
161
|
-
|
|
162
|
-
|
|
173
|
+
const _render2 = (0, _react2.render)((0, _jsxRuntime.jsx)(_index.Focusable, {
|
|
174
|
+
children: args => {
|
|
175
|
+
renderSpy(args);
|
|
176
|
+
return _button4 || (_button4 = (0, _jsxRuntime.jsx)("button", {
|
|
177
|
+
children: "foo"
|
|
178
|
+
}));
|
|
179
|
+
}
|
|
163
180
|
})),
|
|
164
181
|
rerender = _render2.rerender;
|
|
165
182
|
const firstButton = _react2.screen.getByText('foo');
|
|
@@ -175,9 +192,15 @@ describe('<Focusable />', () => {
|
|
|
175
192
|
});
|
|
176
193
|
|
|
177
194
|
// Set child
|
|
178
|
-
rerender(
|
|
179
|
-
|
|
180
|
-
|
|
195
|
+
rerender((0, _jsxRuntime.jsx)(_index.Focusable, {
|
|
196
|
+
children: args => {
|
|
197
|
+
renderSpy(args);
|
|
198
|
+
return _span || (_span = (0, _jsxRuntime.jsxs)("span", {
|
|
199
|
+
children: ["some content text", (0, _jsxRuntime.jsx)("button", {
|
|
200
|
+
children: "bar"
|
|
201
|
+
})]
|
|
202
|
+
}));
|
|
203
|
+
}
|
|
181
204
|
}));
|
|
182
205
|
const secondButton = _react2.screen.getByText('bar');
|
|
183
206
|
await secondButton.focus();
|
|
@@ -187,24 +210,50 @@ describe('<Focusable />', () => {
|
|
|
187
210
|
});
|
|
188
211
|
});
|
|
189
212
|
it('should warn when there is more than one focusable descendant', async () => {
|
|
190
|
-
(0, _react2.render)(
|
|
191
|
-
|
|
213
|
+
(0, _react2.render)((0, _jsxRuntime.jsx)(_index.Focusable, {
|
|
214
|
+
children: () => {
|
|
215
|
+
return _span2 || (_span2 = (0, _jsxRuntime.jsxs)("span", {
|
|
216
|
+
children: [(0, _jsxRuntime.jsx)("button", {
|
|
217
|
+
children: "foo"
|
|
218
|
+
}), (0, _jsxRuntime.jsx)("span", {
|
|
219
|
+
children: (0, _jsxRuntime.jsx)("button", {
|
|
220
|
+
children: "bar"
|
|
221
|
+
})
|
|
222
|
+
})]
|
|
223
|
+
}));
|
|
224
|
+
}
|
|
192
225
|
}));
|
|
193
226
|
const expectedWarningMessage = 'Warning: [Focusable] Exactly one focusable child is required (2 found).';
|
|
194
227
|
expect(consoleWarningMock).toHaveBeenCalledWith(expect.stringContaining(expectedWarningMessage), expect.any(String));
|
|
195
228
|
});
|
|
196
229
|
it('should warn when there are no focusable descendants', async () => {
|
|
197
|
-
(0, _react2.render)(
|
|
198
|
-
|
|
230
|
+
(0, _react2.render)((0, _jsxRuntime.jsx)(_index.Focusable, {
|
|
231
|
+
children: () => {
|
|
232
|
+
return _span3 || (_span3 = (0, _jsxRuntime.jsx)("span", {
|
|
233
|
+
children: "hello!"
|
|
234
|
+
}));
|
|
235
|
+
}
|
|
199
236
|
}));
|
|
200
237
|
const expectedWarningMessage = 'Warning: [Focusable] Exactly one focusable child is required (0 found).';
|
|
201
238
|
expect(consoleWarningMock).toHaveBeenCalledWith(expect.stringContaining(expectedWarningMessage), expect.any(String));
|
|
202
239
|
});
|
|
203
240
|
it('should attach event listener correctly even when the focusable element is not the root', async () => {
|
|
204
241
|
const renderSpy = _vitest.vi.fn();
|
|
205
|
-
(0, _react2.render)(
|
|
206
|
-
|
|
207
|
-
|
|
242
|
+
(0, _react2.render)((0, _jsxRuntime.jsx)(_index.Focusable, {
|
|
243
|
+
children: args => {
|
|
244
|
+
renderSpy(args);
|
|
245
|
+
return _span4 || (_span4 = (0, _jsxRuntime.jsxs)("span", {
|
|
246
|
+
children: [(0, _jsxRuntime.jsx)("h1", {
|
|
247
|
+
children: "hello world"
|
|
248
|
+
}), (0, _jsxRuntime.jsx)("p", {
|
|
249
|
+
children: "some content"
|
|
250
|
+
}), (0, _jsxRuntime.jsx)("span", {
|
|
251
|
+
children: (0, _jsxRuntime.jsx)("button", {
|
|
252
|
+
children: "foo"
|
|
253
|
+
})
|
|
254
|
+
})]
|
|
255
|
+
}));
|
|
256
|
+
}
|
|
208
257
|
}));
|
|
209
258
|
const button = _react2.screen.getByRole('button');
|
|
210
259
|
await (0, _react2.waitFor)(() => {
|
|
@@ -219,11 +268,14 @@ describe('<Focusable />', () => {
|
|
|
219
268
|
});
|
|
220
269
|
it('should provide a focus method', async () => {
|
|
221
270
|
let focusable;
|
|
222
|
-
(0, _react2.render)(
|
|
271
|
+
(0, _react2.render)((0, _jsxRuntime.jsx)(_index.Focusable, {
|
|
223
272
|
ref: el => {
|
|
224
273
|
focusable = el;
|
|
225
|
-
}
|
|
226
|
-
|
|
274
|
+
},
|
|
275
|
+
children: () => _button5 || (_button5 = (0, _jsxRuntime.jsx)("button", {
|
|
276
|
+
children: "hello world"
|
|
277
|
+
}))
|
|
278
|
+
}));
|
|
227
279
|
await focusable.focus();
|
|
228
280
|
const button = _react2.screen.getByText('hello world');
|
|
229
281
|
expect(button).toHaveFocus();
|
|
@@ -231,9 +283,13 @@ describe('<Focusable />', () => {
|
|
|
231
283
|
it('should provide a focused getter', async () => {
|
|
232
284
|
var _focusableInstance;
|
|
233
285
|
let focusableInstance;
|
|
234
|
-
(0, _react2.render)(
|
|
235
|
-
|
|
236
|
-
|
|
286
|
+
(0, _react2.render)((0, _jsxRuntime.jsx)(_index.Focusable, {
|
|
287
|
+
children: args => {
|
|
288
|
+
focusableInstance = args;
|
|
289
|
+
return _button6 || (_button6 = (0, _jsxRuntime.jsx)("button", {
|
|
290
|
+
children: "Click me"
|
|
291
|
+
}));
|
|
292
|
+
}
|
|
237
293
|
}));
|
|
238
294
|
const button = _react2.screen.getByText('Click me');
|
|
239
295
|
expect((_focusableInstance = focusableInstance) === null || _focusableInstance === void 0 ? void 0 : _focusableInstance.focused).toBe(false);
|
|
@@ -249,21 +305,23 @@ describe('<Focusable />', () => {
|
|
|
249
305
|
class TestComponent extends _react.Component {
|
|
250
306
|
render() {
|
|
251
307
|
const changeValue = this.props.changeValue;
|
|
252
|
-
return
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
308
|
+
return (0, _jsxRuntime.jsx)(_index.Focusable, {
|
|
309
|
+
children: ({
|
|
310
|
+
focusVisible
|
|
311
|
+
}) => {
|
|
312
|
+
return (0, _jsxRuntime.jsx)("input", {
|
|
313
|
+
readOnly: true,
|
|
314
|
+
ref: el => {
|
|
315
|
+
inputRef = el;
|
|
316
|
+
},
|
|
317
|
+
value: `${focusVisible}_${changeValue}`
|
|
318
|
+
});
|
|
319
|
+
}
|
|
262
320
|
});
|
|
263
321
|
}
|
|
264
322
|
}
|
|
265
323
|
TestComponent.displayName = "TestComponent";
|
|
266
|
-
const _render3 = (0, _react2.render)(
|
|
324
|
+
const _render3 = (0, _react2.render)((0, _jsxRuntime.jsx)(TestComponent, {
|
|
267
325
|
changeValue: "A"
|
|
268
326
|
})),
|
|
269
327
|
rerender = _render3.rerender,
|
|
@@ -274,7 +332,7 @@ describe('<Focusable />', () => {
|
|
|
274
332
|
});
|
|
275
333
|
|
|
276
334
|
// Set Prop: changeValue
|
|
277
|
-
rerender(
|
|
335
|
+
rerender((0, _jsxRuntime.jsx)(TestComponent, {
|
|
278
336
|
changeValue: "B"
|
|
279
337
|
}));
|
|
280
338
|
await inputRef.focus();
|
|
@@ -298,40 +356,45 @@ describe('<Focusable />', () => {
|
|
|
298
356
|
const _this$state = this.state,
|
|
299
357
|
checked = _this$state.checked,
|
|
300
358
|
disabled = _this$state.disabled;
|
|
301
|
-
return
|
|
302
|
-
|
|
303
|
-
focusableRef = el;
|
|
304
|
-
}
|
|
305
|
-
}, () => {
|
|
306
|
-
return /*#__PURE__*/_react.default.createElement("label", {
|
|
359
|
+
return (0, _jsxRuntime.jsxs)("div", {
|
|
360
|
+
children: [(0, _jsxRuntime.jsx)(_index.Focusable, {
|
|
307
361
|
ref: el => {
|
|
308
|
-
|
|
362
|
+
focusableRef = el;
|
|
309
363
|
},
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
364
|
+
children: () => {
|
|
365
|
+
return (0, _jsxRuntime.jsx)("label", {
|
|
366
|
+
ref: el => {
|
|
367
|
+
labelRef = el;
|
|
368
|
+
},
|
|
369
|
+
"aria-label": 'test-label',
|
|
370
|
+
children: (0, _jsxRuntime.jsx)("input", {
|
|
371
|
+
checked: checked,
|
|
372
|
+
disabled: disabled,
|
|
373
|
+
onChange: () => {
|
|
374
|
+
this.setState({
|
|
375
|
+
checked: true
|
|
376
|
+
});
|
|
377
|
+
},
|
|
378
|
+
type: "checkbox"
|
|
379
|
+
})
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
}), (0, _jsxRuntime.jsx)("button", {
|
|
383
|
+
onClick: () => {
|
|
315
384
|
this.setState({
|
|
316
|
-
|
|
385
|
+
disabled: true
|
|
317
386
|
});
|
|
318
387
|
},
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
});
|
|
326
|
-
},
|
|
327
|
-
ref: el => {
|
|
328
|
-
buttonRef = el;
|
|
329
|
-
}
|
|
330
|
-
}, "hello world"));
|
|
388
|
+
ref: el => {
|
|
389
|
+
buttonRef = el;
|
|
390
|
+
},
|
|
391
|
+
children: "hello world"
|
|
392
|
+
})]
|
|
393
|
+
});
|
|
331
394
|
}
|
|
332
395
|
}
|
|
333
396
|
TestComponent.displayName = "TestComponent";
|
|
334
|
-
const _render4 = (0, _react2.render)(
|
|
397
|
+
const _render4 = (0, _react2.render)((0, _jsxRuntime.jsx)(TestComponent, {})),
|
|
335
398
|
container = _render4.container;
|
|
336
399
|
const input = container.querySelector('input');
|
|
337
400
|
await (0, _react2.waitFor)(() => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@instructure/ui-focusable",
|
|
3
|
-
"version": "10.16.1-snapshot-
|
|
3
|
+
"version": "10.16.1-snapshot-1",
|
|
4
4
|
"description": "A utility used to identify when an element receives focus.",
|
|
5
5
|
"author": "Instructure, Inc. Engineering and Product Design",
|
|
6
6
|
"module": "./es/index.js",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
},
|
|
24
24
|
"license": "MIT",
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@instructure/ui-babel-preset": "10.16.1-snapshot-
|
|
26
|
+
"@instructure/ui-babel-preset": "10.16.1-snapshot-1",
|
|
27
27
|
"@testing-library/jest-dom": "^6.6.3",
|
|
28
28
|
"@testing-library/react": "^16.0.1",
|
|
29
29
|
"@testing-library/user-event": "^14.5.2",
|
|
@@ -31,12 +31,12 @@
|
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@babel/runtime": "^7.26.0",
|
|
34
|
-
"@instructure/console": "10.16.1-snapshot-
|
|
35
|
-
"@instructure/shared-types": "10.16.1-snapshot-
|
|
36
|
-
"@instructure/ui-dom-utils": "10.16.1-snapshot-
|
|
37
|
-
"@instructure/ui-react-utils": "10.16.1-snapshot-
|
|
38
|
-
"@instructure/ui-utils": "10.16.1-snapshot-
|
|
39
|
-
"@instructure/ui-view": "10.16.1-snapshot-
|
|
34
|
+
"@instructure/console": "10.16.1-snapshot-1",
|
|
35
|
+
"@instructure/shared-types": "10.16.1-snapshot-1",
|
|
36
|
+
"@instructure/ui-dom-utils": "10.16.1-snapshot-1",
|
|
37
|
+
"@instructure/ui-react-utils": "10.16.1-snapshot-1",
|
|
38
|
+
"@instructure/ui-utils": "10.16.1-snapshot-1",
|
|
39
|
+
"@instructure/ui-view": "10.16.1-snapshot-1",
|
|
40
40
|
"prop-types": "^15.8.1"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|