Skip to content

Commit a8e0d8b

Browse files
committed
created a wrapper to allow the nav item with its secondary actions to highlight uniformly
1 parent ed3da74 commit a8e0d8b

File tree

4 files changed

+62
-50
lines changed

4 files changed

+62
-50
lines changed

.changeset/yellow-pillows-visit.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@shopify/polaris': patch
3+
---
4+
5+
Extending highlighting for the Navigation Item to full width to cover secondary actions

polaris-react/src/components/Navigation/Navigation.scss

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -92,18 +92,11 @@ $disabled-fade: 0.6;
9292
.Item {
9393
@include nav-item-attributes;
9494
position: relative;
95-
96-
margin-inline-start: var(--p-space-2);
97-
98-
&:last-child {
99-
margin-inline-end: var(--p-space-2);
100-
}
10195
}
10296

10397
.Item-selected {
10498
font-weight: var(--p-font-weight-semibold);
10599
color: var(--p-text-primary);
106-
background-color: var(--p-background-selected);
107100
outline: var(--p-border-width-1) solid transparent;
108101

109102
&::before {
@@ -118,25 +111,6 @@ $disabled-fade: 0.6;
118111
border-bottom-right-radius: var(--p-border-radius-1);
119112
}
120113

121-
@include focus-ring;
122-
123-
&:hover,
124-
&.keyFocused {
125-
background-color: var(--p-background-hovered);
126-
color: var(--p-text-primary-hovered);
127-
}
128-
129-
.keyFocused {
130-
@include focus-ring($style: 'focused');
131-
}
132-
133-
&:active,
134-
&:active:hover {
135-
@include no-focus-ring;
136-
color: var(--p-text-primary);
137-
background-color: var(--p-background-pressed);
138-
}
139-
140114
@media #{$p-breakpoints-md-up} {
141115
font-weight: var(--p-font-weight-medium);
142116
}
@@ -198,9 +172,42 @@ $disabled-fade: 0.6;
198172
}
199173

200174
.ItemWrapper {
175+
width: 100%;
176+
padding: 0 var(--p-space-2);
177+
}
178+
179+
.ItemInnerWrapper {
201180
display: flex;
202181
flex-wrap: nowrap;
203182
width: 100%;
183+
184+
&:hover {
185+
background: var(--p-background-hovered);
186+
color: var(--p-text);
187+
text-decoration: none;
188+
}
189+
}
190+
191+
.ItemInnerWrapper-Selected {
192+
background-color: var(--p-background-selected);
193+
@include focus-ring;
194+
195+
&:hover,
196+
&.keyFocused {
197+
background-color: var(--p-background-hovered);
198+
color: var(--p-text-primary-hovered);
199+
}
200+
201+
.keyFocused {
202+
@include focus-ring($style: 'focused');
203+
}
204+
205+
&:active,
206+
&:active:hover {
207+
@include no-focus-ring;
208+
color: var(--p-text-primary);
209+
background-color: var(--p-background-pressed);
210+
}
204211
}
205212

206213
.Text {
@@ -234,7 +241,6 @@ $disabled-fade: 0.6;
234241
align-items: center;
235242
height: nav(mobile-height);
236243
padding: var(--p-space-1) var(--p-space-4);
237-
margin-right: var(--p-space-1);
238244
border-radius: var(--p-border-radius-1);
239245

240246
@media #{$p-breakpoints-md-up} {

polaris-react/src/components/Navigation/_variables.scss

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,6 @@ $nav-animation-variables: (
3434
text-decoration: none;
3535
text-align: left;
3636

37-
&:hover {
38-
background: var(--p-background-hovered);
39-
color: var(--p-text);
40-
text-decoration: none;
41-
}
42-
4337
@include focus-ring;
4438

4539
&.keyFocused {

polaris-react/src/components/Navigation/components/Item/Item.tsx

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -315,25 +315,32 @@ export function Item({
315315
return (
316316
<li className={className}>
317317
<div className={styles.ItemWrapper}>
318-
<UnstyledLink
319-
url={url}
320-
className={itemClassName}
321-
external={external}
322-
tabIndex={tabIndex}
323-
aria-disabled={disabled}
324-
aria-label={accessibilityLabel}
325-
onClick={getClickHandler(onClick)}
326-
onKeyUp={handleKeyUp}
327-
onBlur={handleBlur}
328-
{...normalizeAriaAttributes(
329-
secondaryNavigationId,
330-
subNavigationItems.length > 0,
331-
showExpanded,
318+
<div
319+
className={classNames(
320+
styles.ItemInnerWrapper,
321+
selected && styles['ItemInnerWrapper-Selected'],
332322
)}
333323
>
334-
{itemContentMarkup}
335-
</UnstyledLink>
336-
{secondaryActionMarkup}
324+
<UnstyledLink
325+
url={url}
326+
className={itemClassName}
327+
external={external}
328+
tabIndex={tabIndex}
329+
aria-disabled={disabled}
330+
aria-label={accessibilityLabel}
331+
onClick={getClickHandler(onClick)}
332+
onKeyUp={handleKeyUp}
333+
onBlur={handleBlur}
334+
{...normalizeAriaAttributes(
335+
secondaryNavigationId,
336+
subNavigationItems.length > 0,
337+
showExpanded,
338+
)}
339+
>
340+
{itemContentMarkup}
341+
</UnstyledLink>
342+
{secondaryActionMarkup}
343+
</div>
337344
</div>
338345
{secondaryNavigationMarkup}
339346
</li>

0 commit comments

Comments
 (0)