Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions src/vcf-nav-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ export class NavItem extends LitElement {
@property()
path = '';

@property({reflect: true})
pathAlias = '';

@property({ type: Boolean, reflect: true })
expanded = false;

Expand Down Expand Up @@ -212,25 +215,20 @@ export class NavItem extends LitElement {
_updateActive() {
const hasBaseUri = (document.baseURI != document.location.href);
const pathAbsolute = this.path.startsWith("/");
const pathAliasArr = this.pathAlias.split(",");
if (hasBaseUri && !pathAbsolute) {
const pathRelativeToRoot = document.location.pathname;
const basePath = new URL(document.baseURI).pathname;
const pathWithoutBase = pathRelativeToRoot.substring(basePath.length);
const pathRelativeToBase = (basePath !== pathRelativeToRoot && pathRelativeToRoot.startsWith(basePath)) ? pathWithoutBase : pathRelativeToRoot;
this.active = pathRelativeToBase === this.path;
this.active = pathRelativeToBase === this.path ||
pathAliasArr.filter((alias) => pathRelativeToBase === alias).length > 0;
} else {
// Absolute path or no base uri in use. No special comparison needed
if (pathAbsolute) {
// Compare an absolute view path
this.active = document.location.pathname == this.path;
} else {
// Compare a relative view path (strip the starting slash)
this.active = document.location.pathname.substring(1) == this.path;
}

this.active = document.location.pathname == this.path ||
pathAliasArr.filter((alias) => document.location.pathname == alias).length > 0;
}
this.toggleAttribute('child-active', document.location.pathname.startsWith(this.path));

this.toggleAttribute('child-active', document.location.pathname.startsWith(this.path) || pathAliasArr.filter((alias) => document.location.pathname.startsWith(alias)).length > 0);
if (this.active) {
this.expanded = true;
}
Expand Down