Skip to content

Commit

Permalink
fix: Use navigated event (#7477) (CP: 24.4) (#7478)
Browse files Browse the repository at this point in the history
* fix: Use navigated event

vaadin-navigated is fired after navigation has taken place

* Update navigation.test.js

* Update packages/side-nav/test/navigation.test.js

* update function calls

---------

Co-authored-by: Artur <[email protected]>
Co-authored-by: Diego Cardoso <[email protected]>
  • Loading branch information
3 people authored Jun 7, 2024
1 parent 68f1d10 commit 5397f33
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions packages/side-nav/src/vaadin-side-nav-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,15 +208,15 @@ class SideNavItem extends SideNavChildrenMixin(DisabledMixin(ElementMixin(Themab
this.__updateCurrent();

window.addEventListener('popstate', this.__boundUpdateCurrent);
window.addEventListener('vaadin-navigate', this.__boundUpdateCurrent);
window.addEventListener('vaadin-navigated', this.__boundUpdateCurrent);
window.addEventListener('side-nav-location-changed', this.__boundUpdateCurrent);
}

/** @protected */
disconnectedCallback() {
super.disconnectedCallback();
window.removeEventListener('popstate', this.__boundUpdateCurrent);
window.removeEventListener('vaadin-navigate', this.__boundUpdateCurrent);
window.removeEventListener('vaadin-navigated', this.__boundUpdateCurrent);
window.removeEventListener('side-nav-location-changed', this.__boundUpdateCurrent);
}

Expand Down
10 changes: 5 additions & 5 deletions packages/side-nav/test/navigation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ describe('navigation', () => {
window.dispatchEvent(new PopStateEvent('popstate'));
}

function navigateWithVaadinNavigateEvent(url) {
function navigateWithVaadinNavigatedEvent(url) {
history.pushState({}, '', url);
window.dispatchEvent(new CustomEvent('vaadin-navigate'));
window.dispatchEvent(new CustomEvent('vaadin-navigated'));
}

beforeEach(async () => {
Expand Down Expand Up @@ -55,21 +55,21 @@ describe('navigation', () => {
});

it('should update current attribute on items when navigating with vaadin-navigate event', async () => {
navigateWithVaadinNavigateEvent('1');
navigateWithVaadinNavigatedEvent('1');
await nextRender();

expect(items[0].hasAttribute('current')).to.be.true;
expect(items[1].hasAttribute('current')).to.be.false;
expect(items[2].hasAttribute('current')).to.be.false;

navigateWithVaadinNavigateEvent('2');
navigateWithVaadinNavigatedEvent('2');
await nextRender();

expect(items[0].hasAttribute('current')).to.be.false;
expect(items[1].hasAttribute('current')).to.be.true;
expect(items[2].hasAttribute('current')).to.be.false;

navigateWithVaadinNavigateEvent('21');
navigateWithVaadinNavigatedEvent('21');
await nextRender();

expect(items[0].hasAttribute('current')).to.be.false;
Expand Down

0 comments on commit 5397f33

Please sign in to comment.