Commit e1398f1 1 parent 6fd2bd5 commit e1398f1 Copy full SHA for e1398f1
File tree 2 files changed +19
-4
lines changed
2 files changed +19
-4
lines changed Original file line number Diff line number Diff line change @@ -93,6 +93,10 @@ export interface DropdownMenuProps {
93
93
* Allows custom styling
94
94
*/
95
95
className ?: string ;
96
+ /**
97
+ * Human-readable selector used for writing tests
98
+ */
99
+ "data-cy" ?: string ;
96
100
}
97
101
98
102
const defaultItemToString = (
@@ -116,7 +120,8 @@ const DropdownMenu = (props: DropdownMenuProps) => {
116
120
Direction . TopCenter ,
117
121
Direction . TopLeft
118
122
] ,
119
- trigger
123
+ trigger,
124
+ "data-cy" : dataCy = "dropdownmenu"
120
125
} = props ;
121
126
122
127
const handleSelection = (
@@ -172,6 +177,7 @@ const DropdownMenu = (props: DropdownMenuProps) => {
172
177
footer = { footer }
173
178
key = { `dropdown-${ sectionIndex } ` }
174
179
sectionIndex = { sectionIndex }
180
+ data-cy = { `${ dataCy } -section-${ sectionIndex } ` }
175
181
>
176
182
{ childrenWithKeys }
177
183
</ SectionWrapper >
@@ -204,6 +210,7 @@ const DropdownMenu = (props: DropdownMenuProps) => {
204
210
< PopoverBox
205
211
maxHeight = { menuMaxHeight }
206
212
maxWidth = { menuMaxWidth }
213
+ data-cy = { dataCy }
207
214
{ ...getMenuProps (
208
215
{ refKey : "menuRef" } ,
209
216
// The menu is not mounted when `isOpen` is false, so Downshift's ref check fails incorrectly
@@ -223,7 +230,11 @@ const DropdownMenu = (props: DropdownMenuProps) => {
223
230
} )
224
231
} )
225
232
) : (
226
- < button { ...getToggleButtonProps ( ) } className = { buttonReset } >
233
+ < button
234
+ { ...getToggleButtonProps ( ) }
235
+ className = { buttonReset }
236
+ data-cy = { `${ dataCy } -button` }
237
+ >
227
238
{ trigger }
228
239
</ button >
229
240
) }
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ exports[`Dropdown renders a closed dropdown 1`] = `
15
15
aria-haspopup = " true"
16
16
aria-label = " open menu"
17
17
class = " css-1m1ecn3"
18
+ data-cy = " dropdownmenu-button"
18
19
data-toggle = " true"
19
20
role = " button"
20
21
type = " button"
@@ -42,6 +43,7 @@ exports[`Dropdown renders a dropdown with a max height 1`] = `
42
43
aria-haspopup = " true"
43
44
aria-label = " open menu"
44
45
class = " css-1m1ecn3"
46
+ data-cy = " dropdownmenu-button"
45
47
data-toggle = " true"
46
48
role = " button"
47
49
type = " button"
@@ -70,6 +72,7 @@ exports[`Dropdown renders an open dropdown 1`] = `
70
72
aria-haspopup = " true"
71
73
aria-label = " close menu"
72
74
class = " css-1m1ecn3"
75
+ data-cy = " dropdownmenu-button"
73
76
data-toggle = " true"
74
77
role = " button"
75
78
type = " button"
@@ -87,7 +90,7 @@ exports[`Dropdown renders an open dropdown 1`] = `
87
90
<div
88
91
aria-labelledby = " downshift-1-label"
89
92
class = " css-1slvl4g"
90
- data-cy = " popover "
93
+ data-cy = " dropdownmenu "
91
94
id = " downshift-1-menu"
92
95
role = " listbox"
93
96
>
@@ -153,6 +156,7 @@ exports[`Dropdown renders an open dropdown with multiple sections 1`] = `
153
156
aria-haspopup = " true"
154
157
aria-label = " close menu"
155
158
class = " css-1m1ecn3"
159
+ data-cy = " dropdownmenu-button"
156
160
data-toggle = " true"
157
161
role = " button"
158
162
type = " button"
@@ -170,7 +174,7 @@ exports[`Dropdown renders an open dropdown with multiple sections 1`] = `
170
174
<div
171
175
aria-labelledby = " downshift-3-label"
172
176
class = " css-1slvl4g"
173
- data-cy = " popover "
177
+ data-cy = " dropdownmenu "
174
178
id = " downshift-3-menu"
175
179
role = " listbox"
176
180
>
You can’t perform that action at this time.
0 commit comments