@khanacademy/wonder-blocks-clickable 2.2.0 → 2.2.1
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-clickable",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.1",
|
|
4
4
|
"design": "v1",
|
|
5
5
|
"description": "Clickable component for Wonder-Blocks.",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
"access": "public"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@babel/runtime": "^7.
|
|
19
|
-
"@khanacademy/wonder-blocks-core": "^
|
|
18
|
+
"@babel/runtime": "^7.16.3",
|
|
19
|
+
"@khanacademy/wonder-blocks-core": "^4.0.0"
|
|
20
20
|
},
|
|
21
21
|
"peerDependencies": {
|
|
22
22
|
"aphrodite": "^1.2.5",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"react-router-dom": "5.3.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"wb-dev-build-settings": "^0.
|
|
29
|
+
"wb-dev-build-settings": "^0.2.0"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "9ebea88533e702011165072f090a377e02fa3f0f"
|
|
32
32
|
}
|
|
@@ -22,8 +22,9 @@ const wait = (delay: number = 0) =>
|
|
|
22
22
|
describe("ClickableBehavior", () => {
|
|
23
23
|
beforeEach(() => {
|
|
24
24
|
// Note: window.location.assign and window.open need mock functions in
|
|
25
|
-
// the testing environment
|
|
26
|
-
window.location
|
|
25
|
+
// the testing environment
|
|
26
|
+
delete window.location;
|
|
27
|
+
window.location = {assign: jest.fn()};
|
|
27
28
|
window.open = jest.fn();
|
|
28
29
|
});
|
|
29
30
|
|
|
@@ -566,6 +567,7 @@ describe("ClickableBehavior", () => {
|
|
|
566
567
|
const button = wrapper.find("#test-button").first();
|
|
567
568
|
button.simulate("click", {
|
|
568
569
|
preventDefault() {
|
|
570
|
+
// $FlowIgnore[object-this-reference]
|
|
569
571
|
this.defaultPrevented = true;
|
|
570
572
|
},
|
|
571
573
|
});
|
|
@@ -1052,6 +1054,7 @@ describe("ClickableBehavior", () => {
|
|
|
1052
1054
|
const button = wrapper.find("#test-button").first();
|
|
1053
1055
|
button.simulate("click", {
|
|
1054
1056
|
preventDefault() {
|
|
1057
|
+
// $FlowIgnore[object-this-reference]
|
|
1055
1058
|
this.defaultPrevented = true;
|
|
1056
1059
|
},
|
|
1057
1060
|
});
|
|
@@ -13,6 +13,11 @@ const wait = (delay: number = 0) =>
|
|
|
13
13
|
});
|
|
14
14
|
|
|
15
15
|
describe("Clickable", () => {
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
delete window.location;
|
|
18
|
+
window.location = {assign: jest.fn()};
|
|
19
|
+
});
|
|
20
|
+
|
|
16
21
|
test("client-side navigation", () => {
|
|
17
22
|
// Arrange
|
|
18
23
|
const wrapper = mount(
|
|
@@ -129,8 +134,6 @@ describe("Clickable", () => {
|
|
|
129
134
|
|
|
130
135
|
test("should navigate to a specific link using the keyboard", () => {
|
|
131
136
|
// Arrange
|
|
132
|
-
window.location.assign = jest.fn();
|
|
133
|
-
|
|
134
137
|
const wrapper = mount(
|
|
135
138
|
<Clickable testId="button" href="/foo" skipClientNav={true}>
|
|
136
139
|
{(eventState) => <h1>Click Me!</h1>}
|
|
@@ -276,7 +279,6 @@ describe("Clickable", () => {
|
|
|
276
279
|
|
|
277
280
|
test("safeWithNav with skipClientNav=true waits for promise resolution", async () => {
|
|
278
281
|
// Arrange
|
|
279
|
-
jest.spyOn(window.location, "assign");
|
|
280
282
|
const wrapper = mount(
|
|
281
283
|
<MemoryRouter>
|
|
282
284
|
<div>
|
|
@@ -309,7 +311,6 @@ describe("Clickable", () => {
|
|
|
309
311
|
|
|
310
312
|
test("beforeNav resolution and safeWithNav with skipClientNav=true waits for promise resolution", async () => {
|
|
311
313
|
// Arrange
|
|
312
|
-
jest.spyOn(window.location, "assign");
|
|
313
314
|
const wrapper = mount(
|
|
314
315
|
<MemoryRouter>
|
|
315
316
|
<div>
|
|
@@ -336,8 +337,6 @@ describe("Clickable", () => {
|
|
|
336
337
|
buttonWrapper.simulate("click", {button: 0});
|
|
337
338
|
await wait(0);
|
|
338
339
|
buttonWrapper.update();
|
|
339
|
-
await wait(0);
|
|
340
|
-
buttonWrapper.update();
|
|
341
340
|
|
|
342
341
|
// Assert
|
|
343
342
|
expect(window.location.assign).toHaveBeenCalledWith("/foo");
|
|
@@ -345,7 +344,6 @@ describe("Clickable", () => {
|
|
|
345
344
|
|
|
346
345
|
test("safeWithNav with skipClientNav=true waits for promise rejection", async () => {
|
|
347
346
|
// Arrange
|
|
348
|
-
jest.spyOn(window.location, "assign");
|
|
349
347
|
const wrapper = mount(
|
|
350
348
|
<MemoryRouter>
|
|
351
349
|
<div>
|
|
@@ -376,9 +374,8 @@ describe("Clickable", () => {
|
|
|
376
374
|
expect(window.location.assign).toHaveBeenCalledWith("/foo");
|
|
377
375
|
});
|
|
378
376
|
|
|
379
|
-
test("safeWithNav with skipClientNav=false calls safeWithNav but doesn't wait to navigate",
|
|
377
|
+
test("safeWithNav with skipClientNav=false calls safeWithNav but doesn't wait to navigate", () => {
|
|
380
378
|
// Arrange
|
|
381
|
-
jest.spyOn(window.location, "assign");
|
|
382
379
|
const safeWithNavMock = jest.fn();
|
|
383
380
|
const wrapper = mount(
|
|
384
381
|
<MemoryRouter>
|
|
@@ -406,12 +403,16 @@ describe("Clickable", () => {
|
|
|
406
403
|
|
|
407
404
|
// Assert
|
|
408
405
|
expect(safeWithNavMock).toHaveBeenCalled();
|
|
409
|
-
expect(
|
|
406
|
+
expect(wrapper).toIncludeText(
|
|
407
|
+
"Hello, world!" /*client side nav to /foo*/,
|
|
408
|
+
);
|
|
409
|
+
expect(window.location.assign).not.toHaveBeenCalledWith(
|
|
410
|
+
"/foo" /*not a full page nav*/,
|
|
411
|
+
);
|
|
410
412
|
});
|
|
411
413
|
|
|
412
414
|
test("safeWithNav with beforeNav resolution and skipClientNav=false calls safeWithNav but doesn't wait to navigate", async () => {
|
|
413
415
|
// Arrange
|
|
414
|
-
jest.spyOn(window.location, "assign");
|
|
415
416
|
const safeWithNavMock = jest.fn();
|
|
416
417
|
const wrapper = mount(
|
|
417
418
|
<MemoryRouter>
|
|
@@ -442,7 +443,12 @@ describe("Clickable", () => {
|
|
|
442
443
|
|
|
443
444
|
// Assert
|
|
444
445
|
expect(safeWithNavMock).toHaveBeenCalled();
|
|
445
|
-
expect(
|
|
446
|
+
expect(wrapper).toIncludeText(
|
|
447
|
+
"Hello, world!" /*client side nav to /foo*/,
|
|
448
|
+
);
|
|
449
|
+
expect(window.location.assign).not.toHaveBeenCalledWith(
|
|
450
|
+
"/foo" /*not a full page nav*/,
|
|
451
|
+
);
|
|
446
452
|
});
|
|
447
453
|
|
|
448
454
|
describe("raw events", () => {
|
|
@@ -558,9 +558,8 @@ export default class ClickableBehavior extends React.Component<
|
|
|
558
558
|
}
|
|
559
559
|
|
|
560
560
|
const keyCode = e.which || e.keyCode;
|
|
561
|
-
const {triggerOnEnter, triggerOnSpace} =
|
|
562
|
-
role
|
|
563
|
-
);
|
|
561
|
+
const {triggerOnEnter, triggerOnSpace} =
|
|
562
|
+
getAppropriateTriggersForRole(role);
|
|
564
563
|
if (
|
|
565
564
|
(triggerOnEnter && keyCode === keyCodes.enter) ||
|
|
566
565
|
(triggerOnSpace && keyCode === keyCodes.space)
|
|
@@ -585,9 +584,8 @@ export default class ClickableBehavior extends React.Component<
|
|
|
585
584
|
}
|
|
586
585
|
|
|
587
586
|
const keyCode = e.which || e.keyCode;
|
|
588
|
-
const {triggerOnEnter, triggerOnSpace} =
|
|
589
|
-
role
|
|
590
|
-
);
|
|
587
|
+
const {triggerOnEnter, triggerOnSpace} =
|
|
588
|
+
getAppropriateTriggersForRole(role);
|
|
591
589
|
if (
|
|
592
590
|
(triggerOnEnter && keyCode === keyCodes.enter) ||
|
|
593
591
|
(triggerOnSpace && keyCode === keyCodes.space)
|
|
@@ -145,6 +145,13 @@ const styles = StyleSheet.create({
|
|
|
145
145
|
</MemoryRouter>
|
|
146
146
|
```
|
|
147
147
|
|
|
148
|
+
### Running callbacks on navigation
|
|
149
|
+
|
|
150
|
+
When using the `href` prop, the `onClick`, `beforeNav`, and `safeWithNav` props
|
|
151
|
+
can be used to run callbacks when navigating to the new URL. Which prop to use
|
|
152
|
+
depends on the use case. See the [Button](#section-button) documentation for
|
|
153
|
+
details.
|
|
154
|
+
|
|
148
155
|
### Navigating with the Keyboard
|
|
149
156
|
|
|
150
157
|
Clickable adds support to keyboard navigation. This way, your components are
|