@khanacademy/wonder-blocks-popover 1.1.4 → 1.1.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@khanacademy/wonder-blocks-popover",
3
- "version": "1.1.4",
3
+ "version": "1.1.5",
4
4
  "design": "v1",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -15,16 +15,16 @@
15
15
  "author": "",
16
16
  "license": "MIT",
17
17
  "dependencies": {
18
- "@babel/runtime": "^7.13.10",
19
- "@khanacademy/wonder-blocks-color": "^1.1.19",
20
- "@khanacademy/wonder-blocks-core": "^3.2.0",
21
- "@khanacademy/wonder-blocks-icon": "^1.2.23",
22
- "@khanacademy/wonder-blocks-icon-button": "^3.4.0",
23
- "@khanacademy/wonder-blocks-layout": "^1.4.5",
24
- "@khanacademy/wonder-blocks-modal": "^2.1.44",
25
- "@khanacademy/wonder-blocks-spacing": "^3.0.4",
26
- "@khanacademy/wonder-blocks-tooltip": "^1.3.4",
27
- "@khanacademy/wonder-blocks-typography": "^1.1.27"
18
+ "@babel/runtime": "^7.16.3",
19
+ "@khanacademy/wonder-blocks-color": "^1.1.20",
20
+ "@khanacademy/wonder-blocks-core": "^4.0.0",
21
+ "@khanacademy/wonder-blocks-icon": "^1.2.24",
22
+ "@khanacademy/wonder-blocks-icon-button": "^3.4.1",
23
+ "@khanacademy/wonder-blocks-layout": "^1.4.6",
24
+ "@khanacademy/wonder-blocks-modal": "^2.1.45",
25
+ "@khanacademy/wonder-blocks-spacing": "^3.0.5",
26
+ "@khanacademy/wonder-blocks-tooltip": "^1.3.5",
27
+ "@khanacademy/wonder-blocks-typography": "^1.1.28"
28
28
  },
29
29
  "peerDependencies": {
30
30
  "@popperjs/core": "^2.10.1",
@@ -34,7 +34,7 @@
34
34
  "react-popper": "^2.0.0"
35
35
  },
36
36
  "devDependencies": {
37
- "wb-dev-build-settings": "^0.1.2"
37
+ "wb-dev-build-settings": "^0.2.0"
38
38
  },
39
- "gitHead": "b6193f70c73e70fbaf76bc688dc69a47fb1d0ef3"
39
+ "gitHead": "9ebea88533e702011165072f090a377e02fa3f0f"
40
40
  }
@@ -6,9 +6,28 @@ import {mount} from "enzyme";
6
6
  import FocusManager from "../focus-manager.js";
7
7
  import {findFocusableNodes} from "../../util/util.js";
8
8
 
9
+ import {unmountAll} from "../../../../../utils/testing/enzyme-shim.js";
10
+ import {getElementAttachedToDocument} from "../../../../../utils/testing/get-element-attached-to-document.js";
11
+
9
12
  describe("FocusManager", () => {
13
+ beforeEach(() => {
14
+ jest.useRealTimers();
15
+ });
16
+
17
+ afterEach(() => {
18
+ unmountAll();
19
+ if (document.body) {
20
+ document.body.innerHTML = "";
21
+ }
22
+ });
23
+
10
24
  it("should focus on the first focusable element inside the popover", async () => {
11
25
  // Arrange
26
+ // We need the elements in the DOM document for the focus() calls to
27
+ // work.
28
+ const containerDiv = getElementAttachedToDocument("container");
29
+ const focusManagerDiv = getElementAttachedToDocument("focusManagerDiv");
30
+
12
31
  const ref = await new Promise((resolve) => {
13
32
  const nodes = (
14
33
  <div ref={resolve}>
@@ -16,7 +35,7 @@ describe("FocusManager", () => {
16
35
  <button data-next />
17
36
  </div>
18
37
  );
19
- mount(nodes);
38
+ mount(nodes, {attachTo: containerDiv});
20
39
  });
21
40
  const domNode = ((ReactDOM.findDOMNode(ref): any): HTMLElement);
22
41
 
@@ -38,10 +57,10 @@ describe("FocusManager", () => {
38
57
  <button data-tab-index="2" />
39
58
  </div>
40
59
  </FocusManager>,
60
+ {attachTo: focusManagerDiv},
41
61
  );
42
62
 
43
63
  // Act
44
-
45
64
  // focus on the previous element before the popover (anchor element)
46
65
  anchorElementNode.focus();
47
66
  // press `tab` to focus on the next element
@@ -61,6 +80,11 @@ describe("FocusManager", () => {
61
80
 
62
81
  it("should focus on the last focusable element inside the popover", async () => {
63
82
  // Arrange
83
+ // We need the elements in the DOM document for the focus() calls to
84
+ // work.
85
+ const containerDiv = getElementAttachedToDocument("container");
86
+ const focusManagerDiv = getElementAttachedToDocument("focusManagerDiv");
87
+
64
88
  const ref = await new Promise((resolve) => {
65
89
  const nodes = (
66
90
  <div ref={resolve}>
@@ -68,7 +92,7 @@ describe("FocusManager", () => {
68
92
  <button data-next />
69
93
  </div>
70
94
  );
71
- mount(nodes);
95
+ mount(nodes, {attachTo: containerDiv});
72
96
  });
73
97
  const domNode = ((ReactDOM.findDOMNode(ref): any): HTMLElement);
74
98
 
@@ -90,6 +114,7 @@ describe("FocusManager", () => {
90
114
  <button data-tab-index="2" />
91
115
  </div>
92
116
  </FocusManager>,
117
+ {attachTo: focusManagerDiv},
93
118
  );
94
119
 
95
120
  // Act
@@ -1,8 +1,6 @@
1
1
  // @flow
2
2
  import * as React from "react";
3
3
  import {render, screen} from "@testing-library/react";
4
- // eslint-disable-next-line import/no-unassigned-import
5
- import "@testing-library/jest-dom/extend-expect";
6
4
 
7
5
  import InitialFocus from "../initial-focus.js";
8
6
 
@@ -161,9 +161,8 @@ export default class Popover extends React.Component<Props, State> {
161
161
  /**
162
162
  * Popover content ref
163
163
  */
164
- contentRef: RefObject<
165
- PopoverContent | PopoverContentCore,
166
- > = React.createRef();
164
+ contentRef: RefObject<PopoverContent | PopoverContentCore> =
165
+ React.createRef();
167
166
 
168
167
  /**
169
168
  * Popover dialog closed