@khanacademy/wonder-blocks-dropdown 2.8.2 → 2.9.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 +28 -0
- package/dist/es/index.js +18 -9
- package/dist/index.js +41 -30
- package/docs.md +4 -11
- package/package.json +9 -10
- package/src/components/__docs__/single-select.stories.js +54 -0
- package/src/components/__tests__/single-select.test.js +95 -0
- package/src/components/dropdown-core.js +7 -7
- package/src/components/multi-select.js +1 -1
- package/src/components/single-select.js +42 -4
- package/src/index.js +2 -1
- package/src/__tests__/__snapshots__/generated-snapshot.test.js.snap +0 -4548
- package/src/__tests__/generated-snapshot.test.js +0 -1612
- package/src/components/action-menu.md +0 -338
- package/src/components/multi-select.md +0 -718
- package/src/components/single-select.md +0 -520
|
@@ -62,12 +62,10 @@ type Labels = {|
|
|
|
62
62
|
*/
|
|
63
63
|
noResults: string,
|
|
64
64
|
/**
|
|
65
|
-
* The number
|
|
66
|
-
*
|
|
67
|
-
* NOTE: We are reusing the same label for both the total number of items
|
|
68
|
-
* and the number of selected items.
|
|
65
|
+
* The total number of available options in the dropdown.
|
|
66
|
+
* These can be all items or only the ones that match the filter.
|
|
69
67
|
*/
|
|
70
|
-
|
|
68
|
+
someResults: (numOptions: number) => string,
|
|
71
69
|
|};
|
|
72
70
|
|
|
73
71
|
// we need to define a DefaultProps type to allow the HOC expose the default
|
|
@@ -253,7 +251,7 @@ class DropdownCore extends React.Component<Props, State> {
|
|
|
253
251
|
clearSearch: defaultLabels.clearSearch,
|
|
254
252
|
filter: defaultLabels.filter,
|
|
255
253
|
noResults: defaultLabels.noResults,
|
|
256
|
-
|
|
254
|
+
someResults: defaultLabels.someSelected,
|
|
257
255
|
},
|
|
258
256
|
light: false,
|
|
259
257
|
selectionType: "single",
|
|
@@ -302,6 +300,8 @@ class DropdownCore extends React.Component<Props, State> {
|
|
|
302
300
|
sameItemsFocusable: false,
|
|
303
301
|
labels: {
|
|
304
302
|
noResults: defaultLabels.noResults,
|
|
303
|
+
// In case we are not overriding this from the caller.
|
|
304
|
+
someResults: defaultLabels.someSelected,
|
|
305
305
|
...props.labels,
|
|
306
306
|
},
|
|
307
307
|
};
|
|
@@ -945,7 +945,7 @@ class DropdownCore extends React.Component<Props, State> {
|
|
|
945
945
|
style={styles.srOnly}
|
|
946
946
|
data-test-id="dropdown-live-region"
|
|
947
947
|
>
|
|
948
|
-
{open && labels.
|
|
948
|
+
{open && labels.someResults(totalItems)}
|
|
949
949
|
</StyledSpan>
|
|
950
950
|
);
|
|
951
951
|
}
|
|
@@ -9,6 +9,7 @@ import DropdownCore from "./dropdown-core.js";
|
|
|
9
9
|
import DropdownOpener from "./dropdown-opener.js";
|
|
10
10
|
import SelectOpener from "./select-opener.js";
|
|
11
11
|
import {
|
|
12
|
+
defaultLabels,
|
|
12
13
|
selectDropdownStyle,
|
|
13
14
|
filterableDropdownStyle,
|
|
14
15
|
} from "../util/constants.js";
|
|
@@ -16,6 +17,28 @@ import {
|
|
|
16
17
|
import typeof OptionItem from "./option-item.js";
|
|
17
18
|
import type {DropdownItem, OpenerProps} from "../util/types.js";
|
|
18
19
|
|
|
20
|
+
export type SingleSelectLabels = {|
|
|
21
|
+
/**
|
|
22
|
+
* Label for describing the dismiss icon on the search filter.
|
|
23
|
+
*/
|
|
24
|
+
clearSearch: string,
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Label for the search placeholder.
|
|
28
|
+
*/
|
|
29
|
+
filter: string,
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Label for when the filter returns no results.
|
|
33
|
+
*/
|
|
34
|
+
noResults: string,
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Label for the opening component when there are some items selected.
|
|
38
|
+
*/
|
|
39
|
+
someResults: (numOptions: number) => string,
|
|
40
|
+
|};
|
|
41
|
+
|
|
19
42
|
type Props = {|
|
|
20
43
|
...AriaProps,
|
|
21
44
|
|
|
@@ -108,6 +131,11 @@ type Props = {|
|
|
|
108
131
|
* top. The items will be filtered by the input.
|
|
109
132
|
*/
|
|
110
133
|
isFilterable?: boolean,
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* The object containing the custom labels used inside this component.
|
|
137
|
+
*/
|
|
138
|
+
labels: SingleSelectLabels,
|
|
111
139
|
|};
|
|
112
140
|
|
|
113
141
|
type State = {|
|
|
@@ -130,9 +158,10 @@ type State = {|
|
|
|
130
158
|
|};
|
|
131
159
|
|
|
132
160
|
type DefaultProps = {|
|
|
133
|
-
alignment:
|
|
134
|
-
disabled:
|
|
135
|
-
light:
|
|
161
|
+
alignment: Props["alignment"],
|
|
162
|
+
disabled: Props["disabled"],
|
|
163
|
+
light: Props["light"],
|
|
164
|
+
labels: Props["labels"],
|
|
136
165
|
|};
|
|
137
166
|
|
|
138
167
|
/**
|
|
@@ -167,6 +196,12 @@ export default class SingleSelect extends React.Component<Props, State> {
|
|
|
167
196
|
alignment: "left",
|
|
168
197
|
disabled: false,
|
|
169
198
|
light: false,
|
|
199
|
+
labels: {
|
|
200
|
+
clearSearch: defaultLabels.clearSearch,
|
|
201
|
+
filter: defaultLabels.filter,
|
|
202
|
+
noResults: defaultLabels.noResults,
|
|
203
|
+
someResults: defaultLabels.someSelected,
|
|
204
|
+
},
|
|
170
205
|
};
|
|
171
206
|
|
|
172
207
|
constructor(props: Props) {
|
|
@@ -318,6 +353,7 @@ export default class SingleSelect extends React.Component<Props, State> {
|
|
|
318
353
|
alignment,
|
|
319
354
|
dropdownStyle,
|
|
320
355
|
isFilterable,
|
|
356
|
+
labels,
|
|
321
357
|
onChange,
|
|
322
358
|
onToggle,
|
|
323
359
|
opened,
|
|
@@ -365,11 +401,12 @@ export default class SingleSelect extends React.Component<Props, State> {
|
|
|
365
401
|
const {
|
|
366
402
|
alignment,
|
|
367
403
|
children,
|
|
404
|
+
className,
|
|
368
405
|
dropdownStyle,
|
|
369
406
|
isFilterable,
|
|
407
|
+
labels,
|
|
370
408
|
light,
|
|
371
409
|
style,
|
|
372
|
-
className,
|
|
373
410
|
} = this.props;
|
|
374
411
|
const {searchText} = this.state;
|
|
375
412
|
const allChildren = React.Children.toArray(children).filter(Boolean);
|
|
@@ -400,6 +437,7 @@ export default class SingleSelect extends React.Component<Props, State> {
|
|
|
400
437
|
isFilterable ? this.handleSearchTextChanged : null
|
|
401
438
|
}
|
|
402
439
|
searchText={isFilterable ? searchText : ""}
|
|
440
|
+
labels={labels}
|
|
403
441
|
/>
|
|
404
442
|
);
|
|
405
443
|
}
|
package/src/index.js
CHANGED
|
@@ -7,6 +7,7 @@ import SingleSelect from "./components/single-select.js";
|
|
|
7
7
|
import MultiSelect from "./components/multi-select.js";
|
|
8
8
|
|
|
9
9
|
import type {Labels} from "./components/multi-select.js";
|
|
10
|
+
import type {SingleSelectLabels} from "./components/single-select.js";
|
|
10
11
|
|
|
11
12
|
export {
|
|
12
13
|
ActionItem,
|
|
@@ -17,4 +18,4 @@ export {
|
|
|
17
18
|
MultiSelect,
|
|
18
19
|
};
|
|
19
20
|
|
|
20
|
-
export type {Labels};
|
|
21
|
+
export type {Labels, SingleSelectLabels};
|