Skip to content

Better way for triggering the collapse of the NavBar. #56

@Dhavalc2012

Description

@Dhavalc2012

We want to trigger the collapse of the navbar on the phone when clicking on the link or outside the NavBar component when NavBar items are shown on the phone.

Currently we are triggering the collapse using target="#navBarCollapse" toggle="collapse". However for this we have to use b-button element which accept toggle attribute. Also, when using this NavBar has transition effect even on the desktop.

Following is the sample code:

<template>
 <Navbar
  expand="lg"
  background-color="body-tertiary"
 >
  <Container type="fluid">
   <NavbarBrand>Navbar</NavbarBrand>
   <NavbarToggler target="#navBarCollapse" toggle="collapse" />
   <NavbarCollapse id="navBarCollapse">
    <NavbarNav>
     <NavLink to="/" active>
     <b-button target="#navBarCollapse" toggle="collapse">
       Home
      </b-button>
     </NavLink>
     <NavLink>Features</NavLink>
     <NavLink>Pricing</NavLink>
     <NavLink disabled>
      Disabled
     </NavLink>
    </NavbarNav>
   </NavbarCollapse>
  </Container>
 </Navbar>
</template>

We also tried using the ref and using as a method like navBarCollapse.value.toggle() and navBarCollapse.value.show()

Is there a better way of handling this programmatically to avoid declaring elements such as b-button and have ability to fire from other components on the body?

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions