Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
298 views
in Technique[技术] by (71.8m points)

reactjs - react js react-boostrap toggling menu buttons not working

I am reading the examples on react-bootstrap for Navbar Nav controls on https://react-bootstrap.github.io/components/navbar/. My current menu button are not toggle at all.

I read some of the post here but they are all using the same code example like

<Navbar collapseOnSelect expand="lg" bg="dark" variant="dark">
  <Navbar.Brand href="#home">React-Bootstrap</Navbar.Brand>
  <Navbar.Toggle aria-controls="responsive-navbar-nav" />
  <Navbar.Collapse id="responsive-navbar-nav">
    <Nav className="mr-auto">
      <Nav.Link href="#features">Features</Nav.Link>
      <Nav.Link href="#pricing">Pricing</Nav.Link>
      <NavDropdown title="Dropdown" id="collasible-nav-dropdown">
        <NavDropdown.Item href="#action/3.1">Action</NavDropdown.Item>
        <NavDropdown.Item href="#action/3.2">Another action</NavDropdown.Item>
        <NavDropdown.Item href="#action/3.3">Something</NavDropdown.Item>
        <NavDropdown.Divider />
        <NavDropdown.Item href="#action/3.4">Separated link</NavDropdown.Item>
      </NavDropdown>
    </Nav>
    <Nav>
      <Nav.Link href="#deets">More deets</Nav.Link>
      <Nav.Link eventKey={2} href="#memes">
        Dank memes
      </Nav.Link>
    </Nav>
  </Navbar.Collapse>
</Navbar>

I have the following code that is not toggling buttons

<Navbar>
  <Navbar.Brand /> // tried this but does not fix it
  <Nav>
    {menuButtonList} // this is any array of menu buttons that include 'Home'
  </Nav>
</Navbar>

The current issue, by default Home button is highlighted as active. When I clicked on the other menu buttons, they highlight and toggle. The first button, Home, stays active.

Any help is appreciated.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Actually your Home is expected to keep highlighted because it's a Navbar.Brand component not a Nav.Link. A Navbar.Brand is expected to behave like that, it's related to what a Brand is all about. When you display your Brand you expect that it shines to reinforce your Brand.

if you don't want a Brand than it's better to switch to another Nav.Link nested at you Nav component instead.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...