@khanacademy/wonder-blocks-dropdown 8.0.2 → 9.1.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/CHANGELOG.md +932 -882
- package/LICENSE +21 -0
- package/dist/components/dropdown-core.d.ts +2 -2
- package/dist/components/dropdown-opener.d.ts +5 -1
- package/dist/components/multi-select.d.ts +13 -10
- package/dist/components/select-opener.d.ts +5 -1
- package/dist/components/single-select.d.ts +15 -10
- package/dist/es/index.js +74 -61
- package/dist/index.d.ts +3 -3
- package/dist/index.js +122 -123
- package/dist/util/constants.d.ts +0 -11
- package/package.json +18 -20
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
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,7 +1,7 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import type { StyleType } from "@khanacademy/wonder-blocks-core";
|
|
3
3
|
import type { DropdownItem } from "../util/types";
|
|
4
|
-
type
|
|
4
|
+
type LabelsValues = {
|
|
5
5
|
/**
|
|
6
6
|
* Label for describing the dismiss icon on the search filter.
|
|
7
7
|
*/
|
|
@@ -116,7 +116,7 @@ type ExportProps = Readonly<{
|
|
|
116
116
|
/**
|
|
117
117
|
* The object containing the custom labels used inside this component.
|
|
118
118
|
*/
|
|
119
|
-
labels?:
|
|
119
|
+
labels?: LabelsValues;
|
|
120
120
|
/**
|
|
121
121
|
* Used to determine if we can automatically select an item using the keyboard.
|
|
122
122
|
*/
|
|
@@ -28,7 +28,7 @@ type Props = Partial<Omit<AriaProps, "aria-disabled">> & {
|
|
|
28
28
|
*/
|
|
29
29
|
testId?: string;
|
|
30
30
|
/**
|
|
31
|
-
*
|
|
31
|
+
* Content for the opener that can be passed to the child as an argument.
|
|
32
32
|
*/
|
|
33
33
|
text: OptionLabel;
|
|
34
34
|
/**
|
|
@@ -43,6 +43,10 @@ type Props = Partial<Omit<AriaProps, "aria-disabled">> & {
|
|
|
43
43
|
* If the dropdown has an error.
|
|
44
44
|
*/
|
|
45
45
|
error?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* The role of the opener.
|
|
48
|
+
*/
|
|
49
|
+
role: "combobox" | "button";
|
|
46
50
|
};
|
|
47
51
|
type DefaultProps = {
|
|
48
52
|
disabled: Props["disabled"];
|
|
@@ -2,7 +2,7 @@ import * as React from "react";
|
|
|
2
2
|
import { type AriaProps, type StyleType } from "@khanacademy/wonder-blocks-core";
|
|
3
3
|
import OptionItem from "./option-item";
|
|
4
4
|
import type { OpenerProps } from "../util/types";
|
|
5
|
-
export type
|
|
5
|
+
export type LabelsValues = {
|
|
6
6
|
/**
|
|
7
7
|
* Label for describing the dismiss icon on the search filter.
|
|
8
8
|
*/
|
|
@@ -12,7 +12,7 @@ export type Labels = {
|
|
|
12
12
|
*/
|
|
13
13
|
filter: string;
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
15
|
+
* Value for when the filter returns no results.
|
|
16
16
|
*/
|
|
17
17
|
noResults: string;
|
|
18
18
|
/**
|
|
@@ -24,15 +24,15 @@ export type Labels = {
|
|
|
24
24
|
*/
|
|
25
25
|
selectNoneLabel: string;
|
|
26
26
|
/**
|
|
27
|
-
*
|
|
27
|
+
* Value for the opening component when there are no items selected.
|
|
28
28
|
*/
|
|
29
29
|
noneSelected: string;
|
|
30
30
|
/**
|
|
31
|
-
*
|
|
31
|
+
* Value for the opening component when there are some items selected.
|
|
32
32
|
*/
|
|
33
33
|
someSelected: (numOptions: number) => string;
|
|
34
34
|
/**
|
|
35
|
-
*
|
|
35
|
+
* Value for the opening component when all the items have been selected.
|
|
36
36
|
*/
|
|
37
37
|
allSelected: string;
|
|
38
38
|
};
|
|
@@ -60,8 +60,8 @@ type DefaultProps = Readonly<{
|
|
|
60
60
|
*/
|
|
61
61
|
shortcuts?: boolean;
|
|
62
62
|
/**
|
|
63
|
-
* When false, the SelectOpener can show a Node as a
|
|
64
|
-
* SelectOpener will use a string as a
|
|
63
|
+
* When false, the SelectOpener can show a Node as a value. When true, the
|
|
64
|
+
* SelectOpener will use a string as a value. If using custom OptionItems, a
|
|
65
65
|
* plain text label can be provided with the `labelAsText` prop.
|
|
66
66
|
* Defaults to true.
|
|
67
67
|
*/
|
|
@@ -94,9 +94,9 @@ type Props = AriaProps & DefaultProps & Readonly<{
|
|
|
94
94
|
*/
|
|
95
95
|
isFilterable?: boolean;
|
|
96
96
|
/**
|
|
97
|
-
* The object containing the custom labels used inside this component.
|
|
97
|
+
* The object containing the custom labels and placeholder values used inside this component.
|
|
98
98
|
*/
|
|
99
|
-
labels?:
|
|
99
|
+
labels?: LabelsValues;
|
|
100
100
|
/**
|
|
101
101
|
* Callback for when the selection changes. Parameter is an updated array of
|
|
102
102
|
* the values that are now selected.
|
|
@@ -177,6 +177,9 @@ type Props = AriaProps & DefaultProps & Readonly<{
|
|
|
177
177
|
* multiple options to be selected. Clients are responsible for keeping track
|
|
178
178
|
* of the selected items.
|
|
179
179
|
*
|
|
180
|
+
* Clients are also responsible for labeling the select using `LabeledField`, or
|
|
181
|
+
* an `aria-label` attribute or `aria-labelledby` on the select.
|
|
182
|
+
*
|
|
180
183
|
* The multi select stays open until closed by the user. The onChange callback
|
|
181
184
|
* happens every time there is a change in the selection of the items.
|
|
182
185
|
*
|
|
@@ -185,7 +188,7 @@ type Props = AriaProps & DefaultProps & Readonly<{
|
|
|
185
188
|
* ```jsx
|
|
186
189
|
* import {OptionItem, MultiSelect} from "@khanacademy/wonder-blocks-dropdown";
|
|
187
190
|
*
|
|
188
|
-
* <MultiSelect onChange={setSelectedValues} selectedValues={selectedValues}>
|
|
191
|
+
* <MultiSelect aria-label="Fruits" onChange={setSelectedValues} selectedValues={selectedValues}>
|
|
189
192
|
* <OptionItem value="pear">Pear</OptionItem>
|
|
190
193
|
* <OptionItem value="mango">Mango</OptionItem>
|
|
191
194
|
* </MultiSelect>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import type
|
|
2
|
+
import { type AriaProps } from "@khanacademy/wonder-blocks-core";
|
|
3
3
|
import { OptionLabel } from "../util/types";
|
|
4
4
|
type SelectOpenerProps = AriaProps & {
|
|
5
5
|
/**
|
|
@@ -25,6 +25,10 @@ type SelectOpenerProps = AriaProps & {
|
|
|
25
25
|
* of this component. A placeholder has more faded text colors and styles.
|
|
26
26
|
*/
|
|
27
27
|
isPlaceholder: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* A label to expose on the opener, in the absence of an associated label element or `aria-labelledby`.
|
|
30
|
+
*/
|
|
31
|
+
ariaLabel?: string;
|
|
28
32
|
/**
|
|
29
33
|
* Callback for when the SelectOpener is pressed.
|
|
30
34
|
*/
|
|
@@ -2,9 +2,9 @@ import * as React from "react";
|
|
|
2
2
|
import { type AriaProps, type StyleType } from "@khanacademy/wonder-blocks-core";
|
|
3
3
|
import OptionItem from "./option-item";
|
|
4
4
|
import type { OpenerProps } from "../util/types";
|
|
5
|
-
export type
|
|
5
|
+
export type SingleSelectLabelsValues = {
|
|
6
6
|
/**
|
|
7
|
-
* Label for
|
|
7
|
+
* Label to create an accessible name for the dismiss icon on the search filter.
|
|
8
8
|
*/
|
|
9
9
|
clearSearch: string;
|
|
10
10
|
/**
|
|
@@ -12,11 +12,11 @@ export type SingleSelectLabels = {
|
|
|
12
12
|
*/
|
|
13
13
|
filter: string;
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
15
|
+
* Value for when the filter returns no results.
|
|
16
16
|
*/
|
|
17
17
|
noResults: string;
|
|
18
18
|
/**
|
|
19
|
-
*
|
|
19
|
+
* Value for the opening component when there are some items selected.
|
|
20
20
|
*/
|
|
21
21
|
someResults: (numOptions: number) => string;
|
|
22
22
|
};
|
|
@@ -54,12 +54,12 @@ type DefaultProps = Readonly<{
|
|
|
54
54
|
*/
|
|
55
55
|
error?: boolean;
|
|
56
56
|
/**
|
|
57
|
-
* The object containing the custom labels used inside this component.
|
|
57
|
+
* The object containing the custom labels and placeholder values used inside this component.
|
|
58
58
|
*/
|
|
59
|
-
labels?:
|
|
59
|
+
labels?: SingleSelectLabelsValues;
|
|
60
60
|
/**
|
|
61
|
-
* When false, the SelectOpener can show a Node as a
|
|
62
|
-
* SelectOpener will use a string as a
|
|
61
|
+
* When false, the SelectOpener can show a Node as a value. When true, the
|
|
62
|
+
* SelectOpener will use a string as a value. If using custom OptionItems, a
|
|
63
63
|
* plain text label can be provided with the `labelAsText` prop.
|
|
64
64
|
* Defaults to true.
|
|
65
65
|
*/
|
|
@@ -91,7 +91,8 @@ type Props = AriaProps & DefaultProps & Readonly<{
|
|
|
91
91
|
*/
|
|
92
92
|
id?: string;
|
|
93
93
|
/**
|
|
94
|
-
* Placeholder for the opening component when there are no items selected.
|
|
94
|
+
* Placeholder value for the opening component when there are no items selected.
|
|
95
|
+
* Note: a label is still necessary to describe the purpose of the select.
|
|
95
96
|
*/
|
|
96
97
|
placeholder: string;
|
|
97
98
|
/**
|
|
@@ -172,6 +173,9 @@ type Props = AriaProps & DefaultProps & Readonly<{
|
|
|
172
173
|
* The single select allows the selection of one item. Clients are responsible
|
|
173
174
|
* for keeping track of the selected item in the select.
|
|
174
175
|
*
|
|
176
|
+
* Clients are also responsible for labeling the select using `LabeledField`, an
|
|
177
|
+
* `aria-label` attribute, or `aria-labelledby`.
|
|
178
|
+
*
|
|
175
179
|
* The single select dropdown closes after the selection of an item. If the same
|
|
176
180
|
* item is selected, there is no callback.
|
|
177
181
|
*
|
|
@@ -188,7 +192,7 @@ type Props = AriaProps & DefaultProps & Readonly<{
|
|
|
188
192
|
*
|
|
189
193
|
* const [selectedValue, setSelectedValue] = React.useState("");
|
|
190
194
|
*
|
|
191
|
-
* <SingleSelect placeholder="Choose a fruit" onChange={setSelectedValue} selectedValue={selectedValue}>
|
|
195
|
+
* <SingleSelect aria-label="Your Favorite Fruits" placeholder="Choose a fruit" onChange={setSelectedValue} selectedValue={selectedValue}>
|
|
192
196
|
* <OptionItem label="Pear" value="pear" />
|
|
193
197
|
* <OptionItem label="Mango" value="mango" />
|
|
194
198
|
* </SingleSelect>
|
|
@@ -203,6 +207,7 @@ type Props = AriaProps & DefaultProps & Readonly<{
|
|
|
203
207
|
* const fruitArray = ["Apple", "Banana", "Orange", "Mango", "Pear"];
|
|
204
208
|
*
|
|
205
209
|
* <SingleSelect
|
|
210
|
+
* aria-label="Your Favorite Fruits"
|
|
206
211
|
* placeholder="Choose a fruit"
|
|
207
212
|
* onChange={setSelectedValue}
|
|
208
213
|
* selectedValue={selectedValue}
|