-
Notifications
You must be signed in to change notification settings - Fork 2
/
auro-accordion-group.js
56 lines (47 loc) · 1.61 KB
/
auro-accordion-group.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
// Copyright (c) 2020 Alaska Airlines. All right reserved. Licensed under the Apache-2.0 license
// See LICENSE in the project root for license information.
// ---------------------------------------------------------------------
import { LitElement, html } from "lit-element";
// Import touch detection lib
import "focus-visible/dist/focus-visible.min.js";
// build the component class
class AuroAccordionGroup extends LitElement {
connectedCallback() {
super.connectedCallback();
this.addEventListener('toggleExpanded', this.handleToggleExpanded);
}
/**
* @private Internal function to toggle any expanded panels if it is not the one selected
* @param {object} event - Standard event parameter
*/
handleToggleExpanded(event) {
this.index = this.items.indexOf(event.target);
this.items.forEach((item) => {
if (item !== event.target && item.expanded) {
item.transitionHeight(false);
item.expanded = false;
}
});
this.scrollIntoView({
behavior: "smooth",
block: "nearest",
});
}
/**
* @private Internal function to update items when items are added or removed from the slot
*/
handleSlotChange() {
this.items = Array.from(this.querySelectorAll('auro-accordion'));
}
// function that renders the HTML and CSS into the scope of the component
render() {
return html`
<slot @slotchange=${this.handleSlotChange}></slot>
`;
}
}
/* istanbul ignore else */
// define the name of the custom component
if (!customElements.get("auro-accordion-group")) {
customElements.define("auro-accordion-group", AuroAccordionGroup);
}