@loadsmart/loadsmart-ui 5.11.0 → 5.11.1
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/dist/index.js +490 -340
- package/dist/index.js.map +1 -1
- package/dist/testing/SelectEvent/SelectEvent.d.ts +2 -0
- package/dist/testing/index.js +1 -1
- package/dist/testing/index.js.map +1 -1
- package/package.json +8 -7
- package/src/common/CloseButton/CloseButton.tsx +11 -7
- package/src/common/SelectionWrapper.tsx +7 -7
- package/src/components/Accordion/Accordion.tsx +28 -22
- package/src/components/Banner/Banner.tsx +2 -2
- package/src/components/Breadcrumbs/Breadcrumb.tsx +3 -2
- package/src/components/Breadcrumbs/Breadcrumbs.tsx +1 -1
- package/src/components/Button/Button.tsx +20 -17
- package/src/components/Calendar/Calendar.tsx +8 -4
- package/src/components/Calendar/PickerModeToggle.tsx +6 -3
- package/src/components/Calendar/Pickers/DayPicker.tsx +1 -1
- package/src/components/Calendar/Pickers/MonthPicker.tsx +1 -1
- package/src/components/Calendar/Pickers/PickerButton.tsx +39 -29
- package/src/components/Calendar/Pickers/YearPicker.tsx +1 -1
- package/src/components/Card/Card.tsx +9 -6
- package/src/components/Card/CardTitle.tsx +3 -4
- package/src/components/Checkbox/Checkbox.tsx +26 -14
- package/src/components/Dialog/Dialog.tsx +5 -5
- package/src/components/DragDropFile/styles.tsx +11 -6
- package/src/components/Drawer/Drawer.tsx +6 -6
- package/src/components/Dropdown/DropdownMenu.tsx +28 -15
- package/src/components/Dropdown/DropdownTrigger.tsx +34 -24
- package/src/components/HighlightMatch/HighlightMatch.tsx +1 -2
- package/src/components/Label/Label.tsx +3 -3
- package/src/components/Link/Link.tsx +13 -9
- package/src/components/Loaders/LoadingBar.tsx +2 -2
- package/src/components/Modal/Modal.tsx +12 -7
- package/src/components/ProgressBar/ProgressBar.tsx +6 -4
- package/src/components/Radio/Radio.tsx +19 -11
- package/src/components/Section/Section.tsx +8 -6
- package/src/components/Select/Select.test.tsx +161 -161
- package/src/components/Select/SelectEmpty.tsx +5 -4
- package/src/components/Select/SelectTrigger.tsx +11 -6
- package/src/components/SideNavigation/Menu/Menu.tsx +3 -3
- package/src/components/SideNavigation/Menu/MenuBaseItem.tsx +5 -4
- package/src/components/SideNavigation/Menu/MenuExpandable.tsx +3 -2
- package/src/components/Steps/ProgressSteps/ProgressStep.tsx +39 -31
- package/src/components/Switch/Switch.tsx +18 -6
- package/src/components/Table/Table.tsx +2 -2
- package/src/components/Tabs/Tabs.tsx +32 -26
- package/src/components/Tag/Tag.tsx +44 -35
- package/src/components/TextField/TextField.tsx +22 -15
- package/src/components/Textarea/Textarea.tsx +22 -17
- package/src/components/Toast/Toast.tsx +3 -3
- package/src/components/ToggleGroup/Toggle.tsx +7 -7
- package/src/components/ToggleGroup/ToggleGroup.stories.tsx +14 -12
- package/src/components/Tooltip/Tooltip.tsx +22 -20
- package/src/components/TopNavigation/Menu/MenuItemDropdown.tsx +1 -1
- package/src/components/TopNavigation/OpenSideNavButton/OpenSideNavButton.tsx +1 -1
- package/src/styles/font.tsx +3 -3
- package/src/testing/SelectEvent/SelectEvent.ts +87 -45
|
@@ -48,10 +48,9 @@ const TextareaWrapper = styled.div<WithAdditionalProps>`
|
|
|
48
48
|
'textarea-large-font-size': whenProps({ scale: 'large' }),
|
|
49
49
|
})};
|
|
50
50
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
})};
|
|
51
|
+
border-radius: ${token('textarea-border-radius')};
|
|
52
|
+
border-width: 1px;
|
|
53
|
+
border-style: solid;
|
|
55
54
|
|
|
56
55
|
background: ${conditional({
|
|
57
56
|
'textarea-background': whenProps({ scheme: 'light' }),
|
|
@@ -64,9 +63,11 @@ const TextareaWrapper = styled.div<WithAdditionalProps>`
|
|
|
64
63
|
'textarea-danger-border-color': whenProps({ status: Status.Danger }),
|
|
65
64
|
'textarea-success-border-color': whenProps({ status: Status.Success }),
|
|
66
65
|
})};
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
66
|
+
|
|
67
|
+
color: ${conditional({
|
|
68
|
+
'textarea-color': whenProps({ scheme: 'light' }),
|
|
69
|
+
'textarea-dark-color': whenProps({ scheme: 'dark' }),
|
|
70
|
+
})};
|
|
70
71
|
|
|
71
72
|
${hoverable`
|
|
72
73
|
background: ${conditional({
|
|
@@ -119,30 +120,36 @@ const StyledSpan = styled.span<WithAdditionalProps>`
|
|
|
119
120
|
const Leading = styled(StyledSpan)<WithAdditionalProps>`
|
|
120
121
|
align-items: flex-start;
|
|
121
122
|
|
|
122
|
-
padding: ${token('space-s')} 0;
|
|
123
|
-
|
|
124
123
|
margin: 0 0 0
|
|
125
124
|
${conditional({
|
|
126
125
|
'text-field-padding-x': whenProps({ scale: ['default', 'large'] }),
|
|
127
126
|
'text-field-small-padding-x': whenProps({ scale: 'small' }),
|
|
128
127
|
})};
|
|
128
|
+
|
|
129
|
+
padding: ${token('space-s')} 0;
|
|
129
130
|
`
|
|
130
131
|
|
|
131
132
|
const Trailing = styled(StyledSpan)<WithAdditionalProps>`
|
|
132
133
|
align-items: flex-start;
|
|
133
134
|
|
|
134
|
-
padding: ${token('space-s')} 0;
|
|
135
|
-
|
|
136
135
|
margin: 0
|
|
137
136
|
${conditional({
|
|
138
137
|
'text-field-padding-x': whenProps({ scale: ['default', 'large'] }),
|
|
139
138
|
'text-field-small-padding-x': whenProps({ scale: 'small' }),
|
|
140
139
|
})}
|
|
141
140
|
0 0;
|
|
141
|
+
|
|
142
|
+
padding: ${token('space-s')} 0;
|
|
142
143
|
`
|
|
143
144
|
|
|
144
145
|
const StyledTextarea = styled.textarea<WithAdditionalProps>`
|
|
145
|
-
|
|
146
|
+
${transition()}
|
|
147
|
+
|
|
148
|
+
${font({
|
|
149
|
+
height: 'textarea-font-height',
|
|
150
|
+
})}
|
|
151
|
+
|
|
152
|
+
background: transparent;
|
|
146
153
|
|
|
147
154
|
padding: ${conditional({
|
|
148
155
|
'textarea-padding-y': whenProps({ scale: 'default' }),
|
|
@@ -150,19 +157,17 @@ const StyledTextarea = styled.textarea<WithAdditionalProps>`
|
|
|
150
157
|
'textarea-large-padding-y': whenProps({ scale: 'large' }),
|
|
151
158
|
})}
|
|
152
159
|
0;
|
|
160
|
+
|
|
153
161
|
margin: 0
|
|
154
162
|
${conditional({
|
|
155
163
|
'textarea-padding-x': whenProps({ scale: ['default', 'large'] }),
|
|
156
164
|
'textarea-small-padding-x': whenProps({ scale: 'small' }),
|
|
157
165
|
})};
|
|
158
166
|
|
|
159
|
-
background: transparent;
|
|
160
167
|
border: none;
|
|
161
168
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
height: 'textarea-font-height',
|
|
165
|
-
})}
|
|
169
|
+
flex: 1 0 auto;
|
|
170
|
+
|
|
166
171
|
${focusable()}
|
|
167
172
|
${disableable()}
|
|
168
173
|
`
|
|
@@ -18,11 +18,11 @@ const Container = styled.div<ContainerProps>`
|
|
|
18
18
|
max-width: 100%;
|
|
19
19
|
padding: ${token('toast-padding-y')} ${token('toast-padding-x')};
|
|
20
20
|
overflow: hidden;
|
|
21
|
-
font-size: ${token('toast-font-size')};
|
|
22
|
-
font-weight: ${token('toast-font-weight')};
|
|
23
|
-
line-height: ${token('toast-font-height')};
|
|
24
21
|
|
|
25
22
|
color: ${token('toast-font-color')};
|
|
23
|
+
font-weight: ${token('toast-font-weight')};
|
|
24
|
+
font-size: ${token('toast-font-size')};
|
|
25
|
+
line-height: ${token('toast-font-height')};
|
|
26
26
|
|
|
27
27
|
background: ${conditional({
|
|
28
28
|
'toast-neutral-background': whenProps({ status: Status.Neutral }),
|
|
@@ -14,13 +14,6 @@ import ToggleGroupContext, { SelectableContext } from './ToggleGroupContext'
|
|
|
14
14
|
import type { ToggleGroupOptionProps, ToggleGroupType } from './ToggleGroup.types'
|
|
15
15
|
|
|
16
16
|
const ToggleButton = styled(BaseButton)<{ $type: ToggleGroupType }>`
|
|
17
|
-
padding: ${token('space-xs')} ${token('space-s')};
|
|
18
|
-
|
|
19
|
-
color: ${conditional({
|
|
20
|
-
'color-neutral-darker': whenProps({ 'aria-checked': false }),
|
|
21
|
-
'color-neutral-white': whenProps({ 'aria-checked': true }),
|
|
22
|
-
})};
|
|
23
|
-
|
|
24
17
|
background: ${conditional({
|
|
25
18
|
'color-transparent': whenProps({ 'aria-checked': false }),
|
|
26
19
|
'color-neutral-darkest': whenProps({ 'aria-checked': true }),
|
|
@@ -34,6 +27,13 @@ const ToggleButton = styled(BaseButton)<{ $type: ToggleGroupType }>`
|
|
|
34
27
|
'color-transparent': whenProps({ $type: 'single', 'aria-checked': false }),
|
|
35
28
|
})};
|
|
36
29
|
|
|
30
|
+
color: ${conditional({
|
|
31
|
+
'color-neutral-darker': whenProps({ 'aria-checked': false }),
|
|
32
|
+
'color-neutral-white': whenProps({ 'aria-checked': true }),
|
|
33
|
+
})};
|
|
34
|
+
|
|
35
|
+
padding: ${token('space-xs')} ${token('space-s')};
|
|
36
|
+
|
|
37
37
|
${hoverable`
|
|
38
38
|
border-color: ${conditional({
|
|
39
39
|
'color-neutral-dark': whenProps({ $type: 'multiple' }),
|
|
@@ -87,6 +87,19 @@ Playground.args = {
|
|
|
87
87
|
scale: 'default',
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
+
const withIconOptions = [
|
|
91
|
+
{
|
|
92
|
+
label: 'Above',
|
|
93
|
+
value: true,
|
|
94
|
+
leading: <span>♣</span>,
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
label: 'Below',
|
|
98
|
+
value: false,
|
|
99
|
+
leading: <span>♠</span>,
|
|
100
|
+
},
|
|
101
|
+
]
|
|
102
|
+
|
|
90
103
|
export const WithIcon: Story<ToggleGroupProps> = (args) => {
|
|
91
104
|
return (
|
|
92
105
|
<div className="flex flex-row">
|
|
@@ -97,18 +110,7 @@ export const WithIcon: Story<ToggleGroupProps> = (args) => {
|
|
|
97
110
|
aria-labelledby="rank_options_label"
|
|
98
111
|
id="rank_options"
|
|
99
112
|
name="rank_options"
|
|
100
|
-
options={
|
|
101
|
-
{
|
|
102
|
-
label: 'Above',
|
|
103
|
-
value: true,
|
|
104
|
-
leading: <span>♣</span>,
|
|
105
|
-
},
|
|
106
|
-
{
|
|
107
|
-
label: 'Below',
|
|
108
|
-
value: false,
|
|
109
|
-
leading: <span>♠</span>,
|
|
110
|
-
},
|
|
111
|
-
]}
|
|
113
|
+
options={withIconOptions}
|
|
112
114
|
/>
|
|
113
115
|
</div>
|
|
114
116
|
|
|
@@ -32,10 +32,10 @@ export interface TooltipProps extends HTMLAttributes<HTMLDivElement> {
|
|
|
32
32
|
type ContainerProps = Pick<TooltipProps, 'scheme'>
|
|
33
33
|
|
|
34
34
|
const Container = styled.div<ContainerProps>`
|
|
35
|
-
position: relative;
|
|
36
|
-
|
|
37
35
|
display: inline-block;
|
|
38
36
|
|
|
37
|
+
position: relative;
|
|
38
|
+
|
|
39
39
|
cursor: help;
|
|
40
40
|
|
|
41
41
|
${focusable`
|
|
@@ -49,22 +49,31 @@ const Container = styled.div<ContainerProps>`
|
|
|
49
49
|
type BubbleProps = Pick<TooltipProps, 'position' | 'align'>
|
|
50
50
|
|
|
51
51
|
const Bubble = styled.span<BubbleProps>`
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
${font({
|
|
53
|
+
weight: 'font-weight-medium',
|
|
54
|
+
height: 'font-height-3',
|
|
55
|
+
})}
|
|
56
|
+
|
|
57
|
+
${transition()}
|
|
58
|
+
|
|
59
|
+
white-space: initial;
|
|
54
60
|
|
|
55
|
-
width: max-content;
|
|
56
61
|
min-width: ${token('tooltip-min-width')};
|
|
57
62
|
max-width: ${token('tooltip-max-width')};
|
|
63
|
+
width: max-content;
|
|
64
|
+
|
|
65
|
+
position: absolute;
|
|
66
|
+
z-index: ${token('z-index-tooltip')};
|
|
67
|
+
|
|
68
|
+
background: ${token('tooltip-background')};
|
|
69
|
+
box-shadow: ${token('tooltip-shadow')};
|
|
70
|
+
border-radius: ${token('tooltip-border-radius')};
|
|
58
71
|
|
|
59
72
|
padding: ${token('tooltip-padding-y')} ${token('tooltip-padding-x')};
|
|
60
73
|
|
|
74
|
+
color: ${token('tooltip-color')};
|
|
61
75
|
font-size: ${token('tooltip-font-size')};
|
|
62
76
|
line-height: ${token('tooltip-font-height')};
|
|
63
|
-
color: ${token('tooltip-color')};
|
|
64
|
-
white-space: initial;
|
|
65
|
-
background: ${token('tooltip-background')};
|
|
66
|
-
border-radius: ${token('tooltip-border-radius')};
|
|
67
|
-
box-shadow: ${token('tooltip-shadow')};
|
|
68
77
|
|
|
69
78
|
${({ position }) =>
|
|
70
79
|
position === TooltipPosition.Top &&
|
|
@@ -109,26 +118,19 @@ const Bubble = styled.span<BubbleProps>`
|
|
|
109
118
|
|
|
110
119
|
transform: translate(100%, -50%);
|
|
111
120
|
`};
|
|
112
|
-
|
|
113
|
-
${font({
|
|
114
|
-
weight: 'font-weight-medium',
|
|
115
|
-
height: 'font-height-3',
|
|
116
|
-
})}
|
|
117
|
-
|
|
118
|
-
${transition()}
|
|
119
121
|
`
|
|
120
122
|
|
|
121
123
|
type ArrowProps = Pick<TooltipProps, 'position'>
|
|
122
124
|
const Arrow = styled.span<ArrowProps>`
|
|
123
|
-
position: absolute;
|
|
124
|
-
z-index: 1;
|
|
125
|
-
|
|
126
125
|
width: 0;
|
|
127
126
|
height: 0;
|
|
128
127
|
|
|
129
128
|
background: transparent;
|
|
130
129
|
border-style: solid;
|
|
131
130
|
|
|
131
|
+
position: absolute;
|
|
132
|
+
z-index: 1;
|
|
133
|
+
|
|
132
134
|
${({ position }) =>
|
|
133
135
|
position === TooltipPosition.Top &&
|
|
134
136
|
css`
|
|
@@ -27,8 +27,8 @@ const MenuDropdownTrigger = styled(DropdownTrigger.Handle)`
|
|
|
27
27
|
export const MenuDropdownLabel = styled.label`
|
|
28
28
|
${transition()}
|
|
29
29
|
|
|
30
|
-
display: flex;
|
|
31
30
|
align-items: center;
|
|
31
|
+
display: flex;
|
|
32
32
|
|
|
33
33
|
${typography('body-bold', { color: 'top-navigation-item-color' })}
|
|
34
34
|
|
|
@@ -11,10 +11,10 @@ export type OpenSideNavButtonProps = {
|
|
|
11
11
|
|
|
12
12
|
const Container = styled.button`
|
|
13
13
|
margin-right: ${token('space-2xl')};
|
|
14
|
-
cursor: pointer;
|
|
15
14
|
|
|
16
15
|
background: none;
|
|
17
16
|
border: none;
|
|
17
|
+
cursor: pointer;
|
|
18
18
|
`
|
|
19
19
|
|
|
20
20
|
function OpenSideNavButton({ className, onClick }: OpenSideNavButtonProps): JSX.Element {
|
package/src/styles/font.tsx
CHANGED
|
@@ -26,11 +26,11 @@ function fontStyle({
|
|
|
26
26
|
transform = 'none',
|
|
27
27
|
}: FontStyleOptions): FlattenInterpolation<ThemedProps> {
|
|
28
28
|
return css`
|
|
29
|
-
|
|
30
|
-
font-size: ${getToken(size)};
|
|
29
|
+
color: ${getToken(color)};
|
|
31
30
|
font-weight: ${getToken(weight)};
|
|
31
|
+
font-size: ${getToken(size)};
|
|
32
|
+
font-family: ${getToken(family)};
|
|
32
33
|
line-height: ${getToken(height)};
|
|
33
|
-
color: ${getToken(color)};
|
|
34
34
|
text-transform: ${transform};
|
|
35
35
|
-webkit-font-smoothing: antialiased;
|
|
36
36
|
-moz-osx-font-smoothing: grayscale;
|
|
@@ -1,16 +1,56 @@
|
|
|
1
1
|
/* eslint-disable */
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
fireEvent,
|
|
4
|
+
queries,
|
|
5
|
+
waitFor,
|
|
6
|
+
within,
|
|
7
|
+
waitForElementToBeRemoved,
|
|
8
|
+
} from '@testing-library/dom'
|
|
3
9
|
import { act } from '@testing-library/react'
|
|
4
10
|
import userEvent from '@testing-library/user-event'
|
|
5
11
|
|
|
6
12
|
// based on https://github.com/romgain/react-select-event/blob/master/src/index.ts
|
|
7
13
|
|
|
8
|
-
// find the
|
|
9
|
-
function
|
|
14
|
+
// find the select container from its input field 🤷
|
|
15
|
+
function getSelectContainer(input: HTMLElement): HTMLElement {
|
|
10
16
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
11
17
|
return input.parentNode!.parentNode!.parentNode as HTMLElement
|
|
12
18
|
}
|
|
13
19
|
|
|
20
|
+
/**
|
|
21
|
+
* Please, make sure to call expand before trying to get the menu container
|
|
22
|
+
*/
|
|
23
|
+
function getSelectMenu(input: HTMLElement): HTMLElement {
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
25
|
+
return input.parentNode!.parentNode!.nextSibling as HTMLElement
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function getSelectTriggerHandle(input: HTMLElement): HTMLElement {
|
|
29
|
+
return input.parentNode!.nextSibling!.nextSibling as HTMLElement
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function getSelectSearchContainer(input: HTMLElement): HTMLElement {
|
|
33
|
+
return input.parentNode as HTMLElement
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function isSelectMenuExpanded(input: HTMLElement): boolean {
|
|
37
|
+
const selectContainer = getSelectContainer(input)
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Once the select is expanded, we have the following structure:
|
|
41
|
+
* +-------------+
|
|
42
|
+
* | Close button (visually hiddren)
|
|
43
|
+
* +-------------+
|
|
44
|
+
* | DropdownTrigger
|
|
45
|
+
* +-------------+
|
|
46
|
+
* | Popover
|
|
47
|
+
* +-------------+
|
|
48
|
+
*
|
|
49
|
+
* This, if the container has 3 children, we assume the menu is expanded
|
|
50
|
+
*/
|
|
51
|
+
return selectContainer.children.length == 3
|
|
52
|
+
}
|
|
53
|
+
|
|
14
54
|
/**
|
|
15
55
|
* This is needed because some datasources might be asynchronous.
|
|
16
56
|
* To ensure that the data they retrieve will be available, we wait for the
|
|
@@ -18,15 +58,16 @@ function getReactSelectContainerFromInput(input: HTMLElement): HTMLElement {
|
|
|
18
58
|
* @param {HTMLElement} input - You can refer to this element by the label you applied to the `Select`.
|
|
19
59
|
*/
|
|
20
60
|
async function waitForPendingQuery(input: HTMLElement) {
|
|
21
|
-
const
|
|
61
|
+
const searchContainer = getSelectSearchContainer(input)
|
|
22
62
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
63
|
+
if (!queries.queryByTestId(searchContainer, 'select-trigger-loading')) {
|
|
64
|
+
return
|
|
65
|
+
}
|
|
26
66
|
|
|
27
|
-
await
|
|
28
|
-
|
|
29
|
-
|
|
67
|
+
await waitForElementToBeRemoved(
|
|
68
|
+
() => queries.queryByTestId(searchContainer, 'select-trigger-loading'),
|
|
69
|
+
{ timeout: 2500 }
|
|
70
|
+
)
|
|
30
71
|
}
|
|
31
72
|
|
|
32
73
|
/**
|
|
@@ -35,21 +76,23 @@ async function waitForPendingQuery(input: HTMLElement) {
|
|
|
35
76
|
* @returns {Promise<void>}
|
|
36
77
|
*/
|
|
37
78
|
async function expand(input: HTMLElement): Promise<void> {
|
|
38
|
-
|
|
79
|
+
await waitForPendingQuery(input)
|
|
39
80
|
|
|
40
|
-
|
|
41
|
-
if (queries.queryByRole(selectContainer, 'listbox')) {
|
|
81
|
+
if (isSelectMenuExpanded(input)) {
|
|
42
82
|
return
|
|
43
83
|
}
|
|
44
84
|
|
|
85
|
+
const triggerHandle = getSelectTriggerHandle(input)
|
|
86
|
+
|
|
45
87
|
await waitFor(() => {
|
|
46
|
-
expect(
|
|
88
|
+
expect(triggerHandle).toBeEnabled()
|
|
47
89
|
})
|
|
48
90
|
|
|
49
91
|
await act(async () => {
|
|
50
|
-
userEvent.click(
|
|
51
|
-
|
|
52
|
-
|
|
92
|
+
userEvent.click(triggerHandle)
|
|
93
|
+
await waitFor(() => {
|
|
94
|
+
expect(isSelectMenuExpanded(input)).toBe(true)
|
|
95
|
+
})
|
|
53
96
|
})
|
|
54
97
|
}
|
|
55
98
|
|
|
@@ -59,18 +102,17 @@ async function expand(input: HTMLElement): Promise<void> {
|
|
|
59
102
|
* @returns {Promise<void>}
|
|
60
103
|
*/
|
|
61
104
|
async function collapse(input: HTMLElement): Promise<void> {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
// if listbox is not rendered, then the select is already collapsed
|
|
65
|
-
if (!queries.queryByRole(selectContainer, 'listbox')) {
|
|
105
|
+
if (!isSelectMenuExpanded(input)) {
|
|
66
106
|
return
|
|
67
107
|
}
|
|
68
108
|
|
|
109
|
+
const triggerHandle = getSelectTriggerHandle(input)
|
|
110
|
+
|
|
69
111
|
await act(async () => {
|
|
70
|
-
userEvent.click(
|
|
112
|
+
userEvent.click(triggerHandle)
|
|
71
113
|
|
|
72
114
|
await waitFor(() => {
|
|
73
|
-
expect(
|
|
115
|
+
expect(isSelectMenuExpanded(input)).toBe(false)
|
|
74
116
|
})
|
|
75
117
|
})
|
|
76
118
|
}
|
|
@@ -83,13 +125,12 @@ async function collapse(input: HTMLElement): Promise<void> {
|
|
|
83
125
|
* @returns {Promise<void>}
|
|
84
126
|
*/
|
|
85
127
|
async function select(option: string, input: HTMLElement): Promise<void> {
|
|
86
|
-
const selectContainer = getReactSelectContainerFromInput(input)
|
|
87
|
-
|
|
88
|
-
await waitForPendingQuery(input)
|
|
89
128
|
await expand(input)
|
|
90
129
|
|
|
130
|
+
const menuContainer = getSelectMenu(input)
|
|
131
|
+
|
|
91
132
|
await act(async () => {
|
|
92
|
-
const optionElement = await queries.findByLabelText(
|
|
133
|
+
const optionElement = await queries.findByLabelText(menuContainer, option)
|
|
93
134
|
|
|
94
135
|
// click the option if exists; Select currently closes when an item is clicked.
|
|
95
136
|
if (optionElement && optionElement.getAttribute('aria-selected') == 'false') {
|
|
@@ -109,13 +150,12 @@ async function select(option: string, input: HTMLElement): Promise<void> {
|
|
|
109
150
|
* @returns {Promise<void>}
|
|
110
151
|
*/
|
|
111
152
|
async function unselect(option: string, input: HTMLElement): Promise<void> {
|
|
112
|
-
const selectContainer = getReactSelectContainerFromInput(input)
|
|
113
|
-
|
|
114
|
-
await waitForPendingQuery(input)
|
|
115
153
|
await expand(input)
|
|
116
154
|
|
|
155
|
+
const menuContainer = getSelectMenu(input)
|
|
156
|
+
|
|
117
157
|
await act(async () => {
|
|
118
|
-
const optionElement = await queries.findByLabelText(
|
|
158
|
+
const optionElement = await queries.findByLabelText(menuContainer, option)
|
|
119
159
|
|
|
120
160
|
// ensures that the option exists and IS selected
|
|
121
161
|
if (optionElement && optionElement.getAttribute('aria-selected') == 'true') {
|
|
@@ -133,12 +173,12 @@ async function unselect(option: string, input: HTMLElement): Promise<void> {
|
|
|
133
173
|
* @returns {Promise<void>}
|
|
134
174
|
*/
|
|
135
175
|
async function clear(input: HTMLElement): Promise<void> {
|
|
136
|
-
const selectContainer = getReactSelectContainerFromInput(input)
|
|
137
|
-
|
|
138
176
|
await waitForPendingQuery(input)
|
|
139
177
|
|
|
178
|
+
const searchContainer = getSelectSearchContainer(input)
|
|
179
|
+
|
|
140
180
|
await act(async () => {
|
|
141
|
-
const clearButton = within(
|
|
181
|
+
const clearButton = within(searchContainer).getByTestId('select-trigger-clear')
|
|
142
182
|
|
|
143
183
|
if (clearButton) {
|
|
144
184
|
userEvent.click(clearButton)
|
|
@@ -153,7 +193,7 @@ async function clear(input: HTMLElement): Promise<void> {
|
|
|
153
193
|
* @returns {Promise<void>}
|
|
154
194
|
*/
|
|
155
195
|
async function search(query: string, input: HTMLElement): Promise<void> {
|
|
156
|
-
const selectContainer =
|
|
196
|
+
const selectContainer = getSelectContainer(input)
|
|
157
197
|
|
|
158
198
|
await act(async () => {
|
|
159
199
|
fireEvent.change(input, { target: { value: query } })
|
|
@@ -168,14 +208,14 @@ async function search(query: string, input: HTMLElement): Promise<void> {
|
|
|
168
208
|
* @returns {Promise<HTMLElement[]>}
|
|
169
209
|
*/
|
|
170
210
|
async function getOptions(input: HTMLElement): Promise<HTMLElement[]> {
|
|
171
|
-
const selectContainer = getReactSelectContainerFromInput(input)
|
|
172
|
-
|
|
173
|
-
await waitForPendingQuery(input)
|
|
174
211
|
await expand(input)
|
|
175
|
-
|
|
212
|
+
|
|
213
|
+
const menuContainer = getSelectMenu(input)
|
|
214
|
+
|
|
215
|
+
const options = queries.queryAllByRole(menuContainer, 'option')
|
|
176
216
|
await collapse(input)
|
|
177
217
|
|
|
178
|
-
return
|
|
218
|
+
return options
|
|
179
219
|
}
|
|
180
220
|
|
|
181
221
|
/**
|
|
@@ -184,14 +224,15 @@ async function getOptions(input: HTMLElement): Promise<HTMLElement[]> {
|
|
|
184
224
|
* @returns {Promise<HTMLElement[]>}
|
|
185
225
|
*/
|
|
186
226
|
async function getSelectedOptions(input: HTMLElement): Promise<HTMLElement[]> {
|
|
187
|
-
const selectContainer = getReactSelectContainerFromInput(input)
|
|
188
|
-
let selectedOptions: HTMLElement[] = []
|
|
189
|
-
|
|
190
|
-
await waitForPendingQuery(input)
|
|
191
227
|
await expand(input)
|
|
192
228
|
|
|
229
|
+
const menuContainer = getSelectMenu(input)
|
|
230
|
+
let selectedOptions: HTMLElement[] = []
|
|
231
|
+
|
|
193
232
|
try {
|
|
194
|
-
selectedOptions = await queries.findAllByRole(
|
|
233
|
+
selectedOptions = await queries.findAllByRole(menuContainer, 'option', {
|
|
234
|
+
selected: true,
|
|
235
|
+
})
|
|
195
236
|
} catch (err) {
|
|
196
237
|
selectedOptions = []
|
|
197
238
|
}
|
|
@@ -210,6 +251,7 @@ export const selectEvent = {
|
|
|
210
251
|
collapse,
|
|
211
252
|
getOptions,
|
|
212
253
|
getSelectedOptions,
|
|
254
|
+
isMenuExpanded: isSelectMenuExpanded,
|
|
213
255
|
}
|
|
214
256
|
|
|
215
257
|
export default selectEvent
|