Skip to content

Commit

Permalink
Fixed a bug where background color and cursor style are incorrect whe…
Browse files Browse the repository at this point in the history
…n expanding/collapsing navigation items
  • Loading branch information
cheton committed Dec 22, 2017
1 parent a5fccdf commit 5d10ee2
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 23 deletions.
4 changes: 2 additions & 2 deletions examples/Styled/StyledSideNav.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ const StyledNav = styled(Nav)`
}
}
&& > [class*="sidenav-navitem--"][class*="selected"],
&& > [class*="sidenav-navitem--"][class*="selected"]:hover {
&& > [class*="sidenav-navitem--"][class*="highlighted--"],
&& > [class*="sidenav-navitem--"][class*="highlighted--"]:hover {
> a {
[class*="sidenav-nav-icon--"],
[class*="sidenav-nav-text--"] {
Expand Down
2 changes: 2 additions & 0 deletions src/Nav.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const noop = () => {};

class Nav extends PureComponent {
static propTypes = {
componentType: PropTypes.any,

// A custom element for this component.
componentClass: PropTypes.oneOfType([
PropTypes.string,
Expand Down
26 changes: 16 additions & 10 deletions src/NavItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const noop = () => {};

class NavItem extends PureComponent {
static propTypes = {
componentType: PropTypes.any,

// A custom element for this component.
componentClass: PropTypes.oneOfType([
PropTypes.string,
Expand Down Expand Up @@ -68,7 +70,9 @@ class NavItem extends PureComponent {
isNavText = match(NavText);

handleSelect = (event) => {
const { href, disabled, onSelect, eventKey } = this.props;
const {
href, disabled, onSelect, eventKey
} = this.props;

if (!href || disabled) {
event.preventDefault();
Expand Down Expand Up @@ -111,14 +115,13 @@ class NavItem extends PureComponent {
const navText = this.findNavText(children);

if (subnav) {
const highlighted = active ||
(!!selected && selected === this.props.eventKey);
const isNavItemSelected = active || (!!selected && selected === this.props.eventKey);

return (
<Component
role="presentation"
className={cx(className, styles.sidenavSubnavitem, {
[styles.selected]: highlighted,
[styles.selected]: isNavItemSelected,
[styles.disabled]: disabled
})}
style={style}
Expand Down Expand Up @@ -171,16 +174,19 @@ class NavItem extends PureComponent {
return true;
});

const highlighted = active || expanded ||
(activeNavItems.length > 0) ||
(!!selected && selected === this.props.eventKey);
const isNavItemSelected = active || (!!selected && selected === this.props.eventKey) || (activeNavItems.length > 0);
const isNavItemHighlighted = expanded || isNavItemSelected;
const isNavItemExpandable = (navItems.length > 0);
const isNavItemExpanded = isNavItemExpandable && expanded;

return (
<Component
role="presentation"
className={cx(className, styles.sidenavNavitem, {
[styles.selected]: highlighted,
[styles.expanded]: expanded,
[styles.selected]: isNavItemSelected,
[styles.highlighted]: isNavItemHighlighted,
[styles.expandable]: isNavItemExpandable,
[styles.expanded]: isNavItemExpanded,
[styles.disabled]: disabled
})}
style={style}
Expand Down Expand Up @@ -214,7 +220,7 @@ class NavItem extends PureComponent {
<Component
role="heading"
className={cx(className, styles.sidenavSubnavitem, {
[styles.selected]: active,
[styles.highlighted]: active,
[styles.disabled]: disabled
})}
style={style}
Expand Down
8 changes: 6 additions & 2 deletions src/SideNav.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import match from './match-component';

class SideNav extends PureComponent {
static propTypes = {
componentType: PropTypes.any,

// A custom element for this component.
componentClass: PropTypes.oneOfType([
PropTypes.string,
Expand Down Expand Up @@ -65,7 +67,8 @@ class SideNav extends PureComponent {
};

if (typeof child.ref === 'string') {
warning(false,
warning(
false,
'String refs are not supported on `<SideNav.Toggle>` component. ' +
'To apply a ref to the component use the callback signature:\n\n ' +
'https://facebook.github.io/react/docs/more-about-refs.html#the-ref-callback-attribute'
Expand All @@ -89,7 +92,8 @@ class SideNav extends PureComponent {
};

if (typeof child.ref === 'string') {
warning(false,
warning(
false,
'String refs are not supported on `<SideNav.Nav>` component. ' +
'To apply a ref to the component use the callback signature:\n\n ' +
'https://facebook.github.io/react/docs/more-about-refs.html#the-ref-callback-attribute'
Expand Down
2 changes: 2 additions & 0 deletions src/Toggle.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import styles from './index.styl';

class Toggle extends PureComponent {
static propTypes = {
componentType: PropTypes.any,

// A custom element for this component.
componentClass: PropTypes.oneOfType([
PropTypes.string,
Expand Down
2 changes: 1 addition & 1 deletion src/sidenav-expanded.styl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
}

.sidenav-nav > .sidenav-navitem {
&.selected > a {
&.expandable > a {
cursor: pointer;
}
}
Expand Down
22 changes: 14 additions & 8 deletions src/sidenav-navitem.styl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
clear: both;
position: relative;

&.selected > a {
&.highlighted > a {
cursor: default;
}

Expand All @@ -11,27 +11,33 @@
opacity: .15;
}

&.selected > a::after,
&:hover.selected > a::after {
&.highlighted > a::after,
&:hover.highlighted > a::after {
background: #000;
opacity: .2;
}

&.selected.expanded > a::after,
&:hover.selected.expanded > a::after {
&.highlighted.expanded > a::after,
&:hover.highlighted.expanded > a::after {
background: #000;
opacity: .25;
}

&.highlighted.selected.expanded > a::after,
&:hover.highlighted.selected.expanded > a::after {
background: #000;
opacity: .2;
}

&:hover > a .sidenav-nav-icon,
&.selected > a .sidenav-nav-icon {
&.highlighted > a .sidenav-nav-icon {
opacity: 1;
}

&:hover > a .sidenav-nav-icon,
&:hover > a .sidenav-nav-text,
&.selected > a .sidenav-nav-icon,
&.selected > a .sidenav-nav-text {
&.highlighted > a .sidenav-nav-icon,
&.highlighted > a .sidenav-nav-text {
color: #fff;
}

Expand Down

0 comments on commit 5d10ee2

Please sign in to comment.