@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.
@@ -62,12 +62,10 @@ type Labels = {|
62
62
  */
63
63
  noResults: string,
64
64
  /**
65
- * The number total of items available.
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
- someSelected: (numOptions: number) => string,
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
- someSelected: defaultLabels.someSelected,
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.someSelected(totalItems)}
948
+ {open && labels.someResults(totalItems)}
949
949
  </StyledSpan>
950
950
  );
951
951
  }
@@ -575,7 +575,7 @@ export default class MultiSelect extends React.Component<Props, State> {
575
575
  clearSearch,
576
576
  filter,
577
577
  noResults,
578
- someSelected,
578
+ someResults: someSelected,
579
579
  }}
580
580
  />
581
581
  );
@@ -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: $PropertyType<Props, "alignment">,
134
- disabled: $PropertyType<Props, "disabled">,
135
- light: $PropertyType<Props, "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};