Skip to content

Commit

Permalink
feat: (GAUD-6565) add back link click event (#221)
Browse files Browse the repository at this point in the history
  • Loading branch information
dlockhart authored Jun 17, 2024
1 parent 68757ef commit 7e34d42
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
11 changes: 10 additions & 1 deletion d2l-navigation-immersive.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ class NavigationImmersive extends LitElement {
<div class="d2l-navigation-immersive-container">
<div class="d2l-navigation-immersive-left d2l-body-compact">
<slot name="left">
<d2l-navigation-link-back text="${backLinkText}" href="${this.backLinkHref}"></d2l-navigation-link-back>
<d2l-navigation-link-back text="${backLinkText}" href="${this.backLinkHref}" @click="${this._handleBackClick}"></d2l-navigation-link-back>
</slot>
</div>
<div class="${classMap(middleContainerClasses)}">
Expand All @@ -223,6 +223,15 @@ class NavigationImmersive extends LitElement {
`;
}

_handleBackClick() {
this.dispatchEvent(
new CustomEvent(
'd2l-navigation-immersive-back-click',
{ bubbles: false, composed: false }
)
);
}

_handlePageResize(e) {
this._smallWidth = e.matches;
}
Expand Down
16 changes: 15 additions & 1 deletion test/immersive.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import '../d2l-navigation-immersive.js';
import { expect, fixture, html, runConstructor } from '@brightspace-ui/testing';
import { clickElem, expect, fixture, html, oneEvent, runConstructor } from '@brightspace-ui/testing';

describe('d2l-navigation-immersive', () => {

Expand All @@ -18,4 +18,18 @@ describe('d2l-navigation-immersive', () => {
});
});

describe('events', () => {

it('should fire back-link-click event', async() => {
const el = await fixture(html`<d2l-navigation-immersive></d2l-navigation-immersive>`);
const backLink = el
.shadowRoot.querySelector('d2l-navigation-link-back')
.shadowRoot.querySelector('d2l-navigation-link-icon')
.shadowRoot.querySelector('a');
clickElem(backLink);
await oneEvent(el, 'd2l-navigation-immersive-back-click');
});

});

});

0 comments on commit 7e34d42

Please sign in to comment.