Skip to content

Commit

Permalink
feat: expand parent items when item is set current (#7183)
Browse files Browse the repository at this point in the history
  • Loading branch information
ugur-vaadin authored Mar 11, 2024
1 parent c0ada90 commit 736e3ab
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
15 changes: 15 additions & 0 deletions packages/side-nav/src/vaadin-side-nav-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,25 @@ class SideNavItem extends SideNavChildrenMixin(DisabledMixin(ElementMixin(Themab
__updateCurrent() {
this._setCurrent(this.__isCurrent());
if (this.current) {
this.__expandParentItems();
this.expanded = this._items.length > 0;
}
}

/** @private */
__expandParentItems() {
const parentItem = this.__getParentItem();
if (parentItem) {
parentItem.__expandParentItems();
}
this.expanded = true;
}

/** @private */
__getParentItem() {
return this.parentElement instanceof SideNavItem ? this.parentElement : null;
}

/** @private */
__isCurrent() {
if (this.path == null) {
Expand Down
15 changes: 15 additions & 0 deletions packages/side-nav/test/side-nav-item.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,21 @@ describe('side-nav-item', () => {
await item.updateComplete;
expect(spy.calledOnce).to.be.true;
});

it('should expand parent items when path matches', async () => {
item = fixtureSync(`
<vaadin-side-nav-item>
<vaadin-side-nav-item slot="children">
<vaadin-side-nav-item slot="children"></vaadin-side-nav-item>
</vaadin-side-nav-item>
</vaadin-side-nav-item>
`);
await nextRender();
item._items[0]._items[0].path = '';
await item.updateComplete;
expect(item.expanded).to.be.true;
expect(item._items[0].expanded).to.be.true;
});
});

describe('current item with children', () => {
Expand Down

0 comments on commit 736e3ab

Please sign in to comment.