@khanacademy/wonder-blocks-dropdown 2.5.2 → 2.6.0

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/dist/index.js CHANGED
@@ -506,6 +506,7 @@ class ActionItem extends react__WEBPACK_IMPORTED_MODULE_0__["Component"] {
506
506
  target,
507
507
  indent,
508
508
  label,
509
+ lang,
509
510
  onClick,
510
511
  role,
511
512
  style,
@@ -534,6 +535,7 @@ class ActionItem extends react__WEBPACK_IMPORTED_MODULE_0__["Component"] {
534
535
  ...childrenProps
535
536
  };
536
537
  const children = /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](react__WEBPACK_IMPORTED_MODULE_0__["Fragment"], null, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](_khanacademy_wonder_blocks_typography__WEBPACK_IMPORTED_MODULE_6__["LabelMedium"], {
538
+ lang: lang,
537
539
  style: [indent && styles.indent, styles.label]
538
540
  }, label));
539
541
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@khanacademy/wonder-blocks-dropdown",
3
- "version": "2.5.2",
3
+ "version": "2.6.0",
4
4
  "design": "v1",
5
5
  "description": "Dropdown variants for Wonder Blocks.",
6
6
  "main": "dist/index.js",
@@ -19,13 +19,13 @@
19
19
  "@khanacademy/wonder-blocks-button": "^2.10.2",
20
20
  "@khanacademy/wonder-blocks-clickable": "^2.2.1",
21
21
  "@khanacademy/wonder-blocks-color": "^1.1.20",
22
- "@khanacademy/wonder-blocks-core": "^4.0.0",
22
+ "@khanacademy/wonder-blocks-core": "^4.1.0",
23
23
  "@khanacademy/wonder-blocks-icon": "^1.2.24",
24
24
  "@khanacademy/wonder-blocks-icon-button": "^3.4.1",
25
25
  "@khanacademy/wonder-blocks-layout": "^1.4.6",
26
26
  "@khanacademy/wonder-blocks-modal": "^2.1.45",
27
27
  "@khanacademy/wonder-blocks-spacing": "^3.0.5",
28
- "@khanacademy/wonder-blocks-timing": "^2.0.3",
28
+ "@khanacademy/wonder-blocks-timing": "^2.1.0",
29
29
  "@khanacademy/wonder-blocks-typography": "^1.1.28"
30
30
  },
31
31
  "peerDependencies": {
@@ -40,6 +40,5 @@
40
40
  },
41
41
  "devDependencies": {
42
42
  "wb-dev-build-settings": "^0.2.0"
43
- },
44
- "gitHead": "9ebea88533e702011165072f090a377e02fa3f0f"
43
+ }
45
44
  }
@@ -1,32 +1,54 @@
1
+ // @flow
1
2
  import * as React from "react";
2
- import renderer from "react-test-renderer";
3
3
  import {MemoryRouter, Link} from "react-router-dom";
4
4
  import {mount} from "enzyme";
5
+ import {render, screen} from "@testing-library/react";
5
6
 
6
7
  import ActionItem from "../action-item.js";
7
8
 
8
9
  describe("ActionItem", () => {
9
10
  it("should render with disabled styles", () => {
10
- const actionItem = renderer.create(
11
- <ActionItem href="/foo" disabled={true} />,
12
- );
11
+ // Arrange
12
+
13
+ // Act
14
+ render(<ActionItem href="/foo" label="Example" disabled={true} />);
13
15
 
14
- expect(actionItem).toMatchSnapshot();
16
+ // Assert
17
+ expect(screen.getByRole("menuitem")).toBeDisabled();
15
18
  });
16
19
 
17
20
  it("should render an anchor if there's no router", () => {
18
- const wrapper = mount(<ActionItem href="/foo" />);
21
+ // Arrange
19
22
 
20
- expect(wrapper.find("a")).toHaveLength(1);
23
+ // Act
24
+ render(<ActionItem href="/foo" label="Example" />);
25
+
26
+ // Assert
27
+ // eslint-disable-next-line testing-library/no-node-access
28
+ expect(document.querySelectorAll("a")).toHaveLength(1);
21
29
  });
22
30
 
23
31
  it("should render a Link if there's a router", () => {
32
+ // Arrange
33
+
34
+ // Act
24
35
  const wrapper = mount(
25
36
  <MemoryRouter>
26
- <ActionItem href="/foo" />
37
+ <ActionItem href="/foo" label="Example" />
27
38
  </MemoryRouter>,
28
39
  );
29
40
 
41
+ // Assert
30
42
  expect(wrapper.find(Link)).toHaveLength(1);
31
43
  });
44
+
45
+ it("should set the lang attribute if it's passed down", () => {
46
+ // Arrange
47
+
48
+ // Act
49
+ render(<ActionItem label="Español" lang="es" />);
50
+
51
+ // Assert
52
+ expect(screen.getByText("Español")).toHaveAttribute("lang", "es");
53
+ });
32
54
  });
