Skip to content

Commit a400750

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

File tree

4 files changed

+56
-44
lines changed

4 files changed

+56
-44
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: 27 additions & 21 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,18 +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-
133114
&:active,
134115
&:active:hover {
135116
@include no-focus-ring;
@@ -203,9 +184,35 @@ $disabled-fade: 0.6;
203184
}
204185

205186
.ItemWrapper {
187+
width: 100%;
188+
padding: 0 var(--p-space-2);
189+
}
190+
191+
.ItemInnerWrapper {
206192
display: flex;
207193
flex-wrap: nowrap;
208194
width: 100%;
195+
196+
&:hover {
197+
background: var(--p-background-hovered);
198+
color: var(--p-text);
199+
text-decoration: none;
200+
}
201+
}
202+
203+
.ItemInnerWrapper-Selected {
204+
background-color: var(--p-background-selected);
205+
@include focus-ring;
206+
207+
&:hover,
208+
&.keyFocused {
209+
background-color: var(--p-background-hovered);
210+
color: var(--p-text-primary-hovered);
211+
}
212+
213+
.keyFocused {
214+
@include focus-ring($style: 'focused');
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)