@instructure/ui-focusable 8.10.1 → 8.10.2-snapshot.22
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/LICENSE.md +27 -0
- package/es/Focusable/index.js +15 -4
- package/lib/Focusable/index.js +14 -2
- package/package.json +10 -9
- package/src/Focusable/index.tsx +17 -3
- package/types/Focusable/index.d.ts +5 -1
- package/types/Focusable/index.d.ts.map +1 -1
package/LICENSE.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: The MIT License (MIT)
|
|
3
|
+
category: Getting Started
|
|
4
|
+
order: 9
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# The MIT License (MIT)
|
|
8
|
+
|
|
9
|
+
Copyright (c) 2015 Instructure, Inc.
|
|
10
|
+
|
|
11
|
+
**Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
12
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
13
|
+
in the Software without restriction, including without limitation the rights
|
|
14
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
15
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
16
|
+
furnished to do so, subject to the following conditions.**
|
|
17
|
+
|
|
18
|
+
The above copyright notice and this permission notice shall be included in all
|
|
19
|
+
copies or substantial portions of the Software.
|
|
20
|
+
|
|
21
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
22
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
23
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
24
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
25
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
26
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
27
|
+
SOFTWARE.
|
package/es/Focusable/index.js
CHANGED
|
@@ -21,16 +21,17 @@
|
|
|
21
21
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
|
-
import { Component } from 'react';
|
|
24
|
+
import { cloneElement, Component } from 'react';
|
|
25
25
|
import { addInputModeListener, addEventListener, containsActiveElement, findFocusable } from '@instructure/ui-dom-utils';
|
|
26
26
|
import { logWarn as warn } from '@instructure/console';
|
|
27
27
|
import { propTypes, allowedProps } from './props';
|
|
28
|
-
|
|
28
|
+
import { createChainedFunction } from '@instructure/ui-utils';
|
|
29
29
|
/**
|
|
30
30
|
---
|
|
31
31
|
category: components/utilities
|
|
32
32
|
---
|
|
33
33
|
**/
|
|
34
|
+
|
|
34
35
|
class Focusable extends Component {
|
|
35
36
|
constructor(...args) {
|
|
36
37
|
super(...args);
|
|
@@ -59,6 +60,12 @@ class Focusable extends Component {
|
|
|
59
60
|
focused: false
|
|
60
61
|
});
|
|
61
62
|
};
|
|
63
|
+
|
|
64
|
+
this.ref = null;
|
|
65
|
+
|
|
66
|
+
this.attachRef = el => {
|
|
67
|
+
this.ref = el;
|
|
68
|
+
};
|
|
62
69
|
}
|
|
63
70
|
|
|
64
71
|
componentDidMount() {
|
|
@@ -217,10 +224,14 @@ class Focusable extends Component {
|
|
|
217
224
|
focused = _this$state2.focused;
|
|
218
225
|
|
|
219
226
|
if (typeof render === 'function') {
|
|
220
|
-
|
|
227
|
+
const rendered = render({
|
|
221
228
|
focused,
|
|
222
229
|
focusable,
|
|
223
|
-
focusVisible: this.isFocusVisible(focusable, focused)
|
|
230
|
+
focusVisible: this.isFocusVisible(focusable, focused),
|
|
231
|
+
attachRef: this.attachRef
|
|
232
|
+
});
|
|
233
|
+
return /*#__PURE__*/cloneElement(rendered, {
|
|
234
|
+
ref: rendered.ref ? createChainedFunction(rendered.ref, this.attachRef) : this.attachRef
|
|
224
235
|
});
|
|
225
236
|
} else {
|
|
226
237
|
return null;
|
package/lib/Focusable/index.js
CHANGED
|
@@ -19,6 +19,8 @@ var _console = require("@instructure/console");
|
|
|
19
19
|
|
|
20
20
|
var _props = require("./props");
|
|
21
21
|
|
|
22
|
+
var _createChainedFunction = require("@instructure/ui-utils/lib/createChainedFunction.js");
|
|
23
|
+
|
|
22
24
|
/*
|
|
23
25
|
* The MIT License (MIT)
|
|
24
26
|
*
|
|
@@ -76,6 +78,12 @@ class Focusable extends _react.Component {
|
|
|
76
78
|
focused: false
|
|
77
79
|
});
|
|
78
80
|
};
|
|
81
|
+
|
|
82
|
+
this.ref = null;
|
|
83
|
+
|
|
84
|
+
this.attachRef = el => {
|
|
85
|
+
this.ref = el;
|
|
86
|
+
};
|
|
79
87
|
}
|
|
80
88
|
|
|
81
89
|
componentDidMount() {
|
|
@@ -234,10 +242,14 @@ class Focusable extends _react.Component {
|
|
|
234
242
|
focused = _this$state2.focused;
|
|
235
243
|
|
|
236
244
|
if (typeof render === 'function') {
|
|
237
|
-
|
|
245
|
+
const rendered = render({
|
|
238
246
|
focused,
|
|
239
247
|
focusable,
|
|
240
|
-
focusVisible: this.isFocusVisible(focusable, focused)
|
|
248
|
+
focusVisible: this.isFocusVisible(focusable, focused),
|
|
249
|
+
attachRef: this.attachRef
|
|
250
|
+
});
|
|
251
|
+
return /*#__PURE__*/(0, _react.cloneElement)(rendered, {
|
|
252
|
+
ref: rendered.ref ? (0, _createChainedFunction.createChainedFunction)(rendered.ref, this.attachRef) : this.attachRef
|
|
241
253
|
});
|
|
242
254
|
} else {
|
|
243
255
|
return null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@instructure/ui-focusable",
|
|
3
|
-
"version": "8.10.
|
|
3
|
+
"version": "8.10.2-snapshot.22+b84160eff",
|
|
4
4
|
"description": "A utility used to identify when an element receives focus.",
|
|
5
5
|
"author": "Instructure, Inc. Engineering and Product Design",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -24,16 +24,16 @@
|
|
|
24
24
|
},
|
|
25
25
|
"license": "MIT",
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@instructure/ui-babel-preset": "8.10.
|
|
28
|
-
"@instructure/ui-test-utils": "8.10.
|
|
27
|
+
"@instructure/ui-babel-preset": "8.10.2-snapshot.22+b84160eff",
|
|
28
|
+
"@instructure/ui-test-utils": "8.10.2-snapshot.22+b84160eff"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@babel/runtime": "^7.13.10",
|
|
32
|
-
"@instructure/console": "8.10.
|
|
33
|
-
"@instructure/ui-dom-utils": "8.10.
|
|
34
|
-
"@instructure/ui-react-utils": "8.10.
|
|
35
|
-
"@instructure/ui-utils": "8.10.
|
|
36
|
-
"@instructure/ui-view": "8.10.
|
|
32
|
+
"@instructure/console": "8.10.2-snapshot.22+b84160eff",
|
|
33
|
+
"@instructure/ui-dom-utils": "8.10.2-snapshot.22+b84160eff",
|
|
34
|
+
"@instructure/ui-react-utils": "8.10.2-snapshot.22+b84160eff",
|
|
35
|
+
"@instructure/ui-utils": "8.10.2-snapshot.22+b84160eff",
|
|
36
|
+
"@instructure/ui-view": "8.10.2-snapshot.22+b84160eff",
|
|
37
37
|
"prop-types": "^15"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
@@ -42,5 +42,6 @@
|
|
|
42
42
|
"publishConfig": {
|
|
43
43
|
"access": "public"
|
|
44
44
|
},
|
|
45
|
-
"sideEffects": false
|
|
45
|
+
"sideEffects": false,
|
|
46
|
+
"gitHead": "b84160effefb01aeb94b754f0b7a64f8dad1b7f2"
|
|
46
47
|
}
|
package/src/Focusable/index.tsx
CHANGED
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
|
-
import { Component } from 'react'
|
|
25
|
+
import { cloneElement, Component } from 'react'
|
|
26
26
|
|
|
27
27
|
import {
|
|
28
28
|
addInputModeListener,
|
|
@@ -34,6 +34,7 @@ import { logWarn as warn } from '@instructure/console'
|
|
|
34
34
|
|
|
35
35
|
import { propTypes, allowedProps } from './props'
|
|
36
36
|
import type { FocusableProps } from './props'
|
|
37
|
+
import { createChainedFunction } from '@instructure/ui-utils'
|
|
37
38
|
|
|
38
39
|
/**
|
|
39
40
|
---
|
|
@@ -225,6 +226,12 @@ class Focusable extends Component<FocusableProps> {
|
|
|
225
226
|
}
|
|
226
227
|
}
|
|
227
228
|
|
|
229
|
+
ref: Element | null = null
|
|
230
|
+
|
|
231
|
+
attachRef = (el: Element) => {
|
|
232
|
+
this.ref = el
|
|
233
|
+
}
|
|
234
|
+
|
|
228
235
|
// @ts-expect-error ts-migrate(7006) FIXME: Parameter 'focusable' implicitly has an 'any' type... Remove this comment to see the full error message
|
|
229
236
|
isFocusVisible(focusable, focused) {
|
|
230
237
|
if (!focusable || !focused) return false
|
|
@@ -256,10 +263,17 @@ class Focusable extends Component<FocusableProps> {
|
|
|
256
263
|
const { focusable, focused } = this.state
|
|
257
264
|
|
|
258
265
|
if (typeof render === 'function') {
|
|
259
|
-
|
|
266
|
+
const rendered = render({
|
|
260
267
|
focused,
|
|
261
268
|
focusable,
|
|
262
|
-
focusVisible: this.isFocusVisible(focusable, focused)
|
|
269
|
+
focusVisible: this.isFocusVisible(focusable, focused),
|
|
270
|
+
attachRef: this.attachRef
|
|
271
|
+
})
|
|
272
|
+
|
|
273
|
+
return cloneElement(rendered, {
|
|
274
|
+
ref: rendered.ref
|
|
275
|
+
? createChainedFunction(rendered.ref, this.attachRef)
|
|
276
|
+
: this.attachRef
|
|
263
277
|
})
|
|
264
278
|
} else {
|
|
265
279
|
return null
|
|
@@ -61,8 +61,12 @@ declare class Focusable extends Component<FocusableProps> {
|
|
|
61
61
|
get focusable(): false | Element[];
|
|
62
62
|
get focusVisible(): boolean;
|
|
63
63
|
focus(): void;
|
|
64
|
+
ref: Element | null;
|
|
65
|
+
attachRef: (el: Element) => void;
|
|
64
66
|
isFocusVisible(focusable: any, focused: any): boolean;
|
|
65
|
-
render():
|
|
67
|
+
render(): import("react").FunctionComponentElement<{
|
|
68
|
+
ref: (...args: any[]) => any;
|
|
69
|
+
}> | null;
|
|
66
70
|
}
|
|
67
71
|
export default Focusable;
|
|
68
72
|
export { Focusable };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/Focusable/index.tsx"],"names":[],"mappings":"AAwBA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/Focusable/index.tsx"],"names":[],"mappings":"AAwBA,OAAO,EAAgB,SAAS,EAAE,MAAM,OAAO,CAAA;AAW/C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAG7C;;;;GAIG;AACH,cAAM,SAAU,SAAQ,SAAS,CAAC,cAAc,CAAC;IAC/C,MAAM,CAAC,SAAS;;;OAAY;IAC5B,MAAM,CAAC,YAAY;;;SAAe;IAClC,MAAM,CAAC,YAAY;;MAElB;IAED,MAAM,CAAC,UAAU;;;;;;;;;;;;;;MAchB;IAED,cAAc,EAAE;QAAE,MAAM,IAAI,IAAI,CAAA;KAAE,GAAG,IAAI,CAAO;IAChD,aAAa,EAAE;QAAE,MAAM,IAAI,IAAI,CAAA;KAAE,GAAG,IAAI,CAAO;IAC/C,kBAAkB,EAAE;QAClB,cAAc,IAAI,OAAO,CAAA;QACzB,MAAM,IAAI,IAAI,CAAA;KACf,GAAG,IAAI,CAAO;IAEf,KAAK;;;MAGJ;IAED,iBAAiB;IAajB,uBAAuB,CAAC,SAAS,KAAA,EAAE,SAAS,KAAA;IAU5C,kBAAkB,CAAC,SAAS,KAAA,EAAE,SAAS,KAAA;IA0BvC,oBAAoB;IASpB,qBAAqB,CAAC,SAAS,KAAA,EAAE,OAAO,KAAA;IAoBxC,wBAAwB;IAKxB,mBAAmB;IAOnB,kBAAkB;IAOlB,qBAAqB,aAEpB;IAGD,WAAW,uBAGV;IAGD,UAAU,uBAGT;IAED,IAAI,OAAO,YAEV;IAED,IAAI,SAAS,sBAkBZ;IAED,IAAI,YAAY,YAGf;IAED,KAAK;IAQL,GAAG,EAAE,OAAO,GAAG,IAAI,CAAO;IAE1B,SAAS,OAAQ,OAAO,UAEvB;IAGD,cAAc,CAAC,SAAS,KAAA,EAAE,OAAO,KAAA;IAyBjC,MAAM;;;CAqBP;AAED,eAAe,SAAS,CAAA;AACxB,OAAO,EAAE,SAAS,EAAE,CAAA"}
|