Skip to content

Commit

Permalink
feat(esl-anchornav): add active-class to set on active item
Browse files Browse the repository at this point in the history
  • Loading branch information
dshovchko committed Aug 21, 2024
1 parent 3d43ba1 commit e452e71
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion site/views/examples/anchornav.njk
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ aside:
</div>
<div>
<div class="esl-anchornav-pseudo-fixed">
<esl-anchornav>
<esl-anchornav active-class="active">
<div class="h4 text-center">Anchornav</div>
</esl-anchornav>
</div>
Expand Down
4 changes: 3 additions & 1 deletion src/modules/esl-anchornav/core/esl-anchornav.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ export class ESLAnchornav extends ESLBaseElement {

/** Item renderer which is used to build inner markup */
@attr({defaultValue: 'default', name: 'renderer'}) public rendererName: string;
/** CSS classes to set on active item */
@attr({defaultValue: 'active'}) public activeClass: string;

protected _active: ESLAnchorData;
protected _anchors: ESLAnchorData[] = [];
Expand Down Expand Up @@ -171,7 +173,7 @@ export class ESLAnchornav extends ESLBaseElement {
if (y <= topBoundary) active = item;
});
if (active) {
this._items.forEach(($item, id) => $item.classList.toggle('active', id === active.id));
this._items.forEach(($item, id) => $item.classList.toggle(this.activeClass, id === active.id));
this.active = active;
}
}
Expand Down

0 comments on commit e452e71

Please sign in to comment.