@instructure/ui-focusable 11.7.8 → 11.7.9-pr-snapshot-1792147648392
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 +13 -0
- package/es/Focusable/index.js +173 -225
- package/es/Focusable/props.js +5 -26
- package/es/index.js +1 -24
- package/package.json +11 -14
- package/tsconfig.build.json +0 -1
- package/lib/Focusable/index.js +0 -242
- package/lib/Focusable/props.js +0 -31
- package/lib/index.js +0 -12
- package/lib/package.json +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,19 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [11.7.9-pr-snapshot-1792147648392](https://github.com/instructure/instructure-ui/compare/v11.7.8...v11.7.9-pr-snapshot-1792147648392) (2026-10-16)
|
|
7
|
+
|
|
8
|
+
### Build System
|
|
9
|
+
|
|
10
|
+
* **many:** replace babel with swc ([7e36c54](https://github.com/instructure/instructure-ui/commit/7e36c54d240b4fa483801c03ab18e7f860f561e2))
|
|
11
|
+
|
|
12
|
+
### BREAKING CHANGES
|
|
13
|
+
|
|
14
|
+
* **many:** `@instructure/ui-babel-preset` and
|
|
15
|
+
`@instructure/browserslist-config-instui` are removed and will no longer be
|
|
16
|
+
published. Packages depend on `@swc/helpers` instead of `@babel/runtime`.
|
|
17
|
+
|
|
18
|
+
|
|
6
19
|
## [11.7.8](https://github.com/instructure/instructure-ui/compare/v11.7.7...v11.7.8) (2026-10-02)
|
|
7
20
|
|
|
8
21
|
**Note:** Version bump only for package @instructure/ui-focusable
|
package/es/Focusable/index.js
CHANGED
|
@@ -1,233 +1,181 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* The MIT License (MIT)
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
-
*
|
|
6
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
* in the Software without restriction, including without limitation the rights
|
|
9
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
* furnished to do so, subject to the following conditions:
|
|
12
|
-
*
|
|
13
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
* copies or substantial portions of the Software.
|
|
15
|
-
*
|
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
* SOFTWARE.
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
1
|
import { cloneElement, Component } from 'react';
|
|
26
2
|
import { addInputModeListener, addEventListener, containsActiveElement, findFocusable } from '@instructure/ui-dom-utils';
|
|
27
3
|
import { logWarn as warn } from '@instructure/console';
|
|
28
4
|
import { allowedProps } from './props.js';
|
|
29
5
|
import { createChainedFunction } from '@instructure/ui-utils';
|
|
30
|
-
/**
|
|
31
|
-
---
|
|
32
|
-
category: components/Util Components
|
|
33
|
-
---
|
|
34
|
-
**/
|
|
35
6
|
class Focusable extends Component {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
render() {
|
|
209
|
-
const {
|
|
210
|
-
children,
|
|
211
|
-
render = children
|
|
212
|
-
} = this.props;
|
|
213
|
-
const {
|
|
214
|
-
focusable,
|
|
215
|
-
focused
|
|
216
|
-
} = this.state;
|
|
217
|
-
if (typeof render === 'function') {
|
|
218
|
-
const rendered = render({
|
|
219
|
-
focused,
|
|
220
|
-
focusable,
|
|
221
|
-
focusVisible: this.isFocusVisible(focused, focusable),
|
|
222
|
-
attachRef: this.attachRef
|
|
223
|
-
});
|
|
224
|
-
return /*#__PURE__*/cloneElement(rendered, {
|
|
225
|
-
ref: rendered.ref ? createChainedFunction(rendered.ref, this.attachRef) : this.attachRef
|
|
226
|
-
});
|
|
227
|
-
} else {
|
|
228
|
-
return null;
|
|
229
|
-
}
|
|
230
|
-
}
|
|
7
|
+
static{
|
|
8
|
+
this.displayName = 'Focusable';
|
|
9
|
+
}
|
|
10
|
+
static{
|
|
11
|
+
this.allowedProps = allowedProps;
|
|
12
|
+
}
|
|
13
|
+
static{
|
|
14
|
+
this.defaultProps = {
|
|
15
|
+
children: null
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
static{
|
|
19
|
+
this.inputTypes = {
|
|
20
|
+
text: true,
|
|
21
|
+
search: true,
|
|
22
|
+
url: true,
|
|
23
|
+
tel: true,
|
|
24
|
+
email: true,
|
|
25
|
+
password: true,
|
|
26
|
+
number: true,
|
|
27
|
+
date: true,
|
|
28
|
+
month: true,
|
|
29
|
+
week: true,
|
|
30
|
+
time: true,
|
|
31
|
+
datetime: true,
|
|
32
|
+
'datetime-local': true
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
componentDidMount() {
|
|
36
|
+
const { focusable, focused } = this;
|
|
37
|
+
this.addFocusableListeners(focused, focusable);
|
|
38
|
+
this._inputModeListener = addInputModeListener({
|
|
39
|
+
onInputModeChange: this.handleInputModeChange
|
|
40
|
+
});
|
|
41
|
+
this.setState({
|
|
42
|
+
focusable,
|
|
43
|
+
focused
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
getSnapshotBeforeUpdate(prevProps) {
|
|
47
|
+
const { render, children } = this.props;
|
|
48
|
+
if (prevProps.children !== children || prevProps.render !== render) {
|
|
49
|
+
this.removeFocusableListeners();
|
|
50
|
+
}
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
componentDidUpdate() {
|
|
54
|
+
const focusable = this.focusable;
|
|
55
|
+
if (!focusable && this.state.focusable) {
|
|
56
|
+
this.removeFocusableListeners();
|
|
57
|
+
this.setState({
|
|
58
|
+
focusable: undefined,
|
|
59
|
+
focused: false
|
|
60
|
+
});
|
|
61
|
+
} else if (focusable !== this.state.focusable) {
|
|
62
|
+
this.removeFocusableListeners();
|
|
63
|
+
if (this.state.focused) {
|
|
64
|
+
;
|
|
65
|
+
focusable.focus();
|
|
66
|
+
}
|
|
67
|
+
this.addFocusableListeners(this.state.focused, focusable);
|
|
68
|
+
this.setState({
|
|
69
|
+
focusable
|
|
70
|
+
});
|
|
71
|
+
} else {
|
|
72
|
+
this.addFocusableListeners(this.state.focused, focusable);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
componentWillUnmount() {
|
|
76
|
+
if (this._inputModeListener) {
|
|
77
|
+
this._inputModeListener.remove();
|
|
78
|
+
this._inputModeListener = null;
|
|
79
|
+
}
|
|
80
|
+
this.removeFocusableListeners();
|
|
81
|
+
}
|
|
82
|
+
addFocusableListeners(focused, focusable) {
|
|
83
|
+
if (!focusable) return;
|
|
84
|
+
if (focused && !this._blurListener) {
|
|
85
|
+
this._blurListener = addEventListener(focusable, 'blur', this.handleBlur, true);
|
|
86
|
+
} else if (!this._focusListener) {
|
|
87
|
+
this._focusListener = addEventListener(focusable, 'focus', this.handleFocus, true);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
removeFocusableListeners() {
|
|
91
|
+
this.removeFocusListener();
|
|
92
|
+
this.removeBlurListener();
|
|
93
|
+
}
|
|
94
|
+
removeFocusListener() {
|
|
95
|
+
if (this._focusListener) {
|
|
96
|
+
this._focusListener.remove();
|
|
97
|
+
this._focusListener = null;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
removeBlurListener() {
|
|
101
|
+
if (this._blurListener) {
|
|
102
|
+
this._blurListener.remove();
|
|
103
|
+
this._blurListener = null;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
get focused() {
|
|
107
|
+
return containsActiveElement(this);
|
|
108
|
+
}
|
|
109
|
+
get focusable() {
|
|
110
|
+
const focusableArr = findFocusable(this, ()=>true, true) || [];
|
|
111
|
+
const focusableCount = focusableArr && focusableArr.length || 0;
|
|
112
|
+
warn(focusableCount === 1, `[Focusable] Exactly one focusable child is required (${focusableCount} found).`);
|
|
113
|
+
const focusable = focusableArr ? focusableArr[0] : false;
|
|
114
|
+
if (focusable && typeof focusable.focus === 'function') {
|
|
115
|
+
return focusable;
|
|
116
|
+
} else {
|
|
117
|
+
return undefined;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
get focusVisible() {
|
|
121
|
+
const { focusable, focused } = this.state;
|
|
122
|
+
return this.isFocusVisible(focused, focusable);
|
|
123
|
+
}
|
|
124
|
+
focus() {
|
|
125
|
+
const { focusable } = this;
|
|
126
|
+
if (focusable) {
|
|
127
|
+
focusable.focus();
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
isFocusVisible(focused, focusable) {
|
|
131
|
+
if (!focusable || !focused) return false;
|
|
132
|
+
if (this._inputModeListener && this._inputModeListener.isKeyboardMode()) return true;
|
|
133
|
+
const { tagName, type, isContentEditable } = focusable;
|
|
134
|
+
if (tagName == 'INPUT' && Focusable.inputTypes[type]) {
|
|
135
|
+
return true;
|
|
136
|
+
}
|
|
137
|
+
if (tagName == 'TEXTAREA') {
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
140
|
+
return isContentEditable;
|
|
141
|
+
}
|
|
142
|
+
render() {
|
|
143
|
+
const { children, render = children } = this.props;
|
|
144
|
+
const { focusable, focused } = this.state;
|
|
145
|
+
if (typeof render === 'function') {
|
|
146
|
+
const rendered = render({
|
|
147
|
+
focused,
|
|
148
|
+
focusable,
|
|
149
|
+
focusVisible: this.isFocusVisible(focused, focusable),
|
|
150
|
+
attachRef: this.attachRef
|
|
151
|
+
});
|
|
152
|
+
return /*#__PURE__*/ cloneElement(rendered, {
|
|
153
|
+
ref: rendered.ref ? createChainedFunction(rendered.ref, this.attachRef) : this.attachRef
|
|
154
|
+
});
|
|
155
|
+
} else {
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
constructor(...args){
|
|
160
|
+
super(...args), this._focusListener = null, this._blurListener = null, this._inputModeListener = null, this.state = {
|
|
161
|
+
focused: false,
|
|
162
|
+
focusable: undefined
|
|
163
|
+
}, this.handleInputModeChange = ()=>{
|
|
164
|
+
this.forceUpdate();
|
|
165
|
+
}, this.handleFocus = ()=>{
|
|
166
|
+
this.removeFocusListener();
|
|
167
|
+
this.setState({
|
|
168
|
+
focused: true
|
|
169
|
+
});
|
|
170
|
+
}, this.handleBlur = ()=>{
|
|
171
|
+
this.removeBlurListener();
|
|
172
|
+
this.setState({
|
|
173
|
+
focused: false
|
|
174
|
+
});
|
|
175
|
+
}, this.ref = null, this.attachRef = (el)=>{
|
|
176
|
+
this.ref = el;
|
|
177
|
+
};
|
|
178
|
+
}
|
|
231
179
|
}
|
|
232
180
|
export default Focusable;
|
|
233
|
-
export { Focusable };
|
|
181
|
+
export { Focusable };
|
package/es/Focusable/props.js
CHANGED
|
@@ -1,26 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
* in the Software without restriction, including without limitation the rights
|
|
9
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
* furnished to do so, subject to the following conditions:
|
|
12
|
-
*
|
|
13
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
* copies or substantial portions of the Software.
|
|
15
|
-
*
|
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
* SOFTWARE.
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
const allowedProps = ['children', 'render'];
|
|
26
|
-
export { allowedProps };
|
|
1
|
+
const allowedProps = [
|
|
2
|
+
'children',
|
|
3
|
+
'render'
|
|
4
|
+
];
|
|
5
|
+
export { allowedProps };
|
package/es/index.js
CHANGED
|
@@ -1,24 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* The MIT License (MIT)
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
-
*
|
|
6
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
* in the Software without restriction, including without limitation the rights
|
|
9
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
* furnished to do so, subject to the following conditions:
|
|
12
|
-
*
|
|
13
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
* copies or substantial portions of the Software.
|
|
15
|
-
*
|
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
* SOFTWARE.
|
|
23
|
-
*/
|
|
24
|
-
export { Focusable } from './Focusable/index.js';
|
|
1
|
+
export { Focusable } from './Focusable/index.js';
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@instructure/ui-focusable",
|
|
3
|
-
"version": "11.7.
|
|
3
|
+
"version": "11.7.9-pr-snapshot-1792147648392",
|
|
4
|
+
"type": "module",
|
|
4
5
|
"description": "A utility used to identify when an element receives focus.",
|
|
5
6
|
"author": "Instructure, Inc. Engineering and Product Design",
|
|
6
7
|
"module": "./es/index.js",
|
|
7
|
-
"main": "./lib/index.js",
|
|
8
8
|
"types": "./types/index.d.ts",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
@@ -14,17 +14,16 @@
|
|
|
14
14
|
"bugs": "https://github.com/instructure/instructure-ui/issues",
|
|
15
15
|
"license": "MIT",
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@
|
|
18
|
-
"@instructure/
|
|
19
|
-
"@instructure/
|
|
20
|
-
"@instructure/ui-utils": "11.7.
|
|
21
|
-
"@instructure/
|
|
22
|
-
"@instructure/ui-react-utils": "11.7.
|
|
23
|
-
"@instructure/ui-view": "11.7.
|
|
17
|
+
"@swc/helpers": "^0.5.23",
|
|
18
|
+
"@instructure/shared-types": "11.7.9-pr-snapshot-1792147648392",
|
|
19
|
+
"@instructure/console": "11.7.9-pr-snapshot-1792147648392",
|
|
20
|
+
"@instructure/ui-utils": "11.7.9-pr-snapshot-1792147648392",
|
|
21
|
+
"@instructure/ui-dom-utils": "11.7.9-pr-snapshot-1792147648392",
|
|
22
|
+
"@instructure/ui-react-utils": "11.7.9-pr-snapshot-1792147648392",
|
|
23
|
+
"@instructure/ui-view": "11.7.9-pr-snapshot-1792147648392"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"vitest": "^5.0.0"
|
|
27
|
-
"@instructure/ui-babel-preset": "11.7.8"
|
|
26
|
+
"vitest": "^5.0.0"
|
|
28
27
|
},
|
|
29
28
|
"peerDependencies": {
|
|
30
29
|
"react": ">=18 <=19"
|
|
@@ -38,10 +37,8 @@
|
|
|
38
37
|
"src": "./src/index.ts",
|
|
39
38
|
"types": "./types/index.d.ts",
|
|
40
39
|
"import": "./es/index.js",
|
|
41
|
-
"require": "./lib/index.js",
|
|
42
40
|
"default": "./es/index.js"
|
|
43
41
|
},
|
|
44
|
-
"./lib/*": "./lib/*",
|
|
45
42
|
"./es/*": "./es/*",
|
|
46
43
|
"./types/*": "./types/*",
|
|
47
44
|
"./package.json": "./package.json",
|
|
@@ -51,7 +48,7 @@
|
|
|
51
48
|
"lint": "ui-scripts lint",
|
|
52
49
|
"lint:fix": "ui-scripts lint --fix",
|
|
53
50
|
"clean": "ui-scripts clean",
|
|
54
|
-
"build": "ui-scripts build
|
|
51
|
+
"build": "ui-scripts build",
|
|
55
52
|
"build:watch": "pnpm run ts:check -- --watch & ui-scripts build --watch",
|
|
56
53
|
"build:types": "tsc -p tsconfig.build.json",
|
|
57
54
|
"ts:check": "tsc -p tsconfig.build.json --noEmit --emitDeclarationOnly false"
|
package/tsconfig.build.json
CHANGED
package/lib/Focusable/index.js
DELETED
|
@@ -1,242 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = exports.Focusable = void 0;
|
|
7
|
-
var _react = require("react");
|
|
8
|
-
var _addInputModeListener = require("@instructure/ui-dom-utils/lib/addInputModeListener.js");
|
|
9
|
-
var _addEventListener = require("@instructure/ui-dom-utils/lib/addEventListener.js");
|
|
10
|
-
var _containsActiveElement = require("@instructure/ui-dom-utils/lib/containsActiveElement.js");
|
|
11
|
-
var _findFocusable = require("@instructure/ui-dom-utils/lib/findFocusable.js");
|
|
12
|
-
var _console = require("@instructure/console");
|
|
13
|
-
var _props = require("./props.js");
|
|
14
|
-
var _createChainedFunction = require("@instructure/ui-utils/lib/createChainedFunction.js");
|
|
15
|
-
/*
|
|
16
|
-
* The MIT License (MIT)
|
|
17
|
-
*
|
|
18
|
-
* Copyright (c) 2015 - present Instructure, Inc.
|
|
19
|
-
*
|
|
20
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
21
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
22
|
-
* in the Software without restriction, including without limitation the rights
|
|
23
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
24
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
25
|
-
* furnished to do so, subject to the following conditions:
|
|
26
|
-
*
|
|
27
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
28
|
-
* copies or substantial portions of the Software.
|
|
29
|
-
*
|
|
30
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
31
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
32
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
33
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
34
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
35
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
36
|
-
* SOFTWARE.
|
|
37
|
-
*/
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
---
|
|
41
|
-
category: components/Util Components
|
|
42
|
-
---
|
|
43
|
-
**/
|
|
44
|
-
class Focusable extends _react.Component {
|
|
45
|
-
static displayName = 'Focusable';
|
|
46
|
-
static allowedProps = _props.allowedProps;
|
|
47
|
-
static defaultProps = {
|
|
48
|
-
children: null
|
|
49
|
-
};
|
|
50
|
-
static inputTypes = {
|
|
51
|
-
text: true,
|
|
52
|
-
search: true,
|
|
53
|
-
url: true,
|
|
54
|
-
tel: true,
|
|
55
|
-
email: true,
|
|
56
|
-
password: true,
|
|
57
|
-
number: true,
|
|
58
|
-
date: true,
|
|
59
|
-
month: true,
|
|
60
|
-
week: true,
|
|
61
|
-
time: true,
|
|
62
|
-
datetime: true,
|
|
63
|
-
'datetime-local': true
|
|
64
|
-
};
|
|
65
|
-
_focusListener = null;
|
|
66
|
-
_blurListener = null;
|
|
67
|
-
_inputModeListener = null;
|
|
68
|
-
state = {
|
|
69
|
-
focused: false,
|
|
70
|
-
focusable: undefined
|
|
71
|
-
};
|
|
72
|
-
componentDidMount() {
|
|
73
|
-
const {
|
|
74
|
-
focusable,
|
|
75
|
-
focused
|
|
76
|
-
} = this;
|
|
77
|
-
this.addFocusableListeners(focused, focusable);
|
|
78
|
-
this._inputModeListener = (0, _addInputModeListener.addInputModeListener)({
|
|
79
|
-
onInputModeChange: this.handleInputModeChange
|
|
80
|
-
});
|
|
81
|
-
this.setState({
|
|
82
|
-
focusable,
|
|
83
|
-
focused
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
getSnapshotBeforeUpdate(prevProps) {
|
|
87
|
-
const {
|
|
88
|
-
render,
|
|
89
|
-
children
|
|
90
|
-
} = this.props;
|
|
91
|
-
// prevent blur from firing when focusable element is replaced
|
|
92
|
-
if (prevProps.children !== children || prevProps.render !== render) {
|
|
93
|
-
this.removeFocusableListeners();
|
|
94
|
-
}
|
|
95
|
-
return null;
|
|
96
|
-
}
|
|
97
|
-
componentDidUpdate() {
|
|
98
|
-
const focusable = this.focusable;
|
|
99
|
-
if (!focusable && this.state.focusable) {
|
|
100
|
-
this.removeFocusableListeners();
|
|
101
|
-
this.setState({
|
|
102
|
-
focusable: undefined,
|
|
103
|
-
focused: false
|
|
104
|
-
});
|
|
105
|
-
} else if (focusable !== this.state.focusable) {
|
|
106
|
-
this.removeFocusableListeners();
|
|
107
|
-
if (this.state.focused) {
|
|
108
|
-
;
|
|
109
|
-
focusable.focus();
|
|
110
|
-
}
|
|
111
|
-
this.addFocusableListeners(this.state.focused, focusable);
|
|
112
|
-
this.setState({
|
|
113
|
-
focusable
|
|
114
|
-
});
|
|
115
|
-
} else {
|
|
116
|
-
this.addFocusableListeners(this.state.focused, focusable);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
componentWillUnmount() {
|
|
120
|
-
if (this._inputModeListener) {
|
|
121
|
-
this._inputModeListener.remove();
|
|
122
|
-
this._inputModeListener = null;
|
|
123
|
-
}
|
|
124
|
-
this.removeFocusableListeners();
|
|
125
|
-
}
|
|
126
|
-
addFocusableListeners(focused, focusable) {
|
|
127
|
-
if (!focusable) return;
|
|
128
|
-
if (focused && !this._blurListener) {
|
|
129
|
-
this._blurListener = (0, _addEventListener.addEventListener)(focusable, 'blur', this.handleBlur, true);
|
|
130
|
-
} else if (!this._focusListener) {
|
|
131
|
-
this._focusListener = (0, _addEventListener.addEventListener)(focusable, 'focus', this.handleFocus, true);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
removeFocusableListeners() {
|
|
135
|
-
this.removeFocusListener();
|
|
136
|
-
this.removeBlurListener();
|
|
137
|
-
}
|
|
138
|
-
removeFocusListener() {
|
|
139
|
-
if (this._focusListener) {
|
|
140
|
-
this._focusListener.remove();
|
|
141
|
-
this._focusListener = null;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
removeBlurListener() {
|
|
145
|
-
if (this._blurListener) {
|
|
146
|
-
this._blurListener.remove();
|
|
147
|
-
this._blurListener = null;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
handleInputModeChange = () => {
|
|
151
|
-
this.forceUpdate();
|
|
152
|
-
};
|
|
153
|
-
handleFocus = () => {
|
|
154
|
-
this.removeFocusListener();
|
|
155
|
-
this.setState({
|
|
156
|
-
focused: true
|
|
157
|
-
});
|
|
158
|
-
};
|
|
159
|
-
handleBlur = () => {
|
|
160
|
-
this.removeBlurListener();
|
|
161
|
-
this.setState({
|
|
162
|
-
focused: false
|
|
163
|
-
});
|
|
164
|
-
};
|
|
165
|
-
get focused() {
|
|
166
|
-
return (0, _containsActiveElement.containsActiveElement)(this);
|
|
167
|
-
}
|
|
168
|
-
get focusable() {
|
|
169
|
-
const focusableArr = (0, _findFocusable.findFocusable)(this, () => true, true) || [];
|
|
170
|
-
const focusableCount = focusableArr && focusableArr.length || 0;
|
|
171
|
-
(0, _console.logWarn)(focusableCount === 1, `[Focusable] Exactly one focusable child is required (${focusableCount} found).`);
|
|
172
|
-
const focusable = focusableArr ? focusableArr[0] : false;
|
|
173
|
-
if (focusable && typeof focusable.focus === 'function') {
|
|
174
|
-
return focusable;
|
|
175
|
-
} else {
|
|
176
|
-
return undefined;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
get focusVisible() {
|
|
180
|
-
const {
|
|
181
|
-
focusable,
|
|
182
|
-
focused
|
|
183
|
-
} = this.state;
|
|
184
|
-
return this.isFocusVisible(focused, focusable);
|
|
185
|
-
}
|
|
186
|
-
focus() {
|
|
187
|
-
const {
|
|
188
|
-
focusable
|
|
189
|
-
} = this;
|
|
190
|
-
if (focusable) {
|
|
191
|
-
focusable.focus();
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
ref = null;
|
|
195
|
-
attachRef = el => {
|
|
196
|
-
this.ref = el;
|
|
197
|
-
};
|
|
198
|
-
isFocusVisible(focused, focusable) {
|
|
199
|
-
if (!focusable || !focused) return false;
|
|
200
|
-
|
|
201
|
-
// always show focus for keyboard input mode
|
|
202
|
-
if (this._inputModeListener && this._inputModeListener.isKeyboardMode()) return true;
|
|
203
|
-
// note: the type property exist on input fields like HtmlInputElement
|
|
204
|
-
const {
|
|
205
|
-
tagName,
|
|
206
|
-
type,
|
|
207
|
-
isContentEditable
|
|
208
|
-
} = focusable;
|
|
209
|
-
if (tagName == 'INPUT' && Focusable.inputTypes[type]) {
|
|
210
|
-
return true;
|
|
211
|
-
}
|
|
212
|
-
if (tagName == 'TEXTAREA') {
|
|
213
|
-
return true;
|
|
214
|
-
}
|
|
215
|
-
return isContentEditable;
|
|
216
|
-
}
|
|
217
|
-
render() {
|
|
218
|
-
const {
|
|
219
|
-
children,
|
|
220
|
-
render = children
|
|
221
|
-
} = this.props;
|
|
222
|
-
const {
|
|
223
|
-
focusable,
|
|
224
|
-
focused
|
|
225
|
-
} = this.state;
|
|
226
|
-
if (typeof render === 'function') {
|
|
227
|
-
const rendered = render({
|
|
228
|
-
focused,
|
|
229
|
-
focusable,
|
|
230
|
-
focusVisible: this.isFocusVisible(focused, focusable),
|
|
231
|
-
attachRef: this.attachRef
|
|
232
|
-
});
|
|
233
|
-
return /*#__PURE__*/(0, _react.cloneElement)(rendered, {
|
|
234
|
-
ref: rendered.ref ? (0, _createChainedFunction.createChainedFunction)(rendered.ref, this.attachRef) : this.attachRef
|
|
235
|
-
});
|
|
236
|
-
} else {
|
|
237
|
-
return null;
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
exports.Focusable = Focusable;
|
|
242
|
-
var _default = exports.default = Focusable;
|
package/lib/Focusable/props.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.allowedProps = void 0;
|
|
7
|
-
/*
|
|
8
|
-
* The MIT License (MIT)
|
|
9
|
-
*
|
|
10
|
-
* Copyright (c) 2015 - present Instructure, Inc.
|
|
11
|
-
*
|
|
12
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
13
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
14
|
-
* in the Software without restriction, including without limitation the rights
|
|
15
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
16
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
17
|
-
* furnished to do so, subject to the following conditions:
|
|
18
|
-
*
|
|
19
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
20
|
-
* copies or substantial portions of the Software.
|
|
21
|
-
*
|
|
22
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
23
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
24
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
25
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
26
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
27
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
28
|
-
* SOFTWARE.
|
|
29
|
-
*/
|
|
30
|
-
|
|
31
|
-
const allowedProps = exports.allowedProps = ['children', 'render'];
|
package/lib/index.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
Object.defineProperty(exports, "Focusable", {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: function () {
|
|
9
|
-
return _index.Focusable;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
var _index = require("./Focusable/index.js");
|
package/lib/package.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"type":"commonjs"}
|