@@ -1,6 +1,7 @@
1
1
  //@flow
2
2
  import * as React from "react";
3
3
  import {mount} from "enzyme";
4
+ import "jest-enzyme";
4
5
 
5
6
  import ActionItem from "../action-item.js";
6
7
  import OptionItem from "../option-item.js";
@@ -2,6 +2,7 @@
2
2
  import * as React from "react";
3
3
  import {VariableSizeList as List} from "react-window";
4
4
  import {mount} from "enzyme";
5
+ import "jest-enzyme";
5
6
 
6
7
  import OptionItem from "../option-item.js";
7
8
  import SeparatorItem from "../separator-item.js";
@@ -2,6 +2,7 @@
2
2
  import * as React from "react";
3
3
  import * as ReactDOM from "react-dom";
4
4
  import {mount} from "enzyme";
5
+ import "jest-enzyme";
5
6
 
6
7
  import OptionItem from "../option-item.js";
7
8
  import SearchTextInput from "../search-text-input.js";
@@ -2,6 +2,7 @@
2
2
  //@flow
3
3
  import * as React from "react";
4
4
  import {mount} from "enzyme";
5
+ import "jest-enzyme";
5
6
 
6
7
  import {ClickableBehavior} from "@khanacademy/wonder-blocks-clickable";
7
8
  import IconButton from "@khanacademy/wonder-blocks-icon-button";
@@ -1,6 +1,7 @@
1
1
  // @flow
2
2
  import * as React from "react";
3
3
  import {shallow} from "enzyme";
4
+ import "jest-enzyme";
4
5
 
5
6
  import SearchTextInput from "../search-text-input.js";
6
7
 
