-
Notifications
You must be signed in to change notification settings - Fork 25
/
tab-panel-mixin.js
83 lines (75 loc) · 1.87 KB
/
tab-panel-mixin.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import { css } from 'lit';
import { getUniqueId } from '../../helpers/uniqueId.js';
export const TabPanelMixin = superclass => class extends superclass {
static get properties() {
return {
/**
* Opt out of default padding/whitespace around the panel
* @type {boolean}
*/
noPadding: { type: Boolean, attribute: 'no-padding', reflect: true },
/**
* @ignore
*/
// eslint-disable-next-line lit/no-native-attributes
role: { type: String, reflect: true },
/**
* Use to select the tab
* @type {boolean}
*/
selected: { type: Boolean, reflect: true },
/**
* ACCESSIBILITY: REQUIRED: The text used for the tab, as well as labelling the panel
* @type {string}
*/
text: { type: String }
};
}
static get styles() {
return css`
:host {
box-sizing: border-box;
display: none;
margin: 1.2rem 0 0 0;
}
:host([no-padding]) {
margin: 0;
}
:host([selected]) {
display: block;
}
`;
}
constructor() {
super();
this.noPadding = false;
/** @ignore */
this.role = 'tabpanel';
this.selected = false;
}
connectedCallback() {
super.connectedCallback();
if (this.id.length === 0) this.id = getUniqueId();
}
updated(changedProperties) {
super.updated(changedProperties);
changedProperties.forEach((oldVal, prop) => {
if (prop === 'selected') {
if (this.selected) {
requestAnimationFrame(() => {
/** Dispatched when a tab is selected */
this.dispatchEvent(new CustomEvent(
'd2l-tab-panel-selected', { bubbles: true, composed: true }
));
});
}
} else if (prop === 'text') {
this.setAttribute('aria-label', this.text);
/** Dispatched when the text attribute is changed */
this.dispatchEvent(new CustomEvent(
'd2l-tab-panel-text-changed', { bubbles: true, composed: true, detail: { text: this.text } }
));
}
});
}
};