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?
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:
We also tried using the ref and using as a method like
navBarCollapse.value.toggle()andnavBarCollapse.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?