@khanacademy/wonder-blocks-dropdown 5.4.6 → 5.5.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 +17 -0
- package/dist/components/combobox-live-region.d.ts +52 -0
- package/dist/components/combobox-multiple-selection.d.ts +42 -0
- package/dist/components/combobox.d.ts +101 -0
- package/dist/es/index.js +599 -48
- package/dist/hooks/use-listbox.d.ts +16 -7
- package/dist/hooks/use-multiple-selection.d.ts +28 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +602 -46
- package/dist/util/constants.d.ts +2 -0
- package/dist/util/types.d.ts +56 -0
- package/package.json +4 -3
- package/src/components/__tests__/combobox-live-region.test.tsx +179 -0
- package/src/components/__tests__/combobox.test.tsx +749 -0
- package/src/components/combobox-live-region.tsx +212 -0
- package/src/components/combobox-multiple-selection.tsx +108 -0
- package/src/components/combobox.tsx +671 -0
- package/src/components/listbox.tsx +64 -20
- package/src/hooks/use-listbox.tsx +38 -3
- package/src/hooks/use-multiple-selection.tsx +106 -0
- package/src/index.ts +2 -0
- package/src/util/constants.ts +25 -0
- package/src/util/types.ts +60 -0
- package/tsconfig-build.json +1 -0
- package/tsconfig-build.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @khanacademy/wonder-blocks-dropdown
|
|
2
2
|
|
|
3
|
+
## 5.5.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 5fb863d0: Add multiple selection support to `Combobox`
|
|
8
|
+
- ea506e85: Add Combobox component with single selection support
|
|
9
|
+
- 2ad690b3: Add a11y features to announce combobox changes to screen readers
|
|
10
|
+
- b89e828c: Add autocomplete support to Combobox
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- 326954dd: Update borderColor to be more a11y friendly
|
|
15
|
+
- Updated dependencies [5fb863d0]
|
|
16
|
+
- @khanacademy/wonder-blocks-pill@2.5.0
|
|
17
|
+
- @khanacademy/wonder-blocks-search-field@2.2.25
|
|
18
|
+
- @khanacademy/wonder-blocks-modal@5.1.11
|
|
19
|
+
|
|
3
20
|
## 5.4.6
|
|
4
21
|
|
|
5
22
|
### Patch Changes
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { ComboboxLabels, MaybeValueOrValues, OptionItemComponent } from "../util/types";
|
|
3
|
+
type Props = {
|
|
4
|
+
/**
|
|
5
|
+
* The index of the focused item in the listbox.
|
|
6
|
+
*/
|
|
7
|
+
focusedIndex: number;
|
|
8
|
+
/**
|
|
9
|
+
* The index of the focused item in the multi-select combobox.
|
|
10
|
+
*/
|
|
11
|
+
focusedMultiSelectIndex: number;
|
|
12
|
+
/**
|
|
13
|
+
* The labels associated with the live region.
|
|
14
|
+
*/
|
|
15
|
+
labels?: Pick<ComboboxLabels, "closedState" | "liveRegionCurrentItem" | "liveRegionListboxTotal" | "liveRegionMultipleSelectionTotal" | "noItems" | "selected" | "unselected">;
|
|
16
|
+
/**
|
|
17
|
+
* Whether the listbox is open/expanded.
|
|
18
|
+
*/
|
|
19
|
+
opened?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* The list of items in the listbox.
|
|
22
|
+
*/
|
|
23
|
+
options: Array<OptionItemComponent>;
|
|
24
|
+
/**
|
|
25
|
+
* The value of the selected item(s).
|
|
26
|
+
*/
|
|
27
|
+
selected: MaybeValueOrValues;
|
|
28
|
+
/**
|
|
29
|
+
* The label(s) of the selected item(s).
|
|
30
|
+
*/
|
|
31
|
+
selectedLabels: Array<string>;
|
|
32
|
+
/**
|
|
33
|
+
* Whether the use can select more than one option item. Defaults to
|
|
34
|
+
* `single`.
|
|
35
|
+
*/
|
|
36
|
+
selectionType?: "single" | "multiple";
|
|
37
|
+
/**
|
|
38
|
+
* The testId used for the live region.
|
|
39
|
+
*/
|
|
40
|
+
testId?: string;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* A component that announces focus changes to Screen Readers.
|
|
44
|
+
*
|
|
45
|
+
* This is useful as there are lots of issues with `role="combobox"` + Safari
|
|
46
|
+
* when the browser is not capable of announcing correctly the status of the
|
|
47
|
+
* currently focused option item.
|
|
48
|
+
*
|
|
49
|
+
* @see https://bugs.webkit.org/show_bug.cgi?id=167671
|
|
50
|
+
*/
|
|
51
|
+
export declare function ComboboxLiveRegion({ focusedIndex, focusedMultiSelectIndex, labels, selectedLabels, opened, options, selected, selectionType, testId, }: Props): JSX.Element;
|
|
52
|
+
export {};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
type Props = {
|
|
3
|
+
/**
|
|
4
|
+
* Whether the combobox is disabled.
|
|
5
|
+
*/
|
|
6
|
+
disabled?: boolean;
|
|
7
|
+
/**
|
|
8
|
+
* The index of the focused item in the pills group.
|
|
9
|
+
*/
|
|
10
|
+
focusedMultiSelectIndex: number;
|
|
11
|
+
/**
|
|
12
|
+
* The unique identifier for the selected items.
|
|
13
|
+
*/
|
|
14
|
+
id: string;
|
|
15
|
+
/**
|
|
16
|
+
* The list of labels for the selected items.
|
|
17
|
+
*/
|
|
18
|
+
labels: Array<string>;
|
|
19
|
+
/**
|
|
20
|
+
* Function to remove a selected item.
|
|
21
|
+
*/
|
|
22
|
+
onRemove: (value: string) => void;
|
|
23
|
+
/**
|
|
24
|
+
* Accessible label for the remove button.
|
|
25
|
+
*/
|
|
26
|
+
removeSelectedLabel: (value: string) => string;
|
|
27
|
+
/**
|
|
28
|
+
* The list of selected items, where each item represents the value of the
|
|
29
|
+
* selected option.
|
|
30
|
+
*/
|
|
31
|
+
selected: Array<string>;
|
|
32
|
+
/**
|
|
33
|
+
* The testId prefix used for the pills.
|
|
34
|
+
*/
|
|
35
|
+
testId?: string;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Renders the selected items as pills that are horizontally stacked before
|
|
39
|
+
* the input element.
|
|
40
|
+
*/
|
|
41
|
+
export declare const MultipleSelection: React.NamedExoticComponent<Props>;
|
|
42
|
+
export {};
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { StyleType } from "@khanacademy/wonder-blocks-core";
|
|
3
|
+
import { ComboboxLabels, 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
|
+
* Whether the combobox is disabled.
|
|
28
|
+
*
|
|
29
|
+
* A disabled combobox does not support interaction, but it supports focus
|
|
30
|
+
* for a11y reasons. It internally maps to`aria-disabled`. Defaults to
|
|
31
|
+
* false.
|
|
32
|
+
*/
|
|
33
|
+
disabled?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* The unique identifier of the combobox element.
|
|
36
|
+
*/
|
|
37
|
+
id?: string;
|
|
38
|
+
/**
|
|
39
|
+
* The object containing the custom labels used inside this component.
|
|
40
|
+
*
|
|
41
|
+
* This is useful for internationalization. Defaults to English.
|
|
42
|
+
*/
|
|
43
|
+
labels?: ComboboxLabels;
|
|
44
|
+
/**
|
|
45
|
+
* Whether to display the light version of this component.
|
|
46
|
+
*
|
|
47
|
+
* For use when the component is used on a dark background. Defaults to
|
|
48
|
+
* false.
|
|
49
|
+
*/
|
|
50
|
+
light?: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* TODO(WB-1678): Add async support to the listbox.
|
|
53
|
+
*
|
|
54
|
+
* Whether to display the loading state to let the user know that the
|
|
55
|
+
* results are being loaded asynchronously. Defaults to false.
|
|
56
|
+
*/
|
|
57
|
+
loading?: boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Can be used to programmatically control the opening of the listbox.
|
|
60
|
+
*/
|
|
61
|
+
opened?: boolean;
|
|
62
|
+
/**
|
|
63
|
+
* In controlled mode, use this prop in case the parent needs to be notified
|
|
64
|
+
* when the listbox opens/closes.
|
|
65
|
+
*/
|
|
66
|
+
onToggle?: (opened: boolean) => void;
|
|
67
|
+
/**
|
|
68
|
+
* Text that provides context for the user when there are no items selected.
|
|
69
|
+
*/
|
|
70
|
+
placeholder?: string;
|
|
71
|
+
/**
|
|
72
|
+
* Custom styles to add to the combobox element (input).
|
|
73
|
+
*/
|
|
74
|
+
style?: StyleType;
|
|
75
|
+
/**
|
|
76
|
+
* Test ID used for e2e testing.
|
|
77
|
+
*/
|
|
78
|
+
testId?: string;
|
|
79
|
+
/**
|
|
80
|
+
* Indicates whether inputting text could trigger display of one or more
|
|
81
|
+
* predictions of the user’s intended value.
|
|
82
|
+
*
|
|
83
|
+
* It’s internally mapped to aria-autocomplete set in the input field
|
|
84
|
+
* (combobox).
|
|
85
|
+
*/
|
|
86
|
+
autoComplete?: "none" | "list" | undefined;
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* A `Combobox` is an input widget that has an associated `listbox`. This
|
|
90
|
+
* listbox enables users to choose one or more values for the input from a
|
|
91
|
+
* collection of option items.
|
|
92
|
+
*
|
|
93
|
+
* The `listbox` is hidden by default, so its default state is collapsed. The
|
|
94
|
+
* conditions that trigger expanding the `listbox` are:
|
|
95
|
+
*
|
|
96
|
+
* - It is displayed when the `ArrowDown`, `ArrowUp` keys are pressed, or the
|
|
97
|
+
* Open button (🔽) is pressed.
|
|
98
|
+
* - It is displayed when the combobox receives focus.
|
|
99
|
+
*/
|
|
100
|
+
export default function Combobox({ autoComplete, children, disabled, id, labels, onChange, onToggle, opened, placeholder, selectionType, testId, value, }: Props): JSX.Element;
|
|
101
|
+
export {};
|