@khanacademy/wonder-blocks-dropdown 5.2.0 → 5.3.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 CHANGED
@@ -1,5 +1,29 @@
1
1
  # @khanacademy/wonder-blocks-dropdown
2
2
 
3
+ ## 5.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 7030948a: Add `Listbox` component with Single and Multiple selection support
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [f72f7dd4]
12
+ - @khanacademy/wonder-blocks-timing@5.0.0
13
+ - @khanacademy/wonder-blocks-modal@5.1.2
14
+
15
+ ## 5.2.1
16
+
17
+ ### Patch Changes
18
+
19
+ - Updated dependencies [9bfeead9]
20
+ - @khanacademy/wonder-blocks-tokens@1.3.0
21
+ - @khanacademy/wonder-blocks-cell@3.3.5
22
+ - @khanacademy/wonder-blocks-clickable@4.2.1
23
+ - @khanacademy/wonder-blocks-layout@2.0.32
24
+ - @khanacademy/wonder-blocks-modal@5.1.1
25
+ - @khanacademy/wonder-blocks-search-field@2.2.10
26
+
3
27
  ## 5.2.0
4
28
 
5
29
  ### Minor Changes
@@ -0,0 +1,85 @@
1
+ /// <reference types="react" />
2
+ import { StyleType } from "@khanacademy/wonder-blocks-core";
3
+ import { MaybeValueOrValues, OptionItemComponent } from "../util/types";
4
+ type Props = {
5
+ /**
6
+ * The list of items to display in the listbox.
7
+ */
8
+ children: Array<OptionItemComponent>;
9
+ /**
10
+ * Whether the use can select more than one option item. Defaults to
11
+ * `single`.
12
+ *
13
+ * If `multiple` is selected, `aria-multiselectable={true}` is set
14
+ * internally in the listbox element.
15
+ */
16
+ selectionType: "single" | "multiple";
17
+ /**
18
+ * The value of the currently selected items.
19
+ */
20
+ value?: MaybeValueOrValues;
21
+ /**
22
+ * Callback for when the selection changes. The value passed as an argument
23
+ * is an updated array of the selected value(s).
24
+ */
25
+ onChange?: (value: MaybeValueOrValues) => void;
26
+ /**
27
+ * Provides a label for the listbox.
28
+ */
29
+ "aria-label"?: string;
30
+ /**
31
+ * A reference to the element that describes the listbox.
32
+ */
33
+ "aria-labelledby"?: string;
34
+ /**
35
+ * Whether the listbox is disabled.
36
+ *
37
+ * A disabled combobox does not support interaction, but it supports focus
38
+ * for a11y reasons. It internally maps to`aria-disabled`. Defaults to
39
+ * false.
40
+ */
41
+ disabled?: boolean;
42
+ /**
43
+ * The unique identifier of the listbox element.
44
+ */
45
+ id?: string;
46
+ /**
47
+ * TODO(WB-1678): Add async support to the listbox.
48
+ *
49
+ * Whether to display the loading state to let the user know that the
50
+ * results are being loaded asynchronously. Defaults to false.
51
+ */
52
+ loading?: boolean;
53
+ /**
54
+ * Optional custom styles applied to the listbox container.
55
+ */
56
+ style?: StyleType;
57
+ /**
58
+ * Includes the listbox in the page tab sequence.
59
+ */
60
+ tabIndex?: number;
61
+ /**
62
+ * Test ID used for e2e testing.
63
+ */
64
+ testId?: string;
65
+ };
66
+ /**
67
+ * A `Listbox` component presents a list of options and allows a user to select
68
+ * one or more of them. A listbox that allows a single option to be chosen is a
69
+ * single-select listbox; one that allows multiple options to be selected is a
70
+ * multi-select listbox.
71
+ *
72
+ * ### Usage
73
+ *
74
+ * ```tsx
75
+ * import {Listbox} from "@khanacademy/wonder-blocks-dropdown";
76
+ *
77
+ * <Listbox>
78
+ * <OptionItem label="Apple" value="apple" />
79
+ * <OptionItem disabled label="Strawberry" value="strawberry" />
80
+ * <OptionItem label="Pear" value="pear" />
81
+ * </Listbox>
82
+ * ```
83
+ */
84
+ export default function Listbox(props: Props): JSX.Element;
85
+ export {};
@@ -3,7 +3,7 @@ import type { AriaProps, StyleType } from "@khanacademy/wonder-blocks-core";
3
3
  import DropdownOpener from "./dropdown-opener";
4
4
  import SelectOpener from "./select-opener";
5
5
  import OptionItem from "./option-item";
6
- import type { DropdownItem, OpenerProps, OptionItemComponentArray } from "../util/types";
6
+ import type { DropdownItem, OpenerProps, OptionItemComponent, OptionItemComponentArray } from "../util/types";
7
7
  export type Labels = {
8
8
  /**
9
9
  * Label for describing the dismiss icon on the search filter.
@@ -192,7 +192,7 @@ export default class MultiSelect extends React.Component<Props, State> {
192
192
  getMenuText(children: OptionItemComponentArray): string;
193
193
  getShortcuts(numOptions: number): DropdownItem[];
194
194
  getMenuItems(children: OptionItemComponentArray): DropdownItem[];
195
- mapOptionItemToDropdownItem: (option: React.ReactElement<React.ComponentProps<typeof OptionItem>>) => DropdownItem;
195
+ mapOptionItemToDropdownItem: (option: OptionItemComponent) => DropdownItem;
196
196
  handleOpenerRef: (node?: any) => void;
197
197
  handleSearchTextChanged: (searchText: string) => void;
198
198
  handleClick: (e: React.SyntheticEvent) => void;
@@ -39,6 +39,12 @@ type OptionProps = AriaProps & {
39
39
  * @ignore
40
40
  */
41
41
  selected: boolean;
42
+ /**
43
+ * Whether this item is focused. Auto-populated by listbox in combination of
44
+ * aria-activedescendant.
45
+ * @ignore
46
+ */
47
+ focused: boolean;
42
48
  /**
43
49
  * Aria role to use, defaults to "option".
44
50
  */
@@ -59,6 +65,20 @@ type OptionProps = AriaProps & {
59
65
  * @ignore
60
66
  */
61
67
  style?: StyleType;
68
+ /**
69
+ * Injected by the parent component to determine how we are going to handle
70
+ * the component states (hovered, focused, selected, etc.)
71
+ * Defaults to "dropdown".
72
+ * @ignore
73
+ */
74
+ parentComponent?: "dropdown" | "listbox";
75
+ /**
76
+ * The unique identifier of the option item.
77
+ *
78
+ * This is used to identify the option item in the listbox so that it can be
79
+ * focused programmatically (e.g. when the user presses the arrow keys).
80
+ */
81
+ id?: string;
62
82
  /**
63
83
  * Inherited from WB Cell.
64
84
  */
@@ -86,6 +106,7 @@ type OptionProps = AriaProps & {
86
106
  };
87
107
  type DefaultProps = {
88
108
  disabled: OptionProps["disabled"];
109
+ focused: OptionProps["focused"];
89
110
  horizontalRule: OptionProps["horizontalRule"];
90
111
  onToggle: OptionProps["onToggle"];
91
112
  role: OptionProps["role"];
@@ -102,6 +123,7 @@ export default class OptionItem extends React.Component<OptionProps> {
102
123
  static __IS_OPTION_ITEM__: boolean;
103
124
  getCheckComponent(): typeof Check | typeof Checkbox;
104
125
  handleClick: () => void;
126
+ renderCell(): React.ReactNode;
105
127
  render(): React.ReactNode;
106
128
  }
107
129
  export {};