-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathd2l-navigation-skip-main.js
31 lines (25 loc) · 1.05 KB
/
d2l-navigation-skip-main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import './d2l-navigation-skip.js';
import { html, LitElement } from 'lit';
import { FocusMixin } from '@brightspace-ui/core/mixins/focus/focus-mixin.js';
import { LocalizeNavigationElement } from './components/localize-navigation-element.js';
import { querySelectorComposed } from '@brightspace-ui/core/helpers/dom.js';
class NavigationSkipMain extends FocusMixin(LocalizeNavigationElement(LitElement)) {
static get focusElementSelector() {
return 'd2l-navigation-skip';
}
render() {
return html`<d2l-navigation-skip text="${this.localize('skipNav')}" @click="${this._handleSkipNav}" class="vdiff-target"></d2l-navigation-skip>`;
}
_handleSkipNav() {
const elem = querySelectorComposed(document, 'main') ||
querySelectorComposed(document, '[role="main"]') ||
querySelectorComposed(document, 'h1');
if (elem) {
elem.tabIndex = -1;
elem.focus();
} else {
this.dispatchEvent(new CustomEvent('d2l-navigation-skip-fail', { bubbles: false, composed: false }));
}
}
}
customElements.define('d2l-navigation-skip-main', NavigationSkipMain);