Skip to content

Commit

Permalink
feat: add target property to side-nav-item (#7088)
Browse files Browse the repository at this point in the history
* feat: add target property to side-nav-item

* test: add tests for target property

* test: remove test and change check
  • Loading branch information
DiegoCardoso authored Jan 18, 2024
1 parent da40288 commit e042c3e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/side-nav/src/vaadin-side-nav-item.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ declare class SideNavItem extends SideNavChildrenMixin(DisabledMixin(ElementMixi
*/
readonly current: boolean;

/**
* The target of the link. Works only when `path` is set.
*/
target: string | null | undefined;

addEventListener<K extends keyof SideNavItemEventMap>(
type: K,
listener: (this: SideNavItem, ev: SideNavItemEventMap[K]) => void,
Expand Down
6 changes: 6 additions & 0 deletions packages/side-nav/src/vaadin-side-nav-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ class SideNavItem extends SideNavChildrenMixin(DisabledMixin(ElementMixin(Themab
readOnly: true,
reflectToAttribute: true,
},

/**
* The target of the link. Works only when `path` is set.
*/
target: String,
};
}

Expand Down Expand Up @@ -201,6 +206,7 @@ class SideNavItem extends SideNavChildrenMixin(DisabledMixin(ElementMixin(Themab
?disabled="${this.disabled}"
tabindex="${this.disabled || this.path == null ? '-1' : '0'}"
href="${ifDefined(this.disabled ? null : this.path)}"
target="${ifDefined(this.target)}"
part="link"
aria-current="${this.current ? 'page' : 'false'}"
>
Expand Down
16 changes: 16 additions & 0 deletions packages/side-nav/test/side-nav-item.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,5 +292,21 @@ describe('side-nav-item', () => {
toggle.click();
expect(spy.called).to.be.false;
});

describe('target property', () => {
it('should set target attribute to the anchor when target is set', async () => {
item.target = '_blank';
await nextRender();
expect(anchor.getAttribute('target')).to.be.equal('_blank');
});

it('should remove target attribute from the anchor when target is removed', async () => {
item.target = '_blank';
await nextRender();
item.target = null;
await nextRender();
expect(anchor.hasAttribute('target')).to.be.not.ok;
});
});
});
});

0 comments on commit e042c3e

Please sign in to comment.