Skip to content

Commit 6a0e598

Browse files
committed
created a wrapper to allow the nav item with its secondary actions to highlight uniformly
1 parent 23665df commit 6a0e598

File tree

4 files changed

+63
-51
lines changed

4 files changed

+63
-51
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: 34 additions & 28 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
}
@@ -203,9 +177,42 @@ $disabled-fade: 0.6;
203177
}
204178

205179
.ItemWrapper {
180+
width: 100%;
181+
padding: 0 var(--p-space-2);
182+
}
183+
184+
.ItemInnerWrapper {
206185
display: flex;
207186
flex-wrap: nowrap;
208187
width: 100%;
188+
189+
&:hover {
190+
background: var(--p-background-hovered);
191+
color: var(--p-text);
192+
text-decoration: none;
193+
}
194+
}
195+
196+
.ItemInnerWrapper-Selected {
197+
background-color: var(--p-background-selected);
198+
@include focus-ring;
199+
200+
&:hover,
201+
&.keyFocused {
202+
background-color: var(--p-background-hovered);
203+
color: var(--p-text-primary-hovered);
204+
}
205+
206+
.keyFocused {
207+
@include focus-ring($style: 'focused');
208+
}
209+
210+
&:active,
211+
&:active:hover {
212+
@include no-focus-ring;
213+
color: var(--p-text-primary);
214+
background-color: var(--p-background-pressed);
215+
}
209216
}
210217

211218
.Text {
@@ -238,8 +245,7 @@ $disabled-fade: 0.6;
238245
display: flex;
239246
align-items: center;
240247
height: nav(mobile-height);
241-
padding: var(--p-space-1) var(--p-space-4);
242-
margin-right: var(--p-space-1);
248+
padding: var(--p-space-1) var(--p-space-3) var(--p-space-1) var(--p-space-4);
243249
border-radius: var(--p-border-radius-1);
244250

245251
@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 && canBeActive && 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)