@sproutsocial/racine 11.0.0 → 11.0.1-menustyles.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/__flow__/Listbox/index.test.js +0 -18
- package/__flow__/Menu/__snapshots__/index.test.js.snap +4 -272
- package/__flow__/Menu/index.js +10 -2
- package/__flow__/Menu/index.stories.js +19 -1
- package/__flow__/Menu/index.test.js +0 -4
- package/__flow__/Menu/styles.js +11 -9
- package/commonjs/Menu/index.js +20 -9
- package/commonjs/Menu/styles.js +5 -5
- package/lib/Menu/index.js +20 -9
- package/lib/Menu/styles.js +6 -6
- package/package.json +1 -1
- package/__flow__/Listbox/__snapshots__/index.test.js.snap +0 -1314
|
@@ -165,10 +165,6 @@ describe("Listbox", () => {
|
|
|
165
165
|
});
|
|
166
166
|
|
|
167
167
|
describe("AsListbox", () => {
|
|
168
|
-
it("should match snapshot", () => {
|
|
169
|
-
expect(render(<AsListbox />).baseElement).toMatchSnapshot();
|
|
170
|
-
});
|
|
171
|
-
|
|
172
168
|
it("should render items with option role", async () => {
|
|
173
169
|
const { findByText, queryByLabelText, queryByRole } = render(
|
|
174
170
|
<AsListbox />
|
|
@@ -211,10 +207,6 @@ describe("Listbox", () => {
|
|
|
211
207
|
});
|
|
212
208
|
|
|
213
209
|
describe("AsListbox multiselect", () => {
|
|
214
|
-
it("should match snapshot", () => {
|
|
215
|
-
expect(render(<AsListboxMultiselect />).baseElement).toMatchSnapshot();
|
|
216
|
-
});
|
|
217
|
-
|
|
218
210
|
it("should render items with option role", async () => {
|
|
219
211
|
const { queryByLabelText, queryByText, queryByRole } = render(
|
|
220
212
|
<AsListboxMultiselect />
|
|
@@ -244,10 +236,6 @@ describe("Listbox", () => {
|
|
|
244
236
|
});
|
|
245
237
|
|
|
246
238
|
describe("AsListbox with checkboxes", () => {
|
|
247
|
-
it("should match snapshot", () => {
|
|
248
|
-
expect(render(<AsListboxWithCheckboxes />).baseElement).toMatchSnapshot();
|
|
249
|
-
});
|
|
250
|
-
|
|
251
239
|
it("should render items with checkbox role", async () => {
|
|
252
240
|
const { queryByRole } = render(<AsListboxWithCheckboxes />);
|
|
253
241
|
const firstItem = queryByRole(MENU_ITEM_ROLES.CHECKBOX, {
|
|
@@ -267,12 +255,6 @@ describe("Listbox", () => {
|
|
|
267
255
|
});
|
|
268
256
|
|
|
269
257
|
describe("AsListbox with filter input", () => {
|
|
270
|
-
it("should match snapshot", () => {
|
|
271
|
-
expect(
|
|
272
|
-
render(<AsListboxWithFilterInput />).baseElement
|
|
273
|
-
).toMatchSnapshot();
|
|
274
|
-
});
|
|
275
|
-
|
|
276
258
|
it("should allow filtering", async () => {
|
|
277
259
|
const { queryByLabelText, queryAllByRole } = render(
|
|
278
260
|
<AsListboxWithFilterInput />
|
|
@@ -1,276 +1,7 @@
|
|
|
1
1
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
2
|
|
|
3
|
-
exports[`Menu AsMenu should match snapshot 1`] = `
|
|
4
|
-
.c0 {
|
|
5
|
-
box-sizing: border-box;
|
|
6
|
-
font-family: system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI","Roboto","Oxygen","Ubuntu","Cantarell","Fira Sans","Droid Sans","Helvetica Neue",sans-serif;
|
|
7
|
-
margin: 0px;
|
|
8
|
-
padding: 0px;
|
|
9
|
-
width: 200px;
|
|
10
|
-
overflow: hidden;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
.c2 {
|
|
14
|
-
box-sizing: border-box;
|
|
15
|
-
font-family: system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI","Roboto","Oxygen","Ubuntu","Cantarell","Fira Sans","Droid Sans","Helvetica Neue",sans-serif;
|
|
16
|
-
padding-left: 16px;
|
|
17
|
-
margin-top: -1px;
|
|
18
|
-
border-top: 1px solid;
|
|
19
|
-
border-color: #dee1e1;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
.c4 {
|
|
23
|
-
box-sizing: border-box;
|
|
24
|
-
font-family: system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI","Roboto","Oxygen","Ubuntu","Cantarell","Fira Sans","Droid Sans","Helvetica Neue",sans-serif;
|
|
25
|
-
padding: 8px;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
.c5 {
|
|
29
|
-
box-sizing: border-box;
|
|
30
|
-
font-family: system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI","Roboto","Oxygen","Ubuntu","Cantarell","Fira Sans","Droid Sans","Helvetica Neue",sans-serif;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
.c7 {
|
|
34
|
-
display: block;
|
|
35
|
-
width: 100%;
|
|
36
|
-
border-radius: 6px;
|
|
37
|
-
background-color: transparent;
|
|
38
|
-
border: none;
|
|
39
|
-
text-align: left;
|
|
40
|
-
color: #364141;
|
|
41
|
-
font-family: system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI","Roboto","Oxygen","Ubuntu","Cantarell","Fira Sans","Droid Sans","Helvetica Neue",sans-serif;
|
|
42
|
-
font-weight: 400;
|
|
43
|
-
padding: 6px 8px;
|
|
44
|
-
list-style-type: none;
|
|
45
|
-
outline: 0;
|
|
46
|
-
font-size: 13px;
|
|
47
|
-
line-height: 21.333333333333332px;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
.c7:focus,
|
|
51
|
-
.c7:hover {
|
|
52
|
-
color: #364141;
|
|
53
|
-
background-color: #f3f4f4;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
.c7:focus .Icon-svg,
|
|
57
|
-
.c7:hover .Icon-svg {
|
|
58
|
-
color: unset;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
.c7:hover {
|
|
62
|
-
cursor: pointer;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
.c6 {
|
|
66
|
-
display: block;
|
|
67
|
-
width: 100%;
|
|
68
|
-
border-radius: 6px;
|
|
69
|
-
background-color: transparent;
|
|
70
|
-
border: none;
|
|
71
|
-
text-align: left;
|
|
72
|
-
color: #364141;
|
|
73
|
-
font-family: system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI","Roboto","Oxygen","Ubuntu","Cantarell","Fira Sans","Droid Sans","Helvetica Neue",sans-serif;
|
|
74
|
-
font-weight: 400;
|
|
75
|
-
padding: 6px 8px;
|
|
76
|
-
list-style-type: none;
|
|
77
|
-
outline: 0;
|
|
78
|
-
font-size: 13px;
|
|
79
|
-
line-height: 21.333333333333332px;
|
|
80
|
-
color: #FFFFFF;
|
|
81
|
-
background-color: #364141;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
.c6 .Icon-svg {
|
|
85
|
-
color: #FFFFFF;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
.c6:focus,
|
|
89
|
-
.c6:hover {
|
|
90
|
-
color: #364141;
|
|
91
|
-
background-color: #f3f4f4;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
.c6:focus .Icon-svg,
|
|
95
|
-
.c6:hover .Icon-svg {
|
|
96
|
-
color: unset;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
.c6:hover {
|
|
100
|
-
cursor: pointer;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
.c1 {
|
|
104
|
-
list-style-type: none;
|
|
105
|
-
outline: 0;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
.c3 {
|
|
109
|
-
margin: 0;
|
|
110
|
-
padding-left: 0;
|
|
111
|
-
padding-right: 0;
|
|
112
|
-
font-family: system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI","Roboto","Oxygen","Ubuntu","Cantarell","Fira Sans","Droid Sans","Helvetica Neue",sans-serif;
|
|
113
|
-
margin-top: 12px;
|
|
114
|
-
color: #273333;
|
|
115
|
-
font-size: 13px;
|
|
116
|
-
line-height: 21.333333333333332px;
|
|
117
|
-
font-weight: 600;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
<body>
|
|
121
|
-
<div>
|
|
122
|
-
<ul
|
|
123
|
-
aria-activedescendant="MenuItem-1"
|
|
124
|
-
class="c0 c1"
|
|
125
|
-
overflow="hidden"
|
|
126
|
-
role="menu"
|
|
127
|
-
tabindex="0"
|
|
128
|
-
width="200px"
|
|
129
|
-
>
|
|
130
|
-
<div
|
|
131
|
-
class="c2"
|
|
132
|
-
>
|
|
133
|
-
<div
|
|
134
|
-
class="c3 "
|
|
135
|
-
color="text.headline"
|
|
136
|
-
data-qa-text="Fruit"
|
|
137
|
-
font-weight="600"
|
|
138
|
-
>
|
|
139
|
-
Fruit
|
|
140
|
-
</div>
|
|
141
|
-
</div>
|
|
142
|
-
<div
|
|
143
|
-
class="c4"
|
|
144
|
-
role="group"
|
|
145
|
-
>
|
|
146
|
-
<li
|
|
147
|
-
class="c5 c6"
|
|
148
|
-
data-qa-menu-item="Apple"
|
|
149
|
-
id="MenuItem-1"
|
|
150
|
-
role="menuitem"
|
|
151
|
-
tabindex="-1"
|
|
152
|
-
>
|
|
153
|
-
<div
|
|
154
|
-
style="display: flex; align-items: center; justify-content: space-between;"
|
|
155
|
-
>
|
|
156
|
-
<div
|
|
157
|
-
style="flex-grow: 1; word-break: break-word; min-width: 0;"
|
|
158
|
-
>
|
|
159
|
-
Apple
|
|
160
|
-
</div>
|
|
161
|
-
</div>
|
|
162
|
-
</li>
|
|
163
|
-
<li
|
|
164
|
-
class="c5 c7"
|
|
165
|
-
data-qa-menu-item="Banana"
|
|
166
|
-
id="MenuItem-2"
|
|
167
|
-
role="menuitem"
|
|
168
|
-
tabindex="-1"
|
|
169
|
-
>
|
|
170
|
-
<div
|
|
171
|
-
style="display: flex; align-items: center; justify-content: space-between;"
|
|
172
|
-
>
|
|
173
|
-
<div
|
|
174
|
-
style="flex-grow: 1; word-break: break-word; min-width: 0;"
|
|
175
|
-
>
|
|
176
|
-
Banana
|
|
177
|
-
</div>
|
|
178
|
-
</div>
|
|
179
|
-
</li>
|
|
180
|
-
<li
|
|
181
|
-
class="c5 c7"
|
|
182
|
-
data-qa-menu-item="Orange"
|
|
183
|
-
id="MenuItem-3"
|
|
184
|
-
role="menuitem"
|
|
185
|
-
tabindex="-1"
|
|
186
|
-
>
|
|
187
|
-
<div
|
|
188
|
-
style="display: flex; align-items: center; justify-content: space-between;"
|
|
189
|
-
>
|
|
190
|
-
<div
|
|
191
|
-
style="flex-grow: 1; word-break: break-word; min-width: 0;"
|
|
192
|
-
>
|
|
193
|
-
Orange
|
|
194
|
-
</div>
|
|
195
|
-
</div>
|
|
196
|
-
</li>
|
|
197
|
-
</div>
|
|
198
|
-
<div
|
|
199
|
-
class="c2"
|
|
200
|
-
>
|
|
201
|
-
<div
|
|
202
|
-
class="c3 "
|
|
203
|
-
color="text.headline"
|
|
204
|
-
data-qa-text="Maybe Fruit"
|
|
205
|
-
font-weight="600"
|
|
206
|
-
>
|
|
207
|
-
Maybe Fruit
|
|
208
|
-
</div>
|
|
209
|
-
</div>
|
|
210
|
-
<div
|
|
211
|
-
class="c4"
|
|
212
|
-
role="group"
|
|
213
|
-
>
|
|
214
|
-
<li
|
|
215
|
-
class="c5 c7"
|
|
216
|
-
data-qa-menu-item="Tomato"
|
|
217
|
-
id="MenuItem-4"
|
|
218
|
-
role="menuitem"
|
|
219
|
-
tabindex="-1"
|
|
220
|
-
>
|
|
221
|
-
<div
|
|
222
|
-
style="display: flex; align-items: center; justify-content: space-between;"
|
|
223
|
-
>
|
|
224
|
-
<div
|
|
225
|
-
style="flex-grow: 1; word-break: break-word; min-width: 0;"
|
|
226
|
-
>
|
|
227
|
-
Tomato
|
|
228
|
-
</div>
|
|
229
|
-
</div>
|
|
230
|
-
</li>
|
|
231
|
-
<li
|
|
232
|
-
class="c5 c7"
|
|
233
|
-
data-qa-menu-item="Cucumber"
|
|
234
|
-
id="MenuItem-5"
|
|
235
|
-
role="menuitem"
|
|
236
|
-
tabindex="-1"
|
|
237
|
-
>
|
|
238
|
-
<div
|
|
239
|
-
style="display: flex; align-items: center; justify-content: space-between;"
|
|
240
|
-
>
|
|
241
|
-
<div
|
|
242
|
-
style="flex-grow: 1; word-break: break-word; min-width: 0;"
|
|
243
|
-
>
|
|
244
|
-
Cucumber
|
|
245
|
-
</div>
|
|
246
|
-
</div>
|
|
247
|
-
</li>
|
|
248
|
-
<li
|
|
249
|
-
class="c5 c7"
|
|
250
|
-
data-qa-menu-item="Squash"
|
|
251
|
-
id="MenuItem-6"
|
|
252
|
-
role="menuitem"
|
|
253
|
-
tabindex="-1"
|
|
254
|
-
>
|
|
255
|
-
<div
|
|
256
|
-
style="display: flex; align-items: center; justify-content: space-between;"
|
|
257
|
-
>
|
|
258
|
-
<div
|
|
259
|
-
style="flex-grow: 1; word-break: break-word; min-width: 0;"
|
|
260
|
-
>
|
|
261
|
-
Squash
|
|
262
|
-
</div>
|
|
263
|
-
</div>
|
|
264
|
-
</li>
|
|
265
|
-
</div>
|
|
266
|
-
</ul>
|
|
267
|
-
</div>
|
|
268
|
-
</body>
|
|
269
|
-
`;
|
|
270
|
-
|
|
271
3
|
exports[`Menu AsMenuButton should match snapshot 1`] = `
|
|
272
|
-
|
|
273
|
-
.c3 {
|
|
4
|
+
.c3 {
|
|
274
5
|
display: inline-block;
|
|
275
6
|
color: inherit;
|
|
276
7
|
vertical-align: middle;
|
|
@@ -356,7 +87,8 @@ html .c3 {
|
|
|
356
87
|
display: inline-block;
|
|
357
88
|
}
|
|
358
89
|
|
|
359
|
-
<
|
|
90
|
+
<body>
|
|
91
|
+
<div>
|
|
360
92
|
<div
|
|
361
93
|
class="c0"
|
|
362
94
|
>
|
|
@@ -367,7 +99,7 @@ html .c3 {
|
|
|
367
99
|
class="c1"
|
|
368
100
|
data-qa-button=""
|
|
369
101
|
data-qa-button-isdisabled="false"
|
|
370
|
-
id="MenuButton-
|
|
102
|
+
id="MenuButton-7"
|
|
371
103
|
type="button"
|
|
372
104
|
>
|
|
373
105
|
<span
|
package/__flow__/Menu/index.js
CHANGED
|
@@ -85,7 +85,6 @@ export const MenuItem = ({
|
|
|
85
85
|
selected,
|
|
86
86
|
disabled,
|
|
87
87
|
indeterminate,
|
|
88
|
-
active,
|
|
89
88
|
label: labelProp,
|
|
90
89
|
...props
|
|
91
90
|
}: TypeMenuItemProps) => {
|
|
@@ -121,6 +120,7 @@ export const MenuItem = ({
|
|
|
121
120
|
const isHidden = filteredItems && !filteredItems.includes(index);
|
|
122
121
|
const isFocused = index === selectionIndex;
|
|
123
122
|
selectCallbacks.current[index] = onClick;
|
|
123
|
+
const [keyPressed, setKeyPressed] = useState(false);
|
|
124
124
|
|
|
125
125
|
const isCheckboxOrRadio = [
|
|
126
126
|
MENU_ITEM_ROLES.CHECKBOX,
|
|
@@ -150,6 +150,14 @@ export const MenuItem = ({
|
|
|
150
150
|
}
|
|
151
151
|
}, [ref, isCheckboxOrRadio]);
|
|
152
152
|
|
|
153
|
+
useEffect(() => {
|
|
154
|
+
if (filteredItems) {
|
|
155
|
+
setKeyPressed(true);
|
|
156
|
+
} else if (selectionIndex !== 0) {
|
|
157
|
+
setKeyPressed(true);
|
|
158
|
+
}
|
|
159
|
+
}, [selectionIndex, filteredItems]);
|
|
160
|
+
|
|
153
161
|
const handleClick = useCallback(
|
|
154
162
|
(e: SyntheticEvent<HTMLButtonElement>) => {
|
|
155
163
|
menuRef.current?.focus();
|
|
@@ -210,7 +218,7 @@ export const MenuItem = ({
|
|
|
210
218
|
<MenuItemContainer
|
|
211
219
|
data-qa-menu-item={label}
|
|
212
220
|
{...props}
|
|
213
|
-
active={
|
|
221
|
+
active={isFocused && keyPressed}
|
|
214
222
|
id={id}
|
|
215
223
|
aria-label={labelProp}
|
|
216
224
|
value={valueProp}
|
|
@@ -7,7 +7,7 @@ import { names } from "./names";
|
|
|
7
7
|
import Text from "../Text";
|
|
8
8
|
import Box from "../Box";
|
|
9
9
|
|
|
10
|
-
const fruit = ["Apple", "Banana", "Orange"];
|
|
10
|
+
const fruit = ["Apple", "Banana", "Blueberry", "Orange"];
|
|
11
11
|
const maybeFruit = ["Tomato", "Cucumber", "Squash"];
|
|
12
12
|
|
|
13
13
|
export default {
|
|
@@ -233,3 +233,21 @@ export const MenuWithIcons = (props) => {
|
|
|
233
233
|
</Box>
|
|
234
234
|
);
|
|
235
235
|
};
|
|
236
|
+
|
|
237
|
+
export const MenuWithFilter = (props) => {
|
|
238
|
+
return (
|
|
239
|
+
<Box
|
|
240
|
+
width="200px"
|
|
241
|
+
border={500}
|
|
242
|
+
borderRadius="outer"
|
|
243
|
+
borderColor="container.border.base"
|
|
244
|
+
boxShadow="medium"
|
|
245
|
+
backgroundColor="container.background.base"
|
|
246
|
+
>
|
|
247
|
+
<Menu {...props}>
|
|
248
|
+
<Menu.FilterInput placeholder="filter contents..." m={300} />
|
|
249
|
+
<BaseContents />
|
|
250
|
+
</Menu>
|
|
251
|
+
</Box>
|
|
252
|
+
);
|
|
253
|
+
};
|
|
@@ -54,10 +54,6 @@ describe("Menu", () => {
|
|
|
54
54
|
});
|
|
55
55
|
|
|
56
56
|
describe("AsMenu", () => {
|
|
57
|
-
it("should match snapshot", () => {
|
|
58
|
-
expect(render(<AsMenu />).baseElement).toMatchSnapshot();
|
|
59
|
-
});
|
|
60
|
-
|
|
61
57
|
it("should render items with menuitem role", () => {
|
|
62
58
|
const { queryByRole, queryByDataQaLabel } = render(<AsMenu />);
|
|
63
59
|
const firstItem = queryByRole(MENU_ITEM_ROLES.MENUITEM, {
|
package/__flow__/Menu/styles.js
CHANGED
|
@@ -3,7 +3,7 @@ import styled, { css } from "styled-components";
|
|
|
3
3
|
import Box from "../Box";
|
|
4
4
|
import type { TypeMenuItemProps } from "./index.flow";
|
|
5
5
|
import type { TypeTheme } from "../types/theme.flow";
|
|
6
|
-
import { disabled } from "../utils/mixins";
|
|
6
|
+
import { disabled, focusRing } from "../utils/mixins";
|
|
7
7
|
|
|
8
8
|
export const MenuItemContainer = styled<
|
|
9
9
|
typeof Box,
|
|
@@ -35,6 +35,13 @@ export const MenuItemContainer = styled<
|
|
|
35
35
|
${props.theme.typography[200]};
|
|
36
36
|
`};
|
|
37
37
|
|
|
38
|
+
${(props) =>
|
|
39
|
+
props.selected &&
|
|
40
|
+
!props.isCheckboxOrRadio &&
|
|
41
|
+
css`
|
|
42
|
+
font-weight: ${(props) => props.theme.fontWeights.semibold};
|
|
43
|
+
`}
|
|
44
|
+
|
|
38
45
|
${(props) =>
|
|
39
46
|
props.active &&
|
|
40
47
|
!props.disabled &&
|
|
@@ -48,13 +55,6 @@ export const MenuItemContainer = styled<
|
|
|
48
55
|
`}
|
|
49
56
|
|
|
50
57
|
${(props) =>
|
|
51
|
-
props.selected &&
|
|
52
|
-
!props.isCheckboxOrRadio &&
|
|
53
|
-
css`
|
|
54
|
-
font-weight: ${(props) => props.theme.fontWeights.semibold};
|
|
55
|
-
`}
|
|
56
|
-
|
|
57
|
-
${(props) =>
|
|
58
58
|
!props.disabled &&
|
|
59
59
|
css`
|
|
60
60
|
&:focus,
|
|
@@ -86,5 +86,7 @@ export const MenuItemContainer = styled<
|
|
|
86
86
|
|
|
87
87
|
export const MenuItemsContainer = styled<typeof Box, TypeTheme>(Box)`
|
|
88
88
|
list-style-type: none;
|
|
89
|
-
|
|
89
|
+
&:focus {
|
|
90
|
+
${focusRing}
|
|
91
|
+
}
|
|
90
92
|
`;
|
package/commonjs/Menu/index.js
CHANGED
|
@@ -91,9 +91,8 @@ var MenuItem = function MenuItem(_ref) {
|
|
|
91
91
|
selected = _ref.selected,
|
|
92
92
|
disabled = _ref.disabled,
|
|
93
93
|
indeterminate = _ref.indeterminate,
|
|
94
|
-
active = _ref.active,
|
|
95
94
|
labelProp = _ref.label,
|
|
96
|
-
props = _objectWithoutPropertiesLoose(_ref, ["id", "index", "as", "children", "role", "elemBefore", "elemAfter", "value", "onKeyPress", "onClick", "selected", "disabled", "indeterminate", "
|
|
95
|
+
props = _objectWithoutPropertiesLoose(_ref, ["id", "index", "as", "children", "role", "elemBefore", "elemAfter", "value", "onKeyPress", "onClick", "selected", "disabled", "indeterminate", "label"]);
|
|
97
96
|
|
|
98
97
|
var _useContext = (0, React.useContext)(_hooks2.MenuContext),
|
|
99
98
|
menuRole = _useContext.role,
|
|
@@ -131,6 +130,11 @@ var MenuItem = function MenuItem(_ref) {
|
|
|
131
130
|
var isHidden = filteredItems && !filteredItems.includes(index);
|
|
132
131
|
var isFocused = index === selectionIndex;
|
|
133
132
|
selectCallbacks.current[index] = onClick;
|
|
133
|
+
|
|
134
|
+
var _useState = (0, React.useState)(false),
|
|
135
|
+
keyPressed = _useState[0],
|
|
136
|
+
setKeyPressed = _useState[1];
|
|
137
|
+
|
|
134
138
|
var isCheckboxOrRadio = [_constants.MENU_ITEM_ROLES.CHECKBOX, _constants.MENU_ITEM_ROLES.RADIO].includes(itemRole);
|
|
135
139
|
var interactive = onClick || onKeyPress || [_constants.MENU_ITEM_ROLES.OPTION, _constants.MENU_ITEM_ROLES.MENUITEM, _constants.MENU_ITEM_ROLES.CHECKBOX, _constants.MENU_ITEM_ROLES.RADIO].includes(itemRole);
|
|
136
140
|
/**
|
|
@@ -148,6 +152,13 @@ var MenuItem = function MenuItem(_ref) {
|
|
|
148
152
|
}
|
|
149
153
|
}
|
|
150
154
|
}, [ref, isCheckboxOrRadio]);
|
|
155
|
+
(0, React.useEffect)(function () {
|
|
156
|
+
if (filteredItems) {
|
|
157
|
+
setKeyPressed(true);
|
|
158
|
+
} else if (selectionIndex !== 0) {
|
|
159
|
+
setKeyPressed(true);
|
|
160
|
+
}
|
|
161
|
+
}, [selectionIndex, filteredItems]);
|
|
151
162
|
var handleClick = (0, React.useCallback)(function (e) {
|
|
152
163
|
var _menuRef$current;
|
|
153
164
|
|
|
@@ -198,7 +209,7 @@ var MenuItem = function MenuItem(_ref) {
|
|
|
198
209
|
return /*#__PURE__*/React.createElement(_styles.MenuItemContainer, _extends({
|
|
199
210
|
"data-qa-menu-item": label
|
|
200
211
|
}, props, {
|
|
201
|
-
active:
|
|
212
|
+
active: isFocused && keyPressed,
|
|
202
213
|
id: id,
|
|
203
214
|
"aria-label": labelProp,
|
|
204
215
|
value: valueProp,
|
|
@@ -370,14 +381,14 @@ var Menu = function Menu(_ref4) {
|
|
|
370
381
|
descendants = _useDescendants[0],
|
|
371
382
|
setDescendants = _useDescendants[1];
|
|
372
383
|
|
|
373
|
-
var
|
|
384
|
+
var _useState2 = (0, React.useState)({
|
|
374
385
|
selectionIndex: 0,
|
|
375
386
|
filterQuery: "",
|
|
376
387
|
filteredItems: null,
|
|
377
388
|
isFilterInputFocused: false
|
|
378
389
|
}),
|
|
379
|
-
state =
|
|
380
|
-
setState =
|
|
390
|
+
state = _useState2[0],
|
|
391
|
+
setState = _useState2[1];
|
|
381
392
|
|
|
382
393
|
var selectCallbacks = (0, React.useRef)([]);
|
|
383
394
|
var menuRef = (0, React.useRef)(null);
|
|
@@ -436,9 +447,9 @@ var MenuButton = function MenuButton(_ref5) {
|
|
|
436
447
|
placement = _ref5$placement === void 0 ? "bottom" : _ref5$placement,
|
|
437
448
|
props = _objectWithoutPropertiesLoose(_ref5, ["content", "popoutProps", "children", "onClick", "closeOnItemClick", "id", "placement"]);
|
|
438
449
|
|
|
439
|
-
var
|
|
440
|
-
isOpen =
|
|
441
|
-
setIsOpen =
|
|
450
|
+
var _useState3 = (0, React.useState)(false),
|
|
451
|
+
isOpen = _useState3[0],
|
|
452
|
+
setIsOpen = _useState3[1];
|
|
442
453
|
|
|
443
454
|
var closePopout = (0, React.useCallback)(function () {
|
|
444
455
|
return setIsOpen(false);
|
package/commonjs/Menu/styles.js
CHANGED
|
@@ -34,16 +34,16 @@ var MenuItemContainer = (0, _styledComponents.default)(_Box.default).withConfig(
|
|
|
34
34
|
return "6px " + props.theme.space[300];
|
|
35
35
|
}, function (props) {
|
|
36
36
|
return (0, _styledComponents.css)(["", ";"], props.theme.typography[200]);
|
|
37
|
+
}, function (props) {
|
|
38
|
+
return props.selected && !props.isCheckboxOrRadio && (0, _styledComponents.css)(["font-weight:", ";"], function (props) {
|
|
39
|
+
return props.theme.fontWeights.semibold;
|
|
40
|
+
});
|
|
37
41
|
}, function (props) {
|
|
38
42
|
return props.active && !props.disabled && (0, _styledComponents.css)(["color:", ";background-color:", ";.Icon-svg{color:", ";}"], function (props) {
|
|
39
43
|
return props.theme.colors.text.inverse;
|
|
40
44
|
}, props.theme.colors.listItem.background.selected, function (props) {
|
|
41
45
|
return props.theme.colors.text.inverse;
|
|
42
46
|
});
|
|
43
|
-
}, function (props) {
|
|
44
|
-
return props.selected && !props.isCheckboxOrRadio && (0, _styledComponents.css)(["font-weight:", ";"], function (props) {
|
|
45
|
-
return props.theme.fontWeights.semibold;
|
|
46
|
-
});
|
|
47
47
|
}, function (props) {
|
|
48
48
|
return !props.disabled && (0, _styledComponents.css)(["&:focus,&:hover{color:", ";background-color:", ";.Icon-svg{color:unset;}}"], function (props) {
|
|
49
49
|
return props.theme.colors.text.body;
|
|
@@ -59,5 +59,5 @@ exports.MenuItemContainer = MenuItemContainer;
|
|
|
59
59
|
var MenuItemsContainer = (0, _styledComponents.default)(_Box.default).withConfig({
|
|
60
60
|
displayName: "styles__MenuItemsContainer",
|
|
61
61
|
componentId: "fjvae4-1"
|
|
62
|
-
})(["list-style-type:none
|
|
62
|
+
})(["list-style-type:none;&:focus{", "}"], _mixins.focusRing);
|
|
63
63
|
exports.MenuItemsContainer = MenuItemsContainer;
|
package/lib/Menu/index.js
CHANGED
|
@@ -66,9 +66,8 @@ export var MenuItem = function MenuItem(_ref) {
|
|
|
66
66
|
selected = _ref.selected,
|
|
67
67
|
disabled = _ref.disabled,
|
|
68
68
|
indeterminate = _ref.indeterminate,
|
|
69
|
-
active = _ref.active,
|
|
70
69
|
labelProp = _ref.label,
|
|
71
|
-
props = _objectWithoutPropertiesLoose(_ref, ["id", "index", "as", "children", "role", "elemBefore", "elemAfter", "value", "onKeyPress", "onClick", "selected", "disabled", "indeterminate", "
|
|
70
|
+
props = _objectWithoutPropertiesLoose(_ref, ["id", "index", "as", "children", "role", "elemBefore", "elemAfter", "value", "onKeyPress", "onClick", "selected", "disabled", "indeterminate", "label"]);
|
|
72
71
|
|
|
73
72
|
var _useContext = useContext(MenuContext),
|
|
74
73
|
menuRole = _useContext.role,
|
|
@@ -106,6 +105,11 @@ export var MenuItem = function MenuItem(_ref) {
|
|
|
106
105
|
var isHidden = filteredItems && !filteredItems.includes(index);
|
|
107
106
|
var isFocused = index === selectionIndex;
|
|
108
107
|
selectCallbacks.current[index] = onClick;
|
|
108
|
+
|
|
109
|
+
var _useState = useState(false),
|
|
110
|
+
keyPressed = _useState[0],
|
|
111
|
+
setKeyPressed = _useState[1];
|
|
112
|
+
|
|
109
113
|
var isCheckboxOrRadio = [MENU_ITEM_ROLES.CHECKBOX, MENU_ITEM_ROLES.RADIO].includes(itemRole);
|
|
110
114
|
var interactive = onClick || onKeyPress || [MENU_ITEM_ROLES.OPTION, MENU_ITEM_ROLES.MENUITEM, MENU_ITEM_ROLES.CHECKBOX, MENU_ITEM_ROLES.RADIO].includes(itemRole);
|
|
111
115
|
/**
|
|
@@ -123,6 +127,13 @@ export var MenuItem = function MenuItem(_ref) {
|
|
|
123
127
|
}
|
|
124
128
|
}
|
|
125
129
|
}, [ref, isCheckboxOrRadio]);
|
|
130
|
+
useEffect(function () {
|
|
131
|
+
if (filteredItems) {
|
|
132
|
+
setKeyPressed(true);
|
|
133
|
+
} else if (selectionIndex !== 0) {
|
|
134
|
+
setKeyPressed(true);
|
|
135
|
+
}
|
|
136
|
+
}, [selectionIndex, filteredItems]);
|
|
126
137
|
var handleClick = useCallback(function (e) {
|
|
127
138
|
var _menuRef$current;
|
|
128
139
|
|
|
@@ -173,7 +184,7 @@ export var MenuItem = function MenuItem(_ref) {
|
|
|
173
184
|
return /*#__PURE__*/React.createElement(MenuItemContainer, _extends({
|
|
174
185
|
"data-qa-menu-item": label
|
|
175
186
|
}, props, {
|
|
176
|
-
active:
|
|
187
|
+
active: isFocused && keyPressed,
|
|
177
188
|
id: id,
|
|
178
189
|
"aria-label": labelProp,
|
|
179
190
|
value: valueProp,
|
|
@@ -332,14 +343,14 @@ export var Menu = function Menu(_ref4) {
|
|
|
332
343
|
descendants = _useDescendants[0],
|
|
333
344
|
setDescendants = _useDescendants[1];
|
|
334
345
|
|
|
335
|
-
var
|
|
346
|
+
var _useState2 = useState({
|
|
336
347
|
selectionIndex: 0,
|
|
337
348
|
filterQuery: "",
|
|
338
349
|
filteredItems: null,
|
|
339
350
|
isFilterInputFocused: false
|
|
340
351
|
}),
|
|
341
|
-
state =
|
|
342
|
-
setState =
|
|
352
|
+
state = _useState2[0],
|
|
353
|
+
setState = _useState2[1];
|
|
343
354
|
|
|
344
355
|
var selectCallbacks = useRef([]);
|
|
345
356
|
var menuRef = useRef(null);
|
|
@@ -395,9 +406,9 @@ export var MenuButton = function MenuButton(_ref5) {
|
|
|
395
406
|
placement = _ref5$placement === void 0 ? "bottom" : _ref5$placement,
|
|
396
407
|
props = _objectWithoutPropertiesLoose(_ref5, ["content", "popoutProps", "children", "onClick", "closeOnItemClick", "id", "placement"]);
|
|
397
408
|
|
|
398
|
-
var
|
|
399
|
-
isOpen =
|
|
400
|
-
setIsOpen =
|
|
409
|
+
var _useState3 = useState(false),
|
|
410
|
+
isOpen = _useState3[0],
|
|
411
|
+
setIsOpen = _useState3[1];
|
|
401
412
|
|
|
402
413
|
var closePopout = useCallback(function () {
|
|
403
414
|
return setIsOpen(false);
|
package/lib/Menu/styles.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import styled, { css } from "styled-components";
|
|
2
2
|
import Box from "../Box";
|
|
3
|
-
import { disabled } from "../utils/mixins";
|
|
3
|
+
import { disabled, focusRing } from "../utils/mixins";
|
|
4
4
|
export var MenuItemContainer = styled(Box).withConfig({
|
|
5
5
|
displayName: "styles__MenuItemContainer",
|
|
6
6
|
componentId: "fjvae4-0"
|
|
@@ -20,16 +20,16 @@ export var MenuItemContainer = styled(Box).withConfig({
|
|
|
20
20
|
return "6px " + props.theme.space[300];
|
|
21
21
|
}, function (props) {
|
|
22
22
|
return css(["", ";"], props.theme.typography[200]);
|
|
23
|
+
}, function (props) {
|
|
24
|
+
return props.selected && !props.isCheckboxOrRadio && css(["font-weight:", ";"], function (props) {
|
|
25
|
+
return props.theme.fontWeights.semibold;
|
|
26
|
+
});
|
|
23
27
|
}, function (props) {
|
|
24
28
|
return props.active && !props.disabled && css(["color:", ";background-color:", ";.Icon-svg{color:", ";}"], function (props) {
|
|
25
29
|
return props.theme.colors.text.inverse;
|
|
26
30
|
}, props.theme.colors.listItem.background.selected, function (props) {
|
|
27
31
|
return props.theme.colors.text.inverse;
|
|
28
32
|
});
|
|
29
|
-
}, function (props) {
|
|
30
|
-
return props.selected && !props.isCheckboxOrRadio && css(["font-weight:", ";"], function (props) {
|
|
31
|
-
return props.theme.fontWeights.semibold;
|
|
32
|
-
});
|
|
33
33
|
}, function (props) {
|
|
34
34
|
return !props.disabled && css(["&:focus,&:hover{color:", ";background-color:", ";.Icon-svg{color:unset;}}"], function (props) {
|
|
35
35
|
return props.theme.colors.text.body;
|
|
@@ -44,4 +44,4 @@ export var MenuItemContainer = styled(Box).withConfig({
|
|
|
44
44
|
export var MenuItemsContainer = styled(Box).withConfig({
|
|
45
45
|
displayName: "styles__MenuItemsContainer",
|
|
46
46
|
componentId: "fjvae4-1"
|
|
47
|
-
})(["list-style-type:none
|
|
47
|
+
})(["list-style-type:none;&:focus{", "}"], focusRing);
|