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
Responsive navbar #738
Comments
We already have the NgbCollapse directive to do that. Replace the bootstrap example by the following snippet, and you'll have the equivalent. Is there something more needed?
|
Yep, agree with @jnizet - I think that we are covered here so going to close this one. @ravipunjwani feel free to come back with more info if you believe that we are still missing sth. |
Hi @jnizet and @pkozlowski-opensource , I'm coming back on this issue after many days as I got busy with building rest of my app. Kindly have a look at my explanation below for this issue. I agree that the ng-collapse is already a feature in ng-bootstrap library but, it works only on a variable e.g. isNavbarCollapsed. That means the variable can be initialized to a value true or false, but this behaviour remains same with all screen sizes. I would think of a "responsive navbar" that works same as in current example that you provided, additionally with a little logic as follows:
Please refer to the sample plunker to describe the problem with code and a little explanation. The bootstrap implementation works well as I described. Please follow the second example in bootstrap responsive navbar. The key here is the usage of class "navbar-toggleable-xs". |
Hi @pkozlowski-opensource, please update the task status to Open, so that anyone can look into this issue and suggest the feature change. |
@ravipunjwani I had another look at this one and IMO we do behave exactly as BS. Here is a simple plunker I've created: http://plnkr.co/edit/4GJl2bBLsjHGhEjn48hx?p=preview The way the display of the navbar is driven is be CSS only and there is no JS logic in collapse nor in any other place (at least as far as I can tell). If you are after setting the initial state of the collapse you could do it based on the viewport size or use sth fancy like media queries from JS: https://www.sitepoint.com/javascript-media-queries/. In any case I don't think there should be any logic for this on the ng-bootstrap side. Given all the above I'm going to close this issue for now. Open to re-considering if you can demonstrate that we are behaving differently as compared to Bootstrap 4. |
While I agree that with collapse you can implement the navbar, it would be even better to implement a navbar component that USES Collapse.. This is the same approach we've taken for ng-officeuifabric, and you end up with some very simple components, but for the end user it's very easy and there's no discussion about which directive/component to use. |
The problem with a dedicated navbar component is that you would have to take arbitrary decisions that might limit what users can do (less flexibility). Indeed a component would have to have a template and any markup you put in this template harder to customize by users. Having said the above I'm not opposed to the idea of a navbar component, I'm just trying to determine if the gain (less code to write etc.) vs. flexibility makes it "worth". Basically if the new abstraction "pays for itself" (any new abstraction has cost on a new API, documentation, things to learn etc.) @rolandoldengarm if you (or anyone else interested in this feature) could put together a design doc / API proposal we could iterate on it and see if its is worth new API. |
@pkozlowski-opensource Plunker is not working. Locally I get the same result as the Plunker. |
i had the above example working, but then upgraded to bootstrap@4.0.0-alpha.6 (from bootstrap@4.0.0-alpha5) and it stopped working. i noticed that there is a navbar rewrite i changed my menu like this (and it works now) 😄 <nav class="navbar navbar-toggleable-md navbar-light bg-faded">
<button class="navbar-toggler navbar-toggler-right" type="button" (click)="isNavbarCollapsed = !isNavbarCollapsed"
aria-controls="exCollapsingNavbar2" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<a class="navbar-brand" href="#">North America - Conventional</a>
<div [ngbCollapse]="isNavbarCollapsed" class="collapse navbar-collapse" id="exCollapsingNavbar2">
<div class="navbar-nav mr-auto">
<a class="nav-item nav-link" routerLink="/transfers" routerLinkActive="active">Transfers</a>
<a class="nav-item nav-link" routerLink="/jobs" routerLinkActive="active">Jobs</a>
<a class="nav-item nav-link" routerLink="/jobs/7" routerLinkActive="active">Job 7</a>
</div>
</div>
</nav> |
we need auto collapse for ngbCollapse when any link under it clicked: $('.navbar-collapse ul li a').click(function() {
/* always close responsive nav after click */
$('.navbar-toggle:visible').click();
}); |
Even with @datumgeek 's fixes this still doesn't work properly because it doesn't know about reactive design and automatically set it correctly as those change. There needs to be an out of the box navbar that works EXACTLY like the bootstrap example that understands reactive design and works accordingly. That means:
What it doesn't do right now is know the different sizing and change the value based on reactive design. I.e. you need a proper navbar control in here because this hack you have right now doesn't actually address the issue and you're requiring major code just to make work what works right out of the box with bootstrap 4 which defeats the purpose of this project. |
Has anyone had any success adding a dropdown-link to a navbar? @datumgeek 's solution works for me, but using ngbCollapse with a dropdown inside the navbar results in the dropdown getting put inside the navbar element, not on the body. This is what I tried:
|
Works for me (except for initial state which is not collapsed but should be). Here is how I did the dropDown:
|
I was able to replicate bootstraps navbar example with the collapse directive except for animation. The collapse plugin doesn't seem to do the slide in/out animation. |
Are there plans to implement the slide in/out animation? |
I'm finding that neither of these code snippets are working with the current versions of bootstrap and ng-bootstrap. Is there still no plans to implement this and if there isn't is there any chance that there could be a plunker kept up to date. |
I find the same thing as @AnthonyCrowcroft - the snippets used to work but with the 4.0.0-beta updates, it seems to have changed some syntax and stuff. Yes, I can figure it out myself. I don't want a dedicated page in the docs for this since I agree that |
@mcescalante you can always check our demo page code where we've got responsive navbar: ng-bootstrap/demo/src/app/app.component.html Lines 2 to 41 in 5886946
|
Ah excellent! This is perfect @pkozlowski-opensource thank you very much! |
@pkozlowski-opensource That snippet was exactly what I was looking for. Methinks there needs to be something in the docs about this. Wasn't obvious to me as a newbie ng-bootstrap user (but long time bootstrap user) |
Does anyone have a plunkr for the latest version? I don't manage to make it run. |
I wanted to try Bootstrap 4 in hopes of getting access to some of their new goodies, but seeing how it's so difficult to get something as simple as a navbar to work is quite disheartening. The code on the documentation for Bootstrap 4 simply doesn't work with the latest version of Angular. The code from @pkozlowski-opensource works, but it seems like a lot of hoops and hurdles just to get one of the most basic components to work. (The hurdle being having to look up issues in ng-bootstrap when it should just work) |
@dougamos @collindutter You can add the angular/animations to have that slide-in/out effect.
And in your component
Here's a stackblitz demo https://stackblitz.com/edit/ng-bri-bs1-armbhz?file=app%2Fapp.component.html |
- Upgraded to bootstrap v4 beta2 - Removed bootstrap JS - Added ng-bootstrap - Fixed menu (now works with mobile devices) as per example of ng-bootstrap/ng-bootstrap#738 (comment)
Lol this is actually bs that the accepted answer was "here's this directive which doesn't do 90% of what the bootstrap component does, but deal with it." Paste the code from the first response into your ide and compare it with the BS4 component. Just terrible. I also like how the last response is 50+ lines of code to do what the BS4 component does in one. Defeating the purpose of using bootstrap, or angular for that matter. Why not just use es5 and some html and css, technically you COULD achieve everything bootstrap offers. Sad! |
I found this interesting article that explains the purpose of ng-bootstrap and why we shouldn't give it up (even if we have to write more code) : https://stevenschwenke.de/AngularAndBootstrapUseNg-bootstrap. Basically Angular works with components where jquery interacts with the DOM itself. While Jquery can break the app, ng-bootstrap is written the angular way and you keep the control over your components. |
The default ngbCollapse example works also for small initial screen sizes, if you set the initial value of isCollapsed to true (even if this is not really "true" for larger screen sizes, but it works) |
The ngbCollapse is only tied to the onclick button action though. If you increase the window size to hide the 'hamburger' button the 'show' property is still active on the div. Then next time you reduce window size you'll see an already active dropdown. The collapsed menu should be hidden by default every time the 'hamburger' makes an appearance. It should not persisted. |
For me, just adding
|
FYI: These two examples works just fine |
I would just like to raise an opinion as a new After a bunch of searching (and googling, and thinking "There's no way ng-boostrap wouldn't have a navbar component since bootstrap has one") I stumbled on the doc/example in Maybe move the |
Hi guys,
This library is just an awesome box to start with angular while dependent on bootstrap css. I'm creating a navbar and just got through an issue here. Probably it's a new-feature request or it can be said as a bootstrap-feature not yet in ng-bootstrap.
Feature description:
Look at this link where you can set collapsible navbar based on the size of the screen.
Bootstrap 4 documentation for navbar
This can be seen in
responsive navbar
section of this link. To the point, it actually usesnavbar-toggleable-xs
class to define this functionality. The navbar comes collapsible only when the screen size is xs, otherwise, its a regular navbar.Version of Angular, ng-bootstrap, and Bootstrap:
Angular2: 2.0.1
ng-bootstrap: 1.0.0-alpha.6
Bootstrap: 4.0.0-alpha.4
The text was updated successfully, but these errors were encountered: