diff --git a/demo/src/app/components/nav/overview/nav-overview.component.html b/demo/src/app/components/nav/overview/nav-overview.component.html index 6fd375035f..343505c023 100644 --- a/demo/src/app/components/nav/overview/nav-overview.component.html +++ b/demo/src/app/components/nav/overview/nav-overview.component.html @@ -67,7 +67,9 @@

Selection / active nav

To select your navs programmatically, you have to give your nav items unique ids, so you could know and set which one is currently active either using the [(activeId)]="..." binding or the imperative API - with.select(id). If you don't provide any ids, they will be generated automatically. + with.select(id). If you don't provide any ids, they will be generated automatically. The only + limitation is that you can't have the '' (empty string) as id, because ngbNavItem, + ngbNavItem="" and [ngbNavItem]="''" are indistinguishable.

diff --git a/src/nav/nav.spec.ts b/src/nav/nav.spec.ts index c8b703735d..b728cfe71b 100644 --- a/src/nav/nav.spec.ts +++ b/src/nav/nav.spec.ts @@ -333,6 +333,53 @@ describe('nav', () => { expectContents(fixture, ['content 2']); }); + it(`should work navs with boundary [ngbNavItem] values`, () => { + const fixture = createTestComponent(` + +
+ `); + + expectLinks(fixture, [true, false, false, false]); + expectContents(fixture, ['content 1']); + + fixture.componentInstance.activeId = true; + fixture.detectChanges(); + expectLinks(fixture, [false, true, false, false]); + expectContents(fixture, ['content 2']); + + fixture.componentInstance.activeId = false; + fixture.detectChanges(); + expectLinks(fixture, [false, false, true, false]); + expectContents(fixture, ['content 3']); + + fixture.componentInstance.activeId = 0; + fixture.detectChanges(); + expectLinks(fixture, [true, false, false, false]); + expectContents(fixture, ['content 1']); + + fixture.componentInstance.activeId = ''; + fixture.detectChanges(); + expectLinks(fixture, [false, false, false, false]); + expectContents(fixture, []); + }); + it(`should allow overriding ids used in DOM with [domId]`, () => { const fixture = createTestComponent(`