Skip to content

Commit

Permalink
fix(Masthead): have nav item render with selected styles in mobile nav (
Browse files Browse the repository at this point in the history
carbon-design-system#4259)

### Related Ticket(s)

menu item doesn't show active state in hamburg menu in masthead carbon-design-system#4076

### Description

The `LeftNav` menu item wasn't checking with the proper prop, so it wasn't detecting whether to render the nav item as selected in mobile.

FIXED:
<img width="652" alt="Screen Shot 2020-10-19 at 4 26 13 PM" src="https://user-images.githubusercontent.com/54281166/96508017-fcd87200-1227-11eb-98d1-3b56c314b5a1.png">

### Changelog

**New**

- add `titleEnglish` field to the `Nulla quis sem at nibh elementum imperdiet` custom nav item to allow for additional testing

**Changed**

- check for `rest.selectedMenuItem` in the `LeftNav` and render `#{$prefix}--masthead__l0-nav--selected-item` classname - this is specific for L0 nav items that don't have a menu


<!-- React and Web Component deploy previews are enabled by default. -->
<!-- To enable additional available deploy previews, apply the following -->
<!-- labels for the corresponding package: -->
<!-- *** "package: services": Services -->
<!-- *** "package: utilities": Utilities -->
<!-- *** "package: styles": Carbon Expressive -->
<!-- *** "RTL": React / Web Components (RTL) -->
<!-- *** "feature flag": React / Web Components (experimental) -->
  • Loading branch information
annawen1 authored and ariellalgilmore committed Oct 20, 2020
1 parent 883dd74 commit c9a5162
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93081,6 +93081,7 @@ exports[`Storyshots Components|Masthead With L 1 1`] = `
"hasMenu": false,
"menuSections": Array [],
"title": "Nulla quis sem at nibh elementum imperdiet",
"titleEnglish": "Nulla quis sem at nibh elementum imperdiet",
"url": "https://www.ibm.com/industries?lnk=min",
},
Object {
Expand Down Expand Up @@ -93406,6 +93407,7 @@ exports[`Storyshots Components|Masthead With L 1 1`] = `
"hasMenu": false,
"menuSections": Array [],
"title": "Nulla quis sem at nibh elementum imperdiet",
"titleEnglish": "Nulla quis sem at nibh elementum imperdiet",
"url": "https://www.ibm.com/industries?lnk=min",
},
Object {
Expand Down Expand Up @@ -94066,6 +94068,7 @@ exports[`Storyshots Components|Masthead With L 1 1`] = `
"hasMenu": false,
"menuSections": Array [],
"title": "Nulla quis sem at nibh elementum imperdiet",
"titleEnglish": "Nulla quis sem at nibh elementum imperdiet",
"url": "https://www.ibm.com/industries?lnk=min",
},
Object {
Expand Down
3 changes: 2 additions & 1 deletion packages/react/src/components/Masthead/MastheadLeftNav.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ const MastheadLeftNav = ({
<SideNavLink
href={link.url}
className={
rest.selected && `${prefix}--masthead__side-nav--submemu--selected`
rest.selectedMenuItem === link.titleEnglish &&
`${prefix}--masthead__side-nav--submemu--selected`
}
data-autoid={`${stablePrefix}--masthead-${rest.navType}-sidenav__l0-nav${i}`}
key={i}>
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/components/Masthead/MastheadTopNav.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const MastheadTopNav = ({ navigation, ...topNavProps }) => {
} else {
return (
<HeaderMenuItem
className={selected && `${prefix}--masthead__l0-nav--selected`}
className={selected && `${prefix}--masthead__l0-nav--selected-item`}
href={link.url}
data-autoid={autoid}
key={i}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ const mastheadLinks = [
},
{
title: 'Nulla quis sem at nibh elementum imperdiet',
titleEnglish: 'Nulla quis sem at nibh elementum imperdiet',
url: 'https://www.ibm.com/industries?lnk=min',
hasMenu: false,
hasMegapanel: false,
Expand Down
3 changes: 2 additions & 1 deletion packages/styles/scss/components/masthead/_masthead.scss
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ $search-transition-timing: 95ms;
}
}

.#{$prefix}--masthead__l0-nav--selected a[aria-expanded='false'] {
.#{$prefix}--masthead__l0-nav--selected a[aria-expanded='false'],
.#{$prefix}--masthead__l0-nav--selected-item a {
border-bottom: solid 3px $interactive-01;
}

Expand Down

0 comments on commit c9a5162

Please sign in to comment.