@@ -38,6 +38,12 @@ type ActionProps = {|
38
38
  */
39
39
  href?: string,
40
40
 
41
+ /**
42
+ * Optional attribute to indicate to the Screen Reader which language the
43
+ * item text is in.
44
+ */
45
+ lang?: string,
46
+
41
47
  /**
42
48
  * A target destination window for a link to open in.
43
49
  */
@@ -131,6 +137,7 @@ export default class ActionItem extends React.Component<ActionProps> {
131
137
  target,
132
138
  indent,
133
139
  label,
140
+ lang,
134
141
  onClick,
135
142
  role,
136
143
  style,
@@ -176,6 +183,7 @@ export default class ActionItem extends React.Component<ActionProps> {
176
183
  const children = (
177
184
  <React.Fragment>
178
185
  <LabelMedium
186
+ lang={lang}
179
187
  style={[indent && styles.indent, styles.label]}
180
188
  >
181
189
  {label}
@@ -0,0 +1,48 @@
1
+ // @flow
2
+ import * as React from "react";
3
+
4
+ import type {StoryComponentType} from "@storybook/react";
5
+ import ActionMenu from "./action-menu.js";
6
+ import ActionItem from "./action-item.js";
7
+
8
+ export default {
9
+ title: "Dropdown / ActionMenu",
10
+ component: ActionMenu,
11
+ };
12
+
13
+ export const ActionMenuWithLang: StoryComponentType = () => (
14
+ <ActionMenu menuText="Locales">
15
+ {locales.map((locale) => (
16
+ <ActionItem
17
+ key={locale.locale}
18
+ label={locale.localName}
19
+ lang={locale.locale}
20
+ testId={"language_picker_" + locale.locale}
21
+ />
22
+ ))}
23
+ </ActionMenu>
24
+ );
25
+
26
+ ActionMenuWithLang.storyName = "Using the ActionMenu with the lang attribute";
27
+
28
+ ActionMenuWithLang.parameters = {
29
+ docs: {
30
+ storyDescription:
31
+ "You can use the `lang` attribute to specify the language of the action item(s). This is useful if you want to avoid issues with Screen Readers trying to read the proper language for the rendered text.",
32
+ },
33
+ chromatic: {
34
+ disableSnapshot: true,
35
+ },
36
+ };
37
+
38
+ const locales = [
39
+ {id: "az", locale: "az", localName: "Azərbaycanca"},
40
+ {id: "id", locale: "id", localName: "Bahasa Indonesia"},
41
+ {id: "cs", locale: "cs", localName: "čeština"},
42
+ {id: "da", locale: "da", localName: "dansk"},
43
+ {id: "de", locale: "de", localName: "Deutsch"},
44
+ {id: "en", locale: "en", localName: "English"},
45
+ {id: "es", locale: "es", localName: "español"},
46
+ {id: "fr", locale: "fr", localName: "français"},
47
+ {id: "it", locale: "it", localName: "italiano"},
48
+ ];
@@ -79,18 +79,18 @@ class MultiSelectWithCustomStyles extends React.Component<Props, State> {
79
79
  }
80
80
  }
81
81
 
82
- export const customStyles: StoryComponentType = () => (
82
+ export const CustomStyles: StoryComponentType = () => (
83
83
  <MultiSelectWithCustomStyles />
84
84
  );
85
85
 
86
- customStyles.parameters = {
86
+ CustomStyles.parameters = {
87
87
  chromatic: {
88
88
  // we don't need screenshots because this story only tests behavior.
89
89
  disableSnapshot: true,
90
90
  },
91
91
  };
92
92
 
93
- export const customStylesOpened: StoryComponentType = () => (
93
+ export const CustomStylesOpened: StoryComponentType = () => (
94
94
  <MultiSelectWithCustomStyles opened={true} />
95
95
  );
96
96
 
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2018 Khan Academy
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
@@ -1,63 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`ActionItem should render with disabled styles 1`] = `
4
- <button
5
- className=""
6
- disabled={true}
7
- onBlur={[Function]}
8
- onClick={[Function]}
9
- onDragStart={[Function]}
10
- onFocus={[Function]}
11
- onKeyDown={[Function]}
12
- onKeyUp={[Function]}
13
- onMouseDown={[Function]}
14
- onMouseEnter={[Function]}
15
- onMouseLeave={[Function]}
16
- onMouseUp={[Function]}
17
- onTouchCancel={[Function]}
18
- onTouchEnd={[Function]}
19
- onTouchStart={[Function]}
20
- role="menuitem"
21
- style={
22
- Object {
23
- "::MozFocusInner": Object {
24
- "border": 0,
25
- },
26
- "alignItems": "center",
27
- "background": "#ffffff",
28
- "border": "none",
29
- "color": "rgba(33,36,44,0.32)",
30
- "cursor": "default",
31
- "display": "flex",
32
- "flexDirection": "row",
33
- "height": 40,
34
- "margin": 0,
35
- "minHeight": 40,
36
- "outline": "none",
37
- "paddingLeft": 16,
38
- "paddingRight": 16,
39
- "textDecoration": "none",
40
- "touchAction": "manipulation",
41
- }
42
- }
43
- tabIndex={-1}
44
- type="button"
45
- >
46
- <span
47
- className=""
48
- style={
49
- Object {
50
- "MozOsxFontSmoothing": "grayscale",
51
- "WebkitFontSmoothing": "antialiased",
52
- "display": "block",
53
- "fontFamily": "Lato, \\"Noto Sans\\", sans-serif",
54
- "fontSize": 16,
55
- "fontWeight": 400,
56
- "lineHeight": "20px",
57
- "userSelect": "none",
58
- "whiteSpace": "nowrap",
59
- }
60
- }
61
- />
62
- </button>
63
- `;