Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'active' prop to NavDropdown component #2015

Merged
merged 1 commit into from
Jul 6, 2016

Conversation

mrijke
Copy link

@mrijke mrijke commented Jul 4, 2016

This commit adds the 'active' prop to the NavDropdown component, which
when true adds the 'active' class to the component.

Note that this does not automatically fix react-bootstrap/react-router-bootstrap#167, because the LinkContainer does not wrap the entire NavDropdown, but only the individual items.
Personally I fixed this by using a wrapper component wrapping the NavDropdown which checks in the render() if the path of any of its children currently is active (the same check the LinkContainer performs) like so:

  isAnyChildActive() {
    let anyChildActive = false;
    React.Children.forEach(this.props.menuItems, (child) => {
      if (!anyChildActive)
        anyChildActive = this.context.router.isActive(child.props.path, false);
    });
    return anyChildActive;
  }

(in the above code this.props.menuItems is a list of MenuItem wrappers which have the path prop which is passed to the LinkContainer as the to prop)

@taion
Copy link
Member

taion commented Jul 4, 2016

This should go on NavDropdown.

This commit adds the 'active' prop to the NavDropdown component, which
when true adds the 'active' class to the component.
@mrijke
Copy link
Author

mrijke commented Jul 4, 2016

OK, moved the prop to the NavDropdown component.

@mrijke mrijke changed the title Add 'active' prop to Dropdown component Add 'active' prop to NavDropdown component Jul 4, 2016
@jquense
Copy link
Member

jquense commented Jul 5, 2016

LGTM

@taion taion merged commit a5b7ff4 into react-bootstrap:master Jul 6, 2016
@mrijke mrijke deleted the dropdown-add-active-prop branch April 7, 2017 13:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NavDropdown not set to active when MenuItem child link is active route
3 participants