reshaped 3.8.0-canary.6 → 3.8.0-canary.8
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 +27 -0
- package/dist/bundle.css +1 -1
- package/dist/bundle.js +10 -10
- package/dist/components/Actionable/Actionable.module.css +1 -1
- package/dist/components/Alert/tests/Alert.stories.d.ts +6 -5
- package/dist/components/Alert/tests/Alert.stories.js +15 -2
- package/dist/components/Badge/Badge.module.css +1 -1
- package/dist/components/Badge/tests/Badge.stories.d.ts +5 -0
- package/dist/components/Badge/tests/Badge.stories.js +34 -0
- package/dist/components/Breadcrumbs/tests/Breadcrumbs.stories.d.ts +8 -4
- package/dist/components/Breadcrumbs/tests/Breadcrumbs.stories.js +57 -1
- package/dist/components/Button/tests/Button.stories.d.ts +54 -12
- package/dist/components/Button/tests/Button.stories.js +725 -588
- package/dist/components/Card/Card.module.css +1 -1
- package/dist/components/Card/tests/Card.stories.d.ts +28 -6
- package/dist/components/Card/tests/Card.stories.js +110 -65
- package/dist/components/Carousel/Carousel.module.css +1 -1
- package/dist/components/Checkbox/Checkbox.module.css +1 -1
- package/dist/components/Checkbox/tests/Checkbox.stories.d.ts +20 -4
- package/dist/components/Checkbox/tests/Checkbox.stories.js +150 -79
- package/dist/components/CheckboxGroup/tests/CheckboxGroup.stories.d.ts +9 -2
- package/dist/components/CheckboxGroup/tests/CheckboxGroup.stories.js +67 -35
- package/dist/components/Container/tests/Container.stories.d.ts +2 -0
- package/dist/components/Container/tests/Container.stories.js +14 -0
- package/dist/components/ContextMenu/tests/ContextMenu.stories.d.ts +10 -1
- package/dist/components/ContextMenu/tests/ContextMenu.stories.js +57 -13
- package/dist/components/Dismissible/tests/Dismissible.stories.d.ts +5 -0
- package/dist/components/Dismissible/tests/Dismissible.stories.js +30 -1
- package/dist/components/Divider/tests/Divider.stories.d.ts +8 -3
- package/dist/components/Divider/tests/Divider.stories.js +71 -41
- package/dist/components/DropdownMenu/DropdownMenu.js +4 -4
- package/dist/components/DropdownMenu/DropdownMenu.types.d.ts +2 -2
- package/dist/components/DropdownMenu/tests/DropdownMenu.stories.d.ts +35 -6
- package/dist/components/DropdownMenu/tests/DropdownMenu.stories.js +222 -115
- package/dist/components/DropdownMenu/tests/DropdownMenu.test.stories.d.ts +0 -15
- package/dist/components/DropdownMenu/tests/DropdownMenu.test.stories.js +0 -106
- package/dist/components/FileUpload/FileUpload.module.css +1 -1
- package/dist/components/Flyout/Flyout.module.css +1 -1
- package/dist/components/Flyout/utilities/flyout.js +0 -1
- package/dist/components/Flyout/utilities/getPositionFallbacks.js +3 -3
- package/dist/components/Flyout/utilities/isFullyVisible.d.ts +0 -2
- package/dist/components/Flyout/utilities/isFullyVisible.js +5 -7
- package/dist/components/FormControl/tests/FormControl.stories.d.ts +2 -0
- package/dist/components/FormControl/tests/FormControl.stories.js +35 -0
- package/dist/components/Hidden/Hidden.js +2 -1
- package/dist/components/Hidden/tests/Hidden.stories.d.ts +2 -0
- package/dist/components/Hidden/tests/Hidden.stories.js +9 -0
- package/dist/components/HiddenVisually/tests/HiddenVisually.stories.d.ts +2 -0
- package/dist/components/HiddenVisually/tests/HiddenVisually.stories.js +9 -0
- package/dist/components/Hotkey/tests/Hotkey.stories.d.ts +2 -0
- package/dist/components/Hotkey/tests/Hotkey.stories.js +15 -0
- package/dist/components/Icon/tests/Icon.stories.d.ts +3 -0
- package/dist/components/Icon/tests/Icon.stories.js +23 -0
- package/dist/components/Link/tests/Link.stories.d.ts +28 -5
- package/dist/components/Link/tests/Link.stories.js +141 -58
- package/dist/components/Link/tests/Link.test.stories.d.ts +0 -13
- package/dist/components/Link/tests/Link.test.stories.js +0 -85
- package/dist/components/Loader/tests/Loader.stories.d.ts +11 -2
- package/dist/components/Loader/tests/Loader.stories.js +52 -25
- package/dist/components/Loader/tests/Loader.test.stories.d.ts +0 -3
- package/dist/components/Loader/tests/Loader.test.stories.js +0 -21
- package/dist/components/MenuItem/MenuItem.module.css +1 -1
- package/dist/components/MenuItem/tests/MenuItem.stories.d.ts +37 -7
- package/dist/components/MenuItem/tests/MenuItem.stories.js +218 -112
- package/dist/components/Modal/Modal.js +1 -1
- package/dist/components/Modal/Modal.module.css +1 -1
- package/dist/components/Modal/tests/Modal.stories.d.ts +53 -10
- package/dist/components/Modal/tests/Modal.stories.js +366 -214
- package/dist/components/Overlay/tests/Overlay.stories.d.ts +15 -1
- package/dist/components/Overlay/tests/Overlay.stories.js +135 -1
- package/dist/components/Pagination/tests/Pagination.stories.d.ts +14 -1
- package/dist/components/Pagination/tests/Pagination.stories.js +93 -15
- package/dist/components/PinField/tests/PinField.stories.d.ts +1 -1
- package/dist/components/PinField/tests/PinField.stories.js +1 -1
- package/dist/components/Popover/Popover.js +2 -2
- package/dist/components/Popover/Popover.module.css +1 -1
- package/dist/components/Popover/Popover.types.d.ts +2 -0
- package/dist/components/Progress/tests/Progress.stories.d.ts +19 -4
- package/dist/components/Progress/tests/Progress.stories.js +85 -49
- package/dist/components/Radio/Radio.module.css +1 -1
- package/dist/components/Radio/tests/Radio.stories.d.ts +25 -4
- package/dist/components/Radio/tests/Radio.stories.js +147 -65
- package/dist/components/RadioGroup/tests/RadioGroup.stories.d.ts +9 -2
- package/dist/components/RadioGroup/tests/RadioGroup.stories.js +64 -38
- package/dist/components/Reshaped/Reshaped.css +1 -1
- package/dist/components/Resizable/Resizable.js +4 -3
- package/dist/components/Scrim/tests/Scrim.stories.d.ts +10 -2
- package/dist/components/Scrim/tests/Scrim.stories.js +51 -31
- package/dist/components/ScrollArea/ScrollArea.module.css +1 -1
- package/dist/components/Select/Select.d.ts +8 -1
- package/dist/components/Select/Select.js +22 -48
- package/dist/components/Select/Select.module.css +1 -1
- package/dist/components/Select/Select.types.d.ts +83 -38
- package/dist/components/Select/SelectCustom.d.ts +3 -0
- package/dist/components/Select/SelectCustom.js +12 -0
- package/dist/components/Select/SelectCustomControlled.d.ts +4 -0
- package/dist/components/Select/SelectCustomControlled.js +102 -0
- package/dist/components/Select/SelectCustomUncontrolled.d.ts +4 -0
- package/dist/components/Select/SelectCustomUncontrolled.js +18 -0
- package/dist/components/Select/SelectEndContent.d.ts +3 -0
- package/dist/components/Select/SelectEndContent.js +12 -0
- package/dist/components/Select/SelectNative.d.ts +4 -0
- package/dist/components/Select/SelectNative.js +29 -0
- package/dist/components/Select/SelectOption.d.ts +4 -0
- package/dist/components/Select/SelectOption.js +15 -0
- package/dist/components/Select/SelectOptionGroup.d.ts +4 -0
- package/dist/components/Select/SelectOptionGroup.js +11 -0
- package/dist/components/Select/SelectRoot.d.ts +4 -0
- package/dist/components/Select/SelectRoot.js +21 -0
- package/dist/components/Select/SelectStartContent.d.ts +3 -0
- package/dist/components/Select/SelectStartContent.js +20 -0
- package/dist/components/Select/SelectTrigger.d.ts +4 -0
- package/dist/components/Select/SelectTrigger.js +16 -0
- package/dist/components/Select/tests/Select.stories.d.ts +38 -10
- package/dist/components/Select/tests/Select.stories.js +504 -175
- package/dist/components/Skeleton/tests/Skeleton.stories.d.ts +10 -2
- package/dist/components/Skeleton/tests/Skeleton.stories.js +46 -28
- package/dist/components/Slider/Slider.module.css +1 -1
- package/dist/components/Stepper/Stepper.js +2 -2
- package/dist/components/Stepper/Stepper.types.d.ts +2 -0
- package/dist/components/Stepper/tests/Stepper.stories.d.ts +18 -3
- package/dist/components/Stepper/tests/Stepper.stories.js +99 -47
- package/dist/components/Switch/Switch.module.css +1 -1
- package/dist/components/Switch/tests/Switch.stories.d.ts +10 -2
- package/dist/components/Switch/tests/Switch.stories.js +77 -23
- package/dist/components/Switch/tests/Switch.test.stories.d.ts +0 -10
- package/dist/components/Switch/tests/Switch.test.stories.js +0 -68
- package/dist/components/Table/Table.js +6 -3
- package/dist/components/Table/Table.module.css +1 -1
- package/dist/components/Table/tests/Table.stories.d.ts +25 -5
- package/dist/components/Table/tests/Table.stories.js +274 -177
- package/dist/components/Table/tests/Table.test.stories.d.ts +0 -5
- package/dist/components/Table/tests/Table.test.stories.js +0 -82
- package/dist/components/Tabs/Tabs.module.css +1 -1
- package/dist/components/TextArea/TextArea.module.css +1 -1
- package/dist/components/TextArea/tests/TextArea.stories.d.ts +41 -9
- package/dist/components/TextArea/tests/TextArea.stories.js +179 -93
- package/dist/components/TextField/TextField.js +1 -1
- package/dist/components/TextField/TextField.module.css +1 -1
- package/dist/components/TextField/tests/TextField.stories.d.ts +41 -11
- package/dist/components/TextField/tests/TextField.stories.js +206 -132
- package/dist/components/TextField/tests/TextField.test.stories.d.ts +0 -13
- package/dist/components/TextField/tests/TextField.test.stories.js +0 -88
- package/dist/components/Theme/Theme.module.css +1 -1
- package/dist/components/Timeline/Timeline.js +3 -2
- package/dist/components/Timeline/tests/Timeline.stories.d.ts +10 -2
- package/dist/components/Timeline/tests/Timeline.stories.js +69 -45
- package/dist/components/Timeline/tests/Timeline.test.stories.d.ts +0 -2
- package/dist/components/Timeline/tests/Timeline.test.stories.js +0 -21
- package/dist/components/Toast/tests/Toast.stories.d.ts +32 -8
- package/dist/components/Toast/tests/Toast.stories.js +109 -37
- package/dist/components/Tooltip/tests/Tooltip.stories.d.ts +18 -4
- package/dist/components/Tooltip/tests/Tooltip.stories.js +139 -107
- package/dist/components/Tooltip/tests/Tooltip.test.stories.d.ts +0 -6
- package/dist/components/Tooltip/tests/Tooltip.test.stories.js +0 -29
- package/dist/components/View/View.js +6 -4
- package/dist/components/View/tests/View.stories.d.ts +4 -0
- package/dist/components/View/tests/View.stories.js +39 -0
- package/dist/hooks/tests/useDrag.stories.js +1 -1
- package/dist/utilities/props.d.ts +3 -0
- package/dist/utilities/props.js +19 -0
- package/dist/utilities/scroll/disable.js +2 -2
- package/package.json +1 -1
- package/dist/components/Alert/tests/Alert.test.stories.d.ts +0 -15
- package/dist/components/Alert/tests/Alert.test.stories.js +0 -26
- package/dist/components/Badge/tests/Badge.test.stories.d.ts +0 -20
- package/dist/components/Badge/tests/Badge.test.stories.js +0 -46
- package/dist/components/Breadcrumbs/tests/Breadcrumbs.test.stories.d.ts +0 -23
- package/dist/components/Breadcrumbs/tests/Breadcrumbs.test.stories.js +0 -76
- package/dist/components/Button/tests/Button.test.stories.d.ts +0 -28
- package/dist/components/Button/tests/Button.test.stories.js +0 -135
- package/dist/components/Card/tests/Card.test.stories.d.ts +0 -35
- package/dist/components/Card/tests/Card.test.stories.js +0 -54
- package/dist/components/Checkbox/tests/Checkbox.test.stories.d.ts +0 -25
- package/dist/components/Checkbox/tests/Checkbox.test.stories.js +0 -104
- package/dist/components/CheckboxGroup/tests/CheckboxGroup.test.stories.d.ts +0 -22
- package/dist/components/CheckboxGroup/tests/CheckboxGroup.test.stories.js +0 -78
- package/dist/components/Container/tests/Container.test.stories.d.ts +0 -15
- package/dist/components/Container/tests/Container.test.stories.js +0 -26
- package/dist/components/ContextMenu/tests/ContextMenu.test.stories.d.ts +0 -25
- package/dist/components/ContextMenu/tests/ContextMenu.test.stories.js +0 -53
- package/dist/components/Dismissible/tests/Dismissible.test.stories.d.ts +0 -19
- package/dist/components/Dismissible/tests/Dismissible.test.stories.js +0 -42
- package/dist/components/Divider/tests/Divider.test.stories.d.ts +0 -18
- package/dist/components/Divider/tests/Divider.test.stories.js +0 -47
- package/dist/components/FormControl/tests/FormControl.test.stories.d.ts +0 -20
- package/dist/components/FormControl/tests/FormControl.test.stories.js +0 -49
- package/dist/components/Hidden/tests/Hidden.test.stories.d.ts +0 -15
- package/dist/components/Hidden/tests/Hidden.test.stories.js +0 -20
- package/dist/components/HiddenVisually/tests/HiddenVisually.test.stories.d.ts +0 -15
- package/dist/components/HiddenVisually/tests/HiddenVisually.test.stories.js +0 -20
- package/dist/components/Hotkey/tests/Hotkey.test.stories.d.ts +0 -15
- package/dist/components/Hotkey/tests/Hotkey.test.stories.js +0 -26
- package/dist/components/Icon/tests/Icon.test.stories.d.ts +0 -16
- package/dist/components/Icon/tests/Icon.test.stories.js +0 -35
- package/dist/components/MenuItem/tests/MenuItem.test.stories.d.ts +0 -27
- package/dist/components/MenuItem/tests/MenuItem.test.stories.js +0 -116
- package/dist/components/Modal/tests/Modal.test.stories.d.ts +0 -31
- package/dist/components/Modal/tests/Modal.test.stories.js +0 -149
- package/dist/components/Overlay/tests/Overlay.test.stories.d.ts +0 -28
- package/dist/components/Overlay/tests/Overlay.test.stories.js +0 -148
- package/dist/components/Pagination/tests/Pagination.test.stories.d.ts +0 -23
- package/dist/components/Pagination/tests/Pagination.test.stories.js +0 -86
- package/dist/components/Progress/tests/Progress.test.stories.d.ts +0 -16
- package/dist/components/Progress/tests/Progress.test.stories.js +0 -35
- package/dist/components/Radio/tests/Radio.test.stories.d.ts +0 -30
- package/dist/components/Radio/tests/Radio.test.stories.js +0 -118
- package/dist/components/RadioGroup/tests/RadioGroup.test.stories.d.ts +0 -22
- package/dist/components/RadioGroup/tests/RadioGroup.test.stories.js +0 -78
- package/dist/components/Scrim/tests/Scrim.test.stories.d.ts +0 -15
- package/dist/components/Scrim/tests/Scrim.test.stories.js +0 -25
- package/dist/components/Select/tests/Select.test.stories.d.ts +0 -27
- package/dist/components/Select/tests/Select.test.stories.js +0 -132
- package/dist/components/Skeleton/tests/Skeleton.test.stories.d.ts +0 -15
- package/dist/components/Skeleton/tests/Skeleton.test.stories.js +0 -23
- package/dist/components/Stepper/tests/Stepper.test.stories.d.ts +0 -20
- package/dist/components/Stepper/tests/Stepper.test.stories.js +0 -28
- package/dist/components/TextArea/tests/TextArea.test.stories.d.ts +0 -28
- package/dist/components/TextArea/tests/TextArea.test.stories.js +0 -99
- package/dist/components/Toast/tests/Toast.test.stories.d.ts +0 -16
- package/dist/components/Toast/tests/Toast.test.stories.js +0 -101
- package/dist/components/View/tests/View.test.stories.d.ts +0 -24
- package/dist/components/View/tests/View.test.stories.js +0 -50
@@ -1,8 +1,11 @@
|
|
1
|
-
import
|
1
|
+
import React from "react";
|
2
|
+
import { expect, fn, userEvent, within } from "storybook/test";
|
2
3
|
import IconZap from "../../../icons/Zap.js";
|
4
|
+
import { Example, Placeholder } from "../../../utilities/storybook/index.js";
|
5
|
+
import useToggle from "../../../hooks/useToggle.js";
|
6
|
+
import Modal from "../../Modal/index.js";
|
7
|
+
import MenuItem from "../../MenuItem/index.js";
|
3
8
|
import Select from "../index.js";
|
4
|
-
import View from "../../View/index.js";
|
5
|
-
import DropdownMenu from "../../DropdownMenu/DropdownMenu.js";
|
6
9
|
import FormControl from "../../FormControl/index.js";
|
7
10
|
export default {
|
8
11
|
title: "Components/Select",
|
@@ -13,179 +16,505 @@ export default {
|
|
13
16
|
},
|
14
17
|
},
|
15
18
|
};
|
16
|
-
export const
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
19
|
+
export const nativeRender = {
|
20
|
+
name: "native rendering, options, name, id",
|
21
|
+
render: () => (<Example>
|
22
|
+
<Example.Item title="native with options prop">
|
23
|
+
<Select name="animal" id="animal-1" placeholder="Select an animal" options={[
|
24
|
+
{ label: "Dog", value: "dog" },
|
25
|
+
{ label: "Turtle", value: "turtle" },
|
26
|
+
]} inputAttributes={{
|
27
|
+
"aria-label": "Select an animal",
|
28
|
+
}}/>
|
29
|
+
</Example.Item>
|
30
|
+
<Example.Item title="native with option tags">
|
31
|
+
<Select name="animal" id="animal-2" placeholder="Select an animal" inputAttributes={{
|
32
|
+
"aria-label": "Select an animal",
|
33
|
+
}}>
|
34
|
+
<option value="dog">Dog</option>
|
35
|
+
<option value="turtle">Turtle</option>
|
36
|
+
</Select>
|
37
|
+
</Example.Item>
|
38
|
+
</Example>),
|
39
|
+
play: ({ canvas }) => {
|
40
|
+
const [selectWithProp, selectWithTags] = canvas.getAllByRole("combobox");
|
41
|
+
const optionsFromProps = within(selectWithProp).getAllByRole("option");
|
42
|
+
const optionsFromTags = within(selectWithTags).getAllByRole("option");
|
43
|
+
expect(selectWithProp).toHaveAttribute("name", "animal");
|
44
|
+
expect(selectWithProp).toHaveAttribute("id", "animal-1");
|
45
|
+
expect(optionsFromProps).toHaveLength(3);
|
46
|
+
expect(optionsFromProps[0]).toHaveTextContent("Select an animal");
|
47
|
+
expect(optionsFromProps[1]).toHaveTextContent("Dog");
|
48
|
+
expect(optionsFromProps[2]).toHaveTextContent("Turtle");
|
49
|
+
expect(selectWithTags).toHaveAttribute("name", "animal");
|
50
|
+
expect(selectWithTags).toHaveAttribute("id", "animal-2");
|
51
|
+
expect(optionsFromTags).toHaveLength(3);
|
52
|
+
expect(optionsFromTags[0]).toHaveTextContent("Select an animal");
|
53
|
+
expect(optionsFromTags[1]).toHaveTextContent("Dog");
|
54
|
+
expect(optionsFromTags[2]).toHaveTextContent("Turtle");
|
55
|
+
},
|
56
|
+
};
|
57
|
+
export const customRender = {
|
58
|
+
name: "custom rendering, name, id, option groups",
|
59
|
+
render: () => (<Example>
|
60
|
+
<Example.Item title="custom with options">
|
61
|
+
<Select.Custom name="animal" id="animal-1" placeholder="Select an animal" inputAttributes={{
|
62
|
+
"aria-label": "Select an animal",
|
63
|
+
}}>
|
64
|
+
<Select.Option value="dog">Dog</Select.Option>
|
65
|
+
<Select.Option value="turtle">Turtle</Select.Option>
|
66
|
+
</Select.Custom>
|
67
|
+
</Example.Item>
|
68
|
+
<Example.Item title="native with option tags">
|
69
|
+
<Select.Custom name="animal-2" id="animal-2" placeholder="Select an animal" inputAttributes={{
|
70
|
+
"aria-label": "Select an animal",
|
71
|
+
}}>
|
72
|
+
<Select.OptionGroup label="Birds">
|
73
|
+
<Select.Option value="pigeon">Pigeon</Select.Option>
|
74
|
+
<Select.Option value="parrot">Parrot</Select.Option>
|
75
|
+
</Select.OptionGroup>
|
76
|
+
<Select.OptionGroup label="Sea Mammals">
|
77
|
+
<Select.Option value="whale">Whale</Select.Option>
|
78
|
+
<Select.Option value="dolphin">Dolphin</Select.Option>
|
79
|
+
</Select.OptionGroup>
|
80
|
+
</Select.Custom>
|
81
|
+
</Example.Item>
|
82
|
+
</Example>),
|
83
|
+
play: async ({ canvas, canvasElement, mount }) => {
|
84
|
+
await mount();
|
85
|
+
const [trigger] = canvas.getAllByRole("button");
|
86
|
+
const hiddenInputs = canvasElement.querySelectorAll('input[type="hidden"]');
|
87
|
+
const [hiddenInput] = Array.from(hiddenInputs);
|
88
|
+
// Testing only options
|
89
|
+
expect(hiddenInput).toHaveAttribute("name", "animal");
|
90
|
+
expect(hiddenInput).toHaveAttribute("id", "animal-1");
|
91
|
+
expect(trigger).toHaveTextContent("Select an animal");
|
92
|
+
await userEvent.click(trigger);
|
93
|
+
const options = within(canvasElement.ownerDocument.body).getAllByRole("option");
|
94
|
+
expect(options).toHaveLength(2);
|
95
|
+
expect(options[0]).toHaveTextContent("Dog");
|
96
|
+
expect(options[1]).toHaveTextContent("Turtle");
|
97
|
+
// Testing options with groups
|
98
|
+
// Remount to instantly close select
|
99
|
+
await mount();
|
100
|
+
const [_, triggerWithGroups] = canvas.getAllByRole("button");
|
101
|
+
const hiddenInputs2 = canvasElement.querySelectorAll('input[type="hidden"]');
|
102
|
+
const [__, hiddenInputWithGroups] = Array.from(hiddenInputs2);
|
103
|
+
await userEvent.click(triggerWithGroups);
|
104
|
+
const optionsWithGroups = within(canvasElement.ownerDocument.body).getAllByRole("option");
|
105
|
+
const optionGroups = within(canvasElement.ownerDocument.body).getAllByRole("group");
|
106
|
+
expect(hiddenInputWithGroups).toHaveAttribute("name", "animal-2");
|
107
|
+
expect(hiddenInputWithGroups).toHaveAttribute("id", "animal-2");
|
108
|
+
expect(triggerWithGroups).toHaveTextContent("Select an animal");
|
109
|
+
expect(optionGroups).toHaveLength(2);
|
110
|
+
expect(optionGroups[0]).toHaveTextContent("Birds");
|
111
|
+
expect(optionGroups[1]).toHaveTextContent("Sea Mammals");
|
112
|
+
expect(optionsWithGroups).toHaveLength(4);
|
113
|
+
expect(optionsWithGroups[0]).toHaveTextContent("Pigeon");
|
114
|
+
expect(optionsWithGroups[1]).toHaveTextContent("Parrot");
|
115
|
+
expect(optionsWithGroups[2]).toHaveTextContent("Whale");
|
116
|
+
expect(optionsWithGroups[3]).toHaveTextContent("Dolphin");
|
117
|
+
},
|
118
|
+
};
|
119
|
+
export const nativeHandlers = {
|
120
|
+
name: "native, controlled, uncontrolled, onFocus, onBlur, onChange",
|
121
|
+
args: {
|
122
|
+
handleChange: fn(),
|
123
|
+
handleControlledChange: fn(),
|
124
|
+
handleFocus: fn(),
|
125
|
+
handleBlur: fn(),
|
126
|
+
handleClick: fn(),
|
127
|
+
},
|
128
|
+
render: (args) => (<Example>
|
129
|
+
<Example.Item title="native, uncontrolled, onChange">
|
130
|
+
<Select name="animal" placeholder="Select an animal" defaultValue="dog" onChange={args.handleChange} inputAttributes={{
|
131
|
+
"aria-label": "Select an animal",
|
132
|
+
}}>
|
133
|
+
<option value="dog">Dog</option>
|
134
|
+
<option value="turtle">Turtle</option>
|
135
|
+
</Select>
|
136
|
+
</Example.Item>
|
137
|
+
<Example.Item title="native, controlled, onChange">
|
138
|
+
<Select name="animal-2" placeholder="Select an animal" value="dog" onChange={args.handleControlledChange} inputAttributes={{
|
139
|
+
"aria-label": "Select an animal",
|
140
|
+
}}>
|
141
|
+
<option value="dog">Dog</option>
|
142
|
+
<option value="turtle">Turtle</option>
|
143
|
+
</Select>
|
144
|
+
</Example.Item>
|
145
|
+
<Example.Item title="native, onFocus, onBlur, onClick">
|
146
|
+
<Select name="animal-3" placeholder="Select an animal" defaultValue="dog" onFocus={args.handleFocus} onBlur={args.handleBlur} onClick={args.handleClick} inputAttributes={{
|
147
|
+
"aria-label": "Select an animal",
|
148
|
+
}}>
|
149
|
+
<option value="dog">Dog</option>
|
150
|
+
<option value="turtle">Turtle</option>
|
151
|
+
</Select>
|
152
|
+
</Example.Item>
|
153
|
+
</Example>),
|
154
|
+
play: async ({ canvas, args }) => {
|
155
|
+
const [uncontrolled, controlled, focusable] = canvas.getAllByRole("combobox");
|
156
|
+
// Uncontrolled
|
157
|
+
expect(uncontrolled).toHaveValue("dog");
|
158
|
+
await userEvent.selectOptions(uncontrolled, "turtle");
|
159
|
+
expect(uncontrolled).toHaveValue("turtle");
|
160
|
+
expect(args.handleChange).toHaveBeenCalledTimes(1);
|
161
|
+
expect(args.handleChange).toHaveBeenCalledWith({
|
162
|
+
name: "animal",
|
163
|
+
value: "turtle",
|
164
|
+
event: expect.objectContaining({ target: uncontrolled }),
|
165
|
+
});
|
166
|
+
// Controlled
|
167
|
+
expect(controlled).toHaveValue("dog");
|
168
|
+
await userEvent.selectOptions(controlled, "turtle");
|
169
|
+
expect(controlled).toHaveValue("dog");
|
170
|
+
expect(args.handleControlledChange).toHaveBeenCalledTimes(1);
|
171
|
+
expect(args.handleControlledChange).toHaveBeenCalledWith({
|
172
|
+
name: "animal-2",
|
173
|
+
value: "turtle",
|
174
|
+
event: expect.objectContaining({ target: controlled }),
|
175
|
+
});
|
176
|
+
// Focus + blur
|
177
|
+
await userEvent.click(focusable);
|
178
|
+
expect(args.handleFocus).toHaveBeenCalledTimes(1);
|
179
|
+
expect(args.handleFocus).toHaveBeenCalledWith(expect.objectContaining({ target: focusable }));
|
180
|
+
expect(args.handleClick).toHaveBeenCalledTimes(1);
|
181
|
+
expect(args.handleClick).toHaveBeenCalledWith(expect.objectContaining({ target: focusable }));
|
182
|
+
await userEvent.click(document.body);
|
183
|
+
expect(args.handleBlur).toHaveBeenCalledTimes(1);
|
184
|
+
expect(args.handleBlur).toHaveBeenCalledWith(expect.objectContaining({ target: focusable }));
|
185
|
+
},
|
186
|
+
};
|
187
|
+
export const customHandlers = {
|
188
|
+
name: "custom, controlled, uncontrolled, onFocus, onBlur, onChange",
|
189
|
+
args: {
|
190
|
+
handleChange: fn(),
|
191
|
+
handleControlledChange: fn(),
|
192
|
+
handleFocus: fn(),
|
193
|
+
handleBlur: fn(),
|
194
|
+
handleClick: fn(),
|
195
|
+
},
|
196
|
+
render: (args) => (<Example>
|
197
|
+
<Example.Item title="custom, uncontrolled, onChange">
|
198
|
+
<Select.Custom name="animal" placeholder="Select an animal" defaultValue="dog" onChange={args.handleChange} inputAttributes={{
|
199
|
+
"aria-label": "Select an animal",
|
200
|
+
}}>
|
201
|
+
<Select.Option value="dog">Dog</Select.Option>
|
202
|
+
<Select.Option value="turtle">Turtle</Select.Option>
|
203
|
+
</Select.Custom>
|
204
|
+
</Example.Item>
|
205
|
+
<Example.Item title="custom, controlled, onChange">
|
206
|
+
<Select.Custom name="animal-2" placeholder="Select an animal" value="dog" onChange={args.handleControlledChange} inputAttributes={{
|
207
|
+
"aria-label": "Select an animal",
|
208
|
+
}}>
|
209
|
+
<Select.Option value="dog">Dog</Select.Option>
|
210
|
+
<Select.Option value="turtle">Turtle</Select.Option>
|
211
|
+
</Select.Custom>
|
212
|
+
</Example.Item>
|
213
|
+
<Example.Item title="native, onFocus, onBlur, onClick">
|
214
|
+
<Select.Custom name="animal-3" placeholder="Select an animal" defaultValue="dog" onFocus={args.handleFocus} onBlur={args.handleBlur} onClick={args.handleClick} inputAttributes={{
|
215
|
+
"aria-label": "Select an animal",
|
216
|
+
}}>
|
217
|
+
<Select.Option value="dog">Dog</Select.Option>
|
218
|
+
<Select.Option value="turtle">Turtle</Select.Option>
|
219
|
+
</Select.Custom>
|
220
|
+
</Example.Item>
|
221
|
+
</Example>),
|
222
|
+
play: async ({ canvas, canvasElement, args, mount }) => {
|
223
|
+
await mount();
|
224
|
+
const [uncontrolled] = canvas.getAllByRole("button");
|
225
|
+
const hiddenInputs = canvasElement.querySelectorAll('input[type="hidden"]');
|
226
|
+
const [inputUncontrolled] = Array.from(hiddenInputs);
|
227
|
+
// Uncontrolled
|
228
|
+
expect(inputUncontrolled).toHaveValue("dog");
|
229
|
+
await userEvent.click(uncontrolled);
|
230
|
+
const [_, uncontrolledOption] = within(canvasElement.ownerDocument.body).getAllByRole("option");
|
231
|
+
await userEvent.click(uncontrolledOption);
|
232
|
+
expect(inputUncontrolled).toHaveValue("turtle");
|
233
|
+
expect(args.handleChange).toHaveBeenCalledTimes(1);
|
234
|
+
expect(args.handleChange).toHaveBeenCalledWith({
|
235
|
+
name: "animal",
|
236
|
+
value: "turtle",
|
237
|
+
});
|
238
|
+
// Controlled
|
239
|
+
await mount();
|
240
|
+
const [__, controlled, focusable] = canvas.getAllByRole("button");
|
241
|
+
const hiddenInputs2 = canvasElement.querySelectorAll('input[type="hidden"]');
|
242
|
+
const [___, inputControlled] = Array.from(hiddenInputs2);
|
243
|
+
expect(inputControlled).toHaveValue("dog");
|
244
|
+
await userEvent.click(controlled);
|
245
|
+
const [____, controlledOption] = within(canvasElement.ownerDocument.body).getAllByRole("option");
|
246
|
+
await userEvent.click(controlledOption);
|
247
|
+
expect(inputControlled).toHaveValue("dog");
|
248
|
+
expect(args.handleControlledChange).toHaveBeenCalledTimes(1);
|
249
|
+
expect(args.handleControlledChange).toHaveBeenCalledWith({
|
250
|
+
name: "animal-2",
|
251
|
+
value: "turtle",
|
252
|
+
});
|
253
|
+
// Focus + blur + click
|
254
|
+
await userEvent.click(focusable);
|
255
|
+
expect(args.handleFocus).toHaveBeenCalledTimes(1);
|
256
|
+
expect(args.handleFocus).toHaveBeenCalledWith(expect.objectContaining({ target: focusable }));
|
257
|
+
expect(args.handleClick).toHaveBeenCalledTimes(1);
|
258
|
+
expect(args.handleClick).toHaveBeenCalledWith(expect.objectContaining({ target: focusable }));
|
259
|
+
await userEvent.click(document.body);
|
260
|
+
expect(args.handleBlur).toHaveBeenCalledTimes(1);
|
261
|
+
expect(args.handleBlur).toHaveBeenCalledWith(expect.objectContaining({ target: focusable }));
|
262
|
+
},
|
263
|
+
};
|
264
|
+
export const triggerOnly = {
|
265
|
+
name: "trigger only, onClick",
|
266
|
+
args: {
|
267
|
+
handleClick: fn(),
|
268
|
+
},
|
269
|
+
render: (args) => {
|
270
|
+
const toggle = useToggle();
|
271
|
+
const [value, setValue] = React.useState("Dog");
|
272
|
+
const handleClick = (e) => {
|
273
|
+
args.handleClick(e);
|
274
|
+
toggle.toggle();
|
275
|
+
};
|
276
|
+
return (<Example>
|
277
|
+
<Example.Item title="trigger only, onClick">
|
278
|
+
<Select name="animal" placeholder="Select an animal" onClick={handleClick} value="dog" inputAttributes={{
|
279
|
+
"aria-label": "Select an animal",
|
280
|
+
}}>
|
281
|
+
{value}
|
282
|
+
</Select>
|
283
|
+
<Modal active={toggle.active} onClose={toggle.deactivate} position="bottom" padding={2} attributes={{ "aria-label": "Select an animal" }}>
|
284
|
+
<div role="listbox" aria-label="Select an animal">
|
285
|
+
<MenuItem roundedCorners onClick={() => {
|
286
|
+
setValue("Dog");
|
287
|
+
toggle.deactivate();
|
288
|
+
}} attributes={{
|
289
|
+
role: "option",
|
290
|
+
}}>
|
291
|
+
Dog
|
292
|
+
</MenuItem>
|
293
|
+
<MenuItem roundedCorners attributes={{
|
294
|
+
role: "option",
|
295
|
+
}} onClick={() => {
|
296
|
+
setValue("Turtle");
|
297
|
+
toggle.deactivate();
|
298
|
+
}}>
|
299
|
+
Turtle
|
300
|
+
</MenuItem>
|
301
|
+
</div>
|
302
|
+
</Modal>
|
303
|
+
</Example.Item>
|
304
|
+
</Example>);
|
305
|
+
},
|
306
|
+
play: async ({ canvas, args, canvasElement }) => {
|
307
|
+
const [trigger] = canvas.getAllByRole("button");
|
308
|
+
const hiddenInputs = canvasElement.querySelectorAll('input[type="hidden"]');
|
309
|
+
const [input] = Array.from(hiddenInputs);
|
310
|
+
expect(trigger).toHaveTextContent("Dog");
|
311
|
+
expect(input).toHaveAttribute("name", "animal");
|
312
|
+
expect(input).toHaveValue("dog");
|
313
|
+
await userEvent.click(trigger);
|
314
|
+
expect(args.handleClick).toHaveBeenCalledTimes(1);
|
315
|
+
expect(args.handleClick).toHaveBeenCalledWith(expect.objectContaining({ target: trigger }));
|
316
|
+
},
|
317
|
+
};
|
318
|
+
export const multiple = {
|
319
|
+
name: "multiple",
|
320
|
+
args: {
|
321
|
+
handleChange: fn(),
|
322
|
+
},
|
323
|
+
render: (args) => (<Example>
|
324
|
+
<Example.Item title="multiple">
|
325
|
+
<Select.Custom multiple name="animal" placeholder="Select an animal" defaultValue={["dog"]} onChange={args.handleChange}>
|
326
|
+
<Select.Option value="dog">Dog</Select.Option>
|
327
|
+
<Select.Option value="turtle">Turtle</Select.Option>
|
328
|
+
</Select.Custom>
|
329
|
+
</Example.Item>
|
330
|
+
</Example>),
|
331
|
+
play: async ({ canvas, canvasElement, args }) => {
|
332
|
+
const [uncontrolled] = canvas.getAllByRole("button");
|
333
|
+
const hiddenInputs = canvasElement.querySelectorAll('input[type="hidden"]');
|
334
|
+
const [inputUncontrolled] = Array.from(hiddenInputs);
|
335
|
+
// Uncontrolled
|
336
|
+
expect(inputUncontrolled).toHaveValue('["dog"]');
|
337
|
+
await userEvent.click(uncontrolled);
|
338
|
+
const [_, uncontrolledOption] = within(canvasElement.ownerDocument.body).getAllByRole("option");
|
339
|
+
await userEvent.click(uncontrolledOption);
|
340
|
+
expect(inputUncontrolled).toHaveValue('["dog","turtle"]');
|
341
|
+
expect(args.handleChange).toHaveBeenCalledTimes(1);
|
342
|
+
expect(args.handleChange).toHaveBeenCalledWith({
|
343
|
+
name: "animal",
|
344
|
+
value: ["dog", "turtle"],
|
345
|
+
});
|
346
|
+
},
|
347
|
+
};
|
348
|
+
export const variant = {
|
349
|
+
name: "variant",
|
350
|
+
render: () => (<Example>
|
351
|
+
<Example.Item title="variant: faded, native">
|
352
|
+
<Select variant="faded" name="animal" placeholder="Select an animal" inputAttributes={{ "aria-label": "Select an animal" }}>
|
353
|
+
<option value="dog">Dog</option>
|
354
|
+
<option value="turtle">Turtle</option>
|
355
|
+
</Select>
|
356
|
+
</Example.Item>
|
63
357
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
<Select
|
68
|
-
|
69
|
-
|
70
|
-
]} inputAttributes={{ "aria-label": "test select" }}/>
|
71
|
-
</View.Item>
|
72
|
-
<View.Item grow>
|
73
|
-
<Select size="medium" name="animal" startSlot={<Placeholder h={24}/>} options={[
|
74
|
-
{ label: "Dog", value: "dog" },
|
75
|
-
{ label: "Turtle", value: "turtle" },
|
76
|
-
]} inputAttributes={{ "aria-label": "test select" }}/>
|
77
|
-
</View.Item>
|
78
|
-
</View>
|
79
|
-
</Example.Item>
|
358
|
+
<Example.Item title="variant: faded, custom">
|
359
|
+
<Select.Custom variant="faded" name="animal-2" placeholder="Select an animal" inputAttributes={{ "aria-label": "Select an animal" }}>
|
360
|
+
<Select.Option value="dog">Dog</Select.Option>
|
361
|
+
<Select.Option value="turtle">Turtle</Select.Option>
|
362
|
+
</Select.Custom>
|
363
|
+
</Example.Item>
|
80
364
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
<
|
85
|
-
|
86
|
-
|
87
|
-
]} inputAttributes={{ "aria-label": "test select" }}/>
|
88
|
-
</View.Item>
|
89
|
-
<View.Item grow>
|
90
|
-
<Select size="large" name="animal" startSlot={<Placeholder h={24}/>} options={[
|
91
|
-
{ label: "Dog", value: "dog" },
|
92
|
-
{ label: "Turtle", value: "turtle" },
|
93
|
-
]} inputAttributes={{ "aria-label": "test select" }}/>
|
94
|
-
</View.Item>
|
95
|
-
</View>
|
96
|
-
</Example.Item>
|
365
|
+
<Example.Item title="variant: headless, native">
|
366
|
+
<Select variant="headless" name="animal-3" placeholder="Select an animal" inputAttributes={{ "aria-label": "Select an animal" }}>
|
367
|
+
<option value="dog">Dog</option>
|
368
|
+
<option value="turtle">Turtle</option>
|
369
|
+
</Select>
|
370
|
+
</Example.Item>
|
97
371
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
<Select
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
372
|
+
<Example.Item title="variant: headless, custom">
|
373
|
+
<Select.Custom variant="headless" name="animal-4" placeholder="Select an animal" inputAttributes={{ "aria-label": "Select an animal" }}>
|
374
|
+
<Select.Option value="dog">Dog</Select.Option>
|
375
|
+
<Select.Option value="turtle">Turtle</Select.Option>
|
376
|
+
</Select.Custom>
|
377
|
+
</Example.Item>
|
378
|
+
</Example>),
|
379
|
+
};
|
380
|
+
export const size = {
|
381
|
+
name: "size",
|
382
|
+
render: () => (<Example>
|
383
|
+
<Example.Item title="size: small">
|
384
|
+
<Select.Custom size="small" name="animal" placeholder="Select an animal">
|
385
|
+
<Select.Option value="dog">Dog</Select.Option>
|
386
|
+
<Select.Option value="turtle">Turtle</Select.Option>
|
387
|
+
</Select.Custom>
|
388
|
+
</Example.Item>
|
389
|
+
<Example.Item title="size: medium">
|
390
|
+
<Select.Custom size="medium" name="animal" placeholder="Select an animal">
|
391
|
+
<Select.Option value="dog">Dog</Select.Option>
|
392
|
+
<Select.Option value="turtle">Turtle</Select.Option>
|
393
|
+
</Select.Custom>
|
394
|
+
</Example.Item>
|
395
|
+
<Example.Item title="size: large">
|
396
|
+
<Select.Custom size="large" name="animal" placeholder="Select an animal">
|
397
|
+
<Select.Option value="dog">Dog</Select.Option>
|
398
|
+
<Select.Option value="turtle">Turtle</Select.Option>
|
399
|
+
</Select.Custom>
|
400
|
+
</Example.Item>
|
401
|
+
<Example.Item title="size: xlarge">
|
402
|
+
<Select.Custom size="xlarge" name="animal" placeholder="Select an animal">
|
403
|
+
<Select.Option value="dog">Dog</Select.Option>
|
404
|
+
<Select.Option value="turtle">Turtle</Select.Option>
|
405
|
+
</Select.Custom>
|
406
|
+
</Example.Item>
|
407
|
+
</Example>),
|
408
|
+
};
|
409
|
+
export const startSlot = {
|
410
|
+
name: "icon,startSlot",
|
411
|
+
render: () => (<Example>
|
412
|
+
<Example.Item title="icon">
|
413
|
+
<Select.Custom name="animal" placeholder="Select an animal" icon={IconZap}>
|
414
|
+
<Select.Option value="dog">Dog</Select.Option>
|
415
|
+
<Select.Option value="turtle">Turtle</Select.Option>
|
416
|
+
</Select.Custom>
|
417
|
+
</Example.Item>
|
114
418
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
<
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
<
|
189
|
-
|
190
|
-
|
191
|
-
|
419
|
+
<Example.Item title="startSlot">
|
420
|
+
<Select.Custom name="animal" placeholder="Select an animal" startSlot={<Placeholder h={20}/>}>
|
421
|
+
<Select.Option value="dog">Dog</Select.Option>
|
422
|
+
<Select.Option value="turtle">Turtle</Select.Option>
|
423
|
+
</Select.Custom>
|
424
|
+
</Example.Item>
|
425
|
+
</Example>),
|
426
|
+
};
|
427
|
+
export const error = {
|
428
|
+
name: "error",
|
429
|
+
render: () => (<Example>
|
430
|
+
<Example.Item title="error">
|
431
|
+
<Select.Custom name="animal" placeholder="Select an animal" hasError>
|
432
|
+
<Select.Option value="dog">Dog</Select.Option>
|
433
|
+
<Select.Option value="turtle">Turtle</Select.Option>
|
434
|
+
</Select.Custom>
|
435
|
+
</Example.Item>
|
436
|
+
</Example>),
|
437
|
+
};
|
438
|
+
export const disabled = {
|
439
|
+
name: "disabled",
|
440
|
+
render: () => (<Example>
|
441
|
+
<Example.Item title="disabled, native">
|
442
|
+
<Select name="animal" placeholder="Select an animal" disabled inputAttributes={{ "aria-label": "Select an animal" }}>
|
443
|
+
<option value="dog">Dog</option>
|
444
|
+
<option value="turtle">Turtle</option>
|
445
|
+
</Select>
|
446
|
+
</Example.Item>
|
447
|
+
<Example.Item title="disabled, custom">
|
448
|
+
<Select.Custom name="animal-2" placeholder="Select an animal" disabled inputAttributes={{ "aria-label": "Select an animal" }}>
|
449
|
+
<Select.Option value="dog">Dog</Select.Option>
|
450
|
+
<Select.Option value="turtle">Turtle</Select.Option>
|
451
|
+
</Select.Custom>
|
452
|
+
</Example.Item>
|
453
|
+
</Example>),
|
454
|
+
play: ({ canvas }) => {
|
455
|
+
const [native] = canvas.getAllByRole("combobox");
|
456
|
+
const [custom] = canvas.getAllByRole("button");
|
457
|
+
expect(native).toBeDisabled();
|
458
|
+
expect(custom).toBeDisabled();
|
459
|
+
},
|
460
|
+
};
|
461
|
+
export const className = {
|
462
|
+
name: "className, attributes, inputAttributes",
|
463
|
+
render: () => (<Example>
|
464
|
+
<Example.Item title="native, className, attributes, inputAttributes">
|
465
|
+
<Select name="animal" placeholder="Select an animal" className="native-class" attributes={{ id: "test-id" }} inputAttributes={{ "aria-label": "test-label" }}>
|
466
|
+
<option value="dog">Dog</option>
|
467
|
+
<option value="turtle">Turtle</option>
|
468
|
+
</Select>
|
469
|
+
</Example.Item>
|
470
|
+
<Example.Item title="custom, className, attributes, inputAttributes">
|
471
|
+
<Select.Custom name="animal" placeholder="Select an animal" className="custom-class" attributes={{ id: "test-id" }} inputAttributes={{ "aria-label": "test-label" }}>
|
472
|
+
<Select.Option value="dog">Dog</Select.Option>
|
473
|
+
<Select.Option value="turtle">Turtle</Select.Option>
|
474
|
+
</Select.Custom>
|
475
|
+
</Example.Item>
|
476
|
+
</Example>),
|
477
|
+
play: ({ canvas, canvasElement }) => {
|
478
|
+
const native = canvasElement.querySelector(".native-class");
|
479
|
+
const nativeInput = canvas.getByRole("combobox");
|
480
|
+
const custom = canvasElement.querySelector(".custom-class");
|
481
|
+
const [customTrigger] = canvas.getAllByRole("button");
|
482
|
+
expect(native).toHaveAttribute("id", "test-id");
|
483
|
+
expect(nativeInput).toHaveAttribute("aria-label", "test-label");
|
484
|
+
expect(custom).toHaveAttribute("id", "test-id");
|
485
|
+
expect(customTrigger).toHaveAttribute("aria-label", "test-label");
|
486
|
+
},
|
487
|
+
};
|
488
|
+
export const fallback = {
|
489
|
+
name: "test: fallbackAdjustLayout",
|
490
|
+
render: () => (<Example>
|
491
|
+
<Example.Item title="fallback">
|
492
|
+
<Select.Custom name="animal" placeholder="Select an animal" inputAttributes={{ "aria-label": "Select an animal" }}>
|
493
|
+
{[...Array(100)].map((_, index) => (<Select.Option key={index} value={`item-${index}`}>
|
494
|
+
Item {index + 1}
|
495
|
+
</Select.Option>))}
|
496
|
+
</Select.Custom>
|
497
|
+
<div style={{ height: "1000px" }}></div>
|
498
|
+
<Select.Custom name="animal" placeholder="Select an animal" inputAttributes={{ "aria-label": "Select an animal" }}>
|
499
|
+
{[...Array(100)].map((_, index) => (<Select.Option key={index} value={`item-${index}`}>
|
500
|
+
Item {index + 1}
|
501
|
+
</Select.Option>))}
|
502
|
+
</Select.Custom>
|
503
|
+
</Example.Item>
|
504
|
+
</Example>),
|
505
|
+
};
|
506
|
+
export const formControl = {
|
507
|
+
name: "test: with FormControl",
|
508
|
+
render: () => (<Example>
|
509
|
+
<Example.Item title="FormControl">
|
510
|
+
<FormControl hasError>
|
511
|
+
<FormControl.Label>Animal</FormControl.Label>
|
512
|
+
<Select.Custom name="animal" placeholder="Select an animal">
|
513
|
+
<Select.Option value="dog">Dog</Select.Option>
|
514
|
+
<Select.Option value="turtle">Turtle</Select.Option>
|
515
|
+
</Select.Custom>
|
516
|
+
<FormControl.Error>This field is required</FormControl.Error>
|
517
|
+
</FormControl>
|
518
|
+
</Example.Item>
|
519
|
+
</Example>),
|
520
|
+
};
|