From e432968aea9047025f79bcb96c886e99afca287b Mon Sep 17 00:00:00 2001 From: Max Okorokov Date: Wed, 29 Jan 2020 13:28:49 +0100 Subject: [PATCH] fix(nav): allow having falsy values like 0 and 'false' for nav ids Fixes #3569 --- .../nav/overview/nav-overview.component.html | 4 +- src/nav/nav.spec.ts | 47 +++++++++++++++++++ src/nav/nav.ts | 9 +++- 3 files changed, 57 insertions(+), 3 deletions(-) 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(`