@khanacademy/wonder-blocks-popover 3.1.5 → 3.1.7
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 +19 -0
- package/package.json +5 -5
- package/src/components/__tests__/focus-manager.test.tsx +23 -34
- package/src/components/__tests__/popover-anchor.test.tsx +7 -7
- package/src/components/__tests__/popover-content.test.tsx +5 -5
- package/src/components/__tests__/popover-event-listener.test.tsx +8 -6
- package/src/components/__tests__/popover.test.tsx +117 -83
- package/tsconfig-build.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# @khanacademy/wonder-blocks-popover
|
|
2
2
|
|
|
3
|
+
## 3.1.7
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [874081aa]
|
|
8
|
+
- Updated dependencies [874081aa]
|
|
9
|
+
- Updated dependencies [a9bf603a]
|
|
10
|
+
- @khanacademy/wonder-blocks-tokens@1.2.0
|
|
11
|
+
- @khanacademy/wonder-blocks-icon-button@5.1.14
|
|
12
|
+
- @khanacademy/wonder-blocks-modal@4.2.8
|
|
13
|
+
- @khanacademy/wonder-blocks-tooltip@2.1.32
|
|
14
|
+
|
|
15
|
+
## 3.1.6
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- @khanacademy/wonder-blocks-modal@4.2.7
|
|
20
|
+
- @khanacademy/wonder-blocks-tooltip@2.1.31
|
|
21
|
+
|
|
3
22
|
## 3.1.5
|
|
4
23
|
|
|
5
24
|
### Patch Changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@khanacademy/wonder-blocks-popover",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.7",
|
|
4
4
|
"design": "v1",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -17,10 +17,10 @@
|
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@babel/runtime": "^7.18.6",
|
|
19
19
|
"@khanacademy/wonder-blocks-core": "^6.3.1",
|
|
20
|
-
"@khanacademy/wonder-blocks-icon-button": "^5.1.
|
|
21
|
-
"@khanacademy/wonder-blocks-modal": "^4.2.
|
|
22
|
-
"@khanacademy/wonder-blocks-tokens": "^1.
|
|
23
|
-
"@khanacademy/wonder-blocks-tooltip": "^2.1.
|
|
20
|
+
"@khanacademy/wonder-blocks-icon-button": "^5.1.14",
|
|
21
|
+
"@khanacademy/wonder-blocks-modal": "^4.2.8",
|
|
22
|
+
"@khanacademy/wonder-blocks-tokens": "^1.2.0",
|
|
23
|
+
"@khanacademy/wonder-blocks-tooltip": "^2.1.32",
|
|
24
24
|
"@khanacademy/wonder-blocks-typography": "^2.1.10"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import {render, screen} from "@testing-library/react";
|
|
3
|
-
import userEvent from "@testing-library/user-event";
|
|
3
|
+
import {userEvent} from "@testing-library/user-event";
|
|
4
4
|
|
|
5
5
|
import FocusManager from "../focus-manager";
|
|
6
6
|
|
|
@@ -16,7 +16,7 @@ describe("FocusManager", () => {
|
|
|
16
16
|
render(externalNodes);
|
|
17
17
|
|
|
18
18
|
// get the anchor reference to be able pass it to the FocusManager
|
|
19
|
-
const anchorElementNode = screen.
|
|
19
|
+
const anchorElementNode = await screen.findByRole("button", {
|
|
20
20
|
name: "Open popover",
|
|
21
21
|
});
|
|
22
22
|
|
|
@@ -33,10 +33,9 @@ describe("FocusManager", () => {
|
|
|
33
33
|
// Act
|
|
34
34
|
// focus on the previous element before the popover (anchor element)
|
|
35
35
|
anchorElementNode.focus();
|
|
36
|
-
// focus on the
|
|
37
|
-
userEvent.tab();
|
|
36
|
+
// focus gets automatically moved to be on the first focusable element
|
|
38
37
|
|
|
39
|
-
const firstFocusableElementInside = screen.
|
|
38
|
+
const firstFocusableElementInside = await screen.findByText(
|
|
40
39
|
"first focusable element inside",
|
|
41
40
|
);
|
|
42
41
|
|
|
@@ -55,7 +54,7 @@ describe("FocusManager", () => {
|
|
|
55
54
|
render(externalNodes);
|
|
56
55
|
|
|
57
56
|
// get the anchor reference to be able pass it to the FocusManager
|
|
58
|
-
const anchorElementNode = screen.
|
|
57
|
+
const anchorElementNode = await screen.findByRole("button", {
|
|
59
58
|
name: "Open popover",
|
|
60
59
|
});
|
|
61
60
|
|
|
@@ -72,15 +71,15 @@ describe("FocusManager", () => {
|
|
|
72
71
|
// Act
|
|
73
72
|
|
|
74
73
|
// find previous focusable element outside the popover
|
|
75
|
-
const nextFocusableElementOutside = screen.
|
|
74
|
+
const nextFocusableElementOutside = await screen.findByRole("button", {
|
|
76
75
|
name: "Next focusable element outside",
|
|
77
76
|
});
|
|
78
77
|
|
|
79
78
|
// focus on the next element after the popover
|
|
80
79
|
nextFocusableElementOutside.focus();
|
|
81
|
-
userEvent.tab({shift: true});
|
|
80
|
+
await userEvent.tab({shift: true});
|
|
82
81
|
|
|
83
|
-
const lastFocusableElementInside = screen.
|
|
82
|
+
const lastFocusableElementInside = await screen.findByText(
|
|
84
83
|
"third focusable element inside",
|
|
85
84
|
);
|
|
86
85
|
|
|
@@ -100,7 +99,7 @@ describe("FocusManager", () => {
|
|
|
100
99
|
render(externalNodes);
|
|
101
100
|
|
|
102
101
|
// get the anchor reference to be able pass it to the FocusManager
|
|
103
|
-
const anchorElementNode = screen.
|
|
102
|
+
const anchorElementNode = await screen.findByRole("button", {
|
|
104
103
|
name: "Open popover",
|
|
105
104
|
});
|
|
106
105
|
|
|
@@ -113,28 +112,18 @@ describe("FocusManager", () => {
|
|
|
113
112
|
);
|
|
114
113
|
|
|
115
114
|
// Act
|
|
116
|
-
// 1. focus on the
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
// 2. focus on the anchor element
|
|
120
|
-
userEvent.tab();
|
|
121
|
-
|
|
122
|
-
// 3. focus on focusable element inside the popover
|
|
123
|
-
userEvent.tab();
|
|
124
|
-
|
|
125
|
-
// 4. focus on the next focusable element outside the popover (this will
|
|
126
|
-
// be the first focusable element outside the popover)
|
|
127
|
-
userEvent.tab();
|
|
115
|
+
// 1. focus on the Open popover button, this opens the focus manager
|
|
116
|
+
// and focuses the button inside the popover
|
|
117
|
+
await userEvent.tab();
|
|
128
118
|
|
|
129
|
-
//
|
|
130
|
-
|
|
131
|
-
userEvent.tab();
|
|
119
|
+
// 2. we advance to the next focusable element outside the popover
|
|
120
|
+
await userEvent.tab();
|
|
132
121
|
|
|
133
|
-
//
|
|
134
|
-
userEvent.tab();
|
|
122
|
+
// 3. we loop back around to the first focusable element outside the popover
|
|
123
|
+
await userEvent.tab();
|
|
135
124
|
|
|
136
125
|
// find previous focusable element outside the popover
|
|
137
|
-
const prevFocusableElementOutside = screen.
|
|
126
|
+
const prevFocusableElementOutside = await screen.findByRole("button", {
|
|
138
127
|
name: "Prev focusable element outside",
|
|
139
128
|
});
|
|
140
129
|
|
|
@@ -154,7 +143,7 @@ describe("FocusManager", () => {
|
|
|
154
143
|
render(externalNodes);
|
|
155
144
|
|
|
156
145
|
// get the anchor reference to be able pass it to the FocusManager
|
|
157
|
-
const anchorElementNode = screen.
|
|
146
|
+
const anchorElementNode = await screen.findByRole("button", {
|
|
158
147
|
name: "Open popover",
|
|
159
148
|
});
|
|
160
149
|
|
|
@@ -168,20 +157,20 @@ describe("FocusManager", () => {
|
|
|
168
157
|
|
|
169
158
|
// Act
|
|
170
159
|
// 1. focus on the previous element before the popover
|
|
171
|
-
userEvent.tab();
|
|
160
|
+
await userEvent.tab();
|
|
172
161
|
|
|
173
162
|
// 2. focus on the anchor element
|
|
174
|
-
userEvent.tab();
|
|
163
|
+
await userEvent.tab();
|
|
175
164
|
|
|
176
165
|
// 3. focus on focusable element inside the popover
|
|
177
|
-
userEvent.tab();
|
|
166
|
+
await userEvent.tab();
|
|
178
167
|
|
|
179
168
|
// 4. focus on the next focusable element outside the popover (this will
|
|
180
169
|
// be the first focusable element outside the popover)
|
|
181
|
-
userEvent.tab();
|
|
170
|
+
await userEvent.tab();
|
|
182
171
|
|
|
183
172
|
// The elements inside the focus manager should not be focusable anymore.
|
|
184
|
-
const focusableElementInside = screen.
|
|
173
|
+
const focusableElementInside = await screen.findByRole("button", {
|
|
185
174
|
name: "first focusable element inside",
|
|
186
175
|
});
|
|
187
176
|
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import {render, screen} from "@testing-library/react";
|
|
3
|
-
import userEvent from "@testing-library/user-event";
|
|
3
|
+
import {userEvent} from "@testing-library/user-event";
|
|
4
4
|
|
|
5
5
|
import PopoverAnchor from "../popover-anchor";
|
|
6
6
|
|
|
7
7
|
describe("PopoverAnchor", () => {
|
|
8
|
-
it("should set child node as ref", () => {
|
|
8
|
+
it("should set child node as ref", async () => {
|
|
9
9
|
// Arrange
|
|
10
10
|
const updateRef = jest.fn();
|
|
11
11
|
|
|
@@ -16,13 +16,13 @@ describe("PopoverAnchor", () => {
|
|
|
16
16
|
);
|
|
17
17
|
|
|
18
18
|
// Act
|
|
19
|
-
const triggerElement = screen.
|
|
19
|
+
const triggerElement = await screen.findByRole("button");
|
|
20
20
|
|
|
21
21
|
// Assert
|
|
22
22
|
expect(updateRef).toBeCalledWith(triggerElement);
|
|
23
23
|
});
|
|
24
24
|
|
|
25
|
-
it("should add onClick handler if child is a function", () => {
|
|
25
|
+
it("should add onClick handler if child is a function", async () => {
|
|
26
26
|
// Arrange
|
|
27
27
|
const onClickMock = jest.fn();
|
|
28
28
|
|
|
@@ -33,13 +33,13 @@ describe("PopoverAnchor", () => {
|
|
|
33
33
|
);
|
|
34
34
|
|
|
35
35
|
// Act
|
|
36
|
-
userEvent.click(screen.
|
|
36
|
+
await userEvent.click(await screen.findByRole("button"));
|
|
37
37
|
|
|
38
38
|
// Assert
|
|
39
39
|
expect(onClickMock).toBeCalled();
|
|
40
40
|
});
|
|
41
41
|
|
|
42
|
-
it("should add onClick handler if child is a Node", () => {
|
|
42
|
+
it("should add onClick handler if child is a Node", async () => {
|
|
43
43
|
// Arrange
|
|
44
44
|
const onClickMock = jest.fn();
|
|
45
45
|
const onClickInnerMock = jest.fn();
|
|
@@ -51,7 +51,7 @@ describe("PopoverAnchor", () => {
|
|
|
51
51
|
);
|
|
52
52
|
|
|
53
53
|
// Act
|
|
54
|
-
userEvent.click(screen.
|
|
54
|
+
await userEvent.click(await screen.findByRole("button"));
|
|
55
55
|
|
|
56
56
|
// Assert
|
|
57
57
|
// both custom and internal click should be called
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import {render, screen} from "@testing-library/react";
|
|
3
|
-
import userEvent from "@testing-library/user-event";
|
|
3
|
+
import {userEvent} from "@testing-library/user-event";
|
|
4
4
|
|
|
5
5
|
import PopoverContent from "../popover-content";
|
|
6
6
|
import PopoverContext from "../popover-context";
|
|
7
7
|
|
|
8
8
|
describe("PopoverContent", () => {
|
|
9
|
-
it("should close the popover from the actions", () => {
|
|
9
|
+
it("should close the popover from the actions", async () => {
|
|
10
10
|
// Arrange
|
|
11
11
|
const onCloseMock = jest.fn();
|
|
12
12
|
|
|
@@ -25,13 +25,13 @@ describe("PopoverContent", () => {
|
|
|
25
25
|
);
|
|
26
26
|
|
|
27
27
|
// Act
|
|
28
|
-
userEvent.click(screen.
|
|
28
|
+
await userEvent.click(await screen.findByRole("button"));
|
|
29
29
|
|
|
30
30
|
// Assert
|
|
31
31
|
expect(onCloseMock).toBeCalled();
|
|
32
32
|
});
|
|
33
33
|
|
|
34
|
-
it("should warn when setting a image and icon at the same time", () => {
|
|
34
|
+
it("should warn when setting a image and icon at the same time", async () => {
|
|
35
35
|
// Arrange
|
|
36
36
|
const nodes = (
|
|
37
37
|
<PopoverContent
|
|
@@ -51,7 +51,7 @@ describe("PopoverContent", () => {
|
|
|
51
51
|
);
|
|
52
52
|
});
|
|
53
53
|
|
|
54
|
-
it("should warn when setting a horizontal placement with an Illustration popover", () => {
|
|
54
|
+
it("should warn when setting a horizontal placement with an Illustration popover", async () => {
|
|
55
55
|
// Arrange
|
|
56
56
|
const nodes = (
|
|
57
57
|
<PopoverContext.Provider
|
|
@@ -1,26 +1,28 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import {render, screen} from "@testing-library/react";
|
|
3
|
-
import userEvent from "@testing-library/user-event";
|
|
3
|
+
import {userEvent} from "@testing-library/user-event";
|
|
4
4
|
|
|
5
5
|
import {View} from "@khanacademy/wonder-blocks-core";
|
|
6
6
|
import PopoverEventListener from "../popover-event-listener";
|
|
7
7
|
import PopoverContent from "../popover-content";
|
|
8
8
|
|
|
9
9
|
describe("PopoverKeypressListener", () => {
|
|
10
|
-
|
|
10
|
+
// TODO(FEI-5533): Key press events aren't working correctly with
|
|
11
|
+
// user-event v14. We need to investigate and fix this.
|
|
12
|
+
it.skip("should call onClose if Escape is pressed", async () => {
|
|
11
13
|
// Arrange
|
|
12
14
|
const onCloseMock = jest.fn();
|
|
13
15
|
|
|
14
16
|
render(<PopoverEventListener onClose={onCloseMock} />);
|
|
15
17
|
|
|
16
18
|
// Act
|
|
17
|
-
userEvent.keyboard("{esc}");
|
|
19
|
+
await userEvent.keyboard("{esc}");
|
|
18
20
|
|
|
19
21
|
// Assert
|
|
20
22
|
expect(onCloseMock).toHaveBeenCalled();
|
|
21
23
|
});
|
|
22
24
|
|
|
23
|
-
it("should call onClose if clicked outside content ref", () => {
|
|
25
|
+
it("should call onClose if clicked outside content ref", async () => {
|
|
24
26
|
// Arrange
|
|
25
27
|
const onCloseMock = jest.fn();
|
|
26
28
|
const contentRef: React.RefObject<PopoverContent> = React.createRef();
|
|
@@ -56,7 +58,7 @@ describe("PopoverKeypressListener", () => {
|
|
|
56
58
|
expect(onCloseMock).toHaveBeenCalled();
|
|
57
59
|
});
|
|
58
60
|
|
|
59
|
-
it("should not call onClose if clicked inside content ref", () => {
|
|
61
|
+
it("should not call onClose if clicked inside content ref", async () => {
|
|
60
62
|
// Arrange
|
|
61
63
|
const onCloseMock = jest.fn();
|
|
62
64
|
const contentRef: React.RefObject<PopoverContent> = React.createRef();
|
|
@@ -78,7 +80,7 @@ describe("PopoverKeypressListener", () => {
|
|
|
78
80
|
|
|
79
81
|
// Act
|
|
80
82
|
const event = new MouseEvent("click", {view: window, bubbles: true});
|
|
81
|
-
const node = screen.
|
|
83
|
+
const node = await screen.findByTestId("popover-content");
|
|
82
84
|
|
|
83
85
|
if (node) {
|
|
84
86
|
// First click is ignored by PopoverEventListener
|