@instructure/ui-focusable 8.10.1-snapshot.4 → 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/CHANGELOG.md CHANGED
@@ -3,6 +3,10 @@
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
+ ## [8.10.1](https://github.com/instructure/instructure-ui/compare/v8.10.0...v8.10.1) (2021-10-01)
7
+
8
+ **Note:** Version bump only for package @instructure/ui-focusable
9
+
6
10
  # [8.10.0](https://github.com/instructure/instructure-ui/compare/v8.9.1...v8.10.0) (2021-09-28)
7
11
 
8
12
  **Note:** Version bump only for package @instructure/ui-focusable
@@ -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
- return render({
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;
@@ -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
- return render({
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.1-snapshot.4+6c5c9e653",
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.1-snapshot.4+6c5c9e653",
28
- "@instructure/ui-test-utils": "8.10.1-snapshot.4+6c5c9e653"
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.1-snapshot.4+6c5c9e653",
33
- "@instructure/ui-dom-utils": "8.10.1-snapshot.4+6c5c9e653",
34
- "@instructure/ui-react-utils": "8.10.1-snapshot.4+6c5c9e653",
35
- "@instructure/ui-utils": "8.10.1-snapshot.4+6c5c9e653",
36
- "@instructure/ui-view": "8.10.1-snapshot.4+6c5c9e653",
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": {
@@ -43,5 +43,5 @@
43
43
  "access": "public"
44
44
  },
45
45
  "sideEffects": false,
46
- "gitHead": "6c5c9e653f7ce3d239296f4ed19c5679fdddcd5b"
46
+ "gitHead": "b84160effefb01aeb94b754f0b7a64f8dad1b7f2"
47
47
  }
@@ -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
- return render({
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(): any;
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,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAWjC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAE7C;;;;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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