diff --git a/packages/accordion/src/LionAccordion.js b/packages/accordion/src/LionAccordion.js
index 4c2abde5b..31c34717d 100644
--- a/packages/accordion/src/LionAccordion.js
+++ b/packages/accordion/src/LionAccordion.js
@@ -43,21 +43,21 @@ export class LionAccordion extends LitElement {
flex-direction: column;
}
- .accordion ::slotted([slot='invoker']) {
+ .accordion ::slotted([slot='accordion']) {
margin: 0;
}
- .accordion ::slotted([slot='invoker'][expanded]) {
+ .accordion ::slotted([slot='accordion'][expanded]) {
font-weight: bold;
}
- .accordion ::slotted([slot='content']) {
+ .accordion ::slotted([slot='accordion']) {
margin: 0;
visibility: hidden;
display: none;
}
- .accordion ::slotted([slot='content'][expanded]) {
+ .accordion ::slotted([slot='accordion'][expanded]) {
visibility: visible;
display: block;
}
@@ -148,6 +148,7 @@ export class LionAccordion extends LitElement {
+
`;
}
@@ -218,7 +219,7 @@ export class LionAccordion extends LitElement {
const contents = /** @type {HTMLElement[]} */ (
Array.from(this.querySelectorAll('[slot="content"]'))
);
- const accordion = this.shadowRoot?.querySelector('.accordion');
+ const accordion = this.shadowRoot?.querySelector('slot[name=accordion]');
if (accordion) {
invokers.forEach((invoker, index) => {
diff --git a/packages/accordion/test/lion-accordion.test.js b/packages/accordion/test/lion-accordion.test.js
index 9ab22cf01..d5d715fce 100644
--- a/packages/accordion/test/lion-accordion.test.js
+++ b/packages/accordion/test/lion-accordion.test.js
@@ -18,6 +18,12 @@ const basicAccordion = html`
`;
+function getAccordionChildren(/** @type {Element} */ el) {
+ const slot = el.shadowRoot?.querySelector('slot[name=accordion]');
+
+ return slot ? slot.children : [];
+}
+
describe('', () => {
describe('Accordion', () => {
it('sets expanded to [] by default', async () => {
@@ -37,15 +43,16 @@ describe('', () => {
`)
);
expect(el.expanded).to.deep.equal([1]);
+
expect(
- Array.from(el.children).find(
+ Array.from(getAccordionChildren(el)).find(
child => child.slot === 'invoker' && child.hasAttribute('expanded'),
)?.textContent,
).to.equal('invoker 2');
el.expanded = [0];
expect(
- Array.from(el.children).find(
+ Array.from(getAccordionChildren(el)).find(
child => child.slot === 'invoker' && child.hasAttribute('expanded'),
)?.textContent,
).to.equal('invoker 1');
@@ -118,14 +125,14 @@ describe('', () => {
);
expect(el.focusedIndex).to.equal(1);
expect(
- Array.from(el.children).find(
+ Array.from(getAccordionChildren(el)).find(
child => child.slot === 'invoker' && child.firstElementChild?.hasAttribute('focused'),
)?.textContent,
).to.equal('invoker 2');
el.focusedIndex = 0;
expect(
- Array.from(el.children).find(
+ Array.from(getAccordionChildren(el)).find(
child => child.slot === 'invoker' && child.firstElementChild?.hasAttribute('focused'),
)?.textContent,
).to.equal('invoker 1');
@@ -325,12 +332,12 @@ describe('', () => {
el.expanded = [4];
await el.updateComplete;
expect(
- Array.from(el.children).find(
+ Array.from(getAccordionChildren(el)).find(
child => child.slot === 'invoker' && child.hasAttribute('expanded'),
)?.textContent,
).to.equal('invoker 5');
expect(
- Array.from(el.children).find(
+ Array.from(getAccordionChildren(el)).find(
child => child.slot === 'content' && child.hasAttribute('expanded'),
)?.textContent,
).to.equal('content 5');
@@ -375,12 +382,12 @@ describe('', () => {
content 2
`);
- expect(Array.from(el.children).find(child => child.slot === 'content')).to.not.have.attribute(
- 'tabindex',
- );
- expect(Array.from(el.children).find(child => child.slot === 'content')).to.not.have.attribute(
- 'tabindex',
- );
+ expect(
+ Array.from(getAccordionChildren(el)).find(child => child.slot === 'content'),
+ ).to.not.have.attribute('tabindex');
+ expect(
+ Array.from(getAccordionChildren(el)).find(child => child.slot === 'content'),
+ ).to.not.have.attribute('tabindex');
});
describe('Invokers', () => {
@@ -411,7 +418,8 @@ describe('', () => {
`);
expect(
- Array.from(el.children).find(child => child.slot === 'invoker')?.firstElementChild,
+ Array.from(getAccordionChildren(el)).find(child => child.slot === 'invoker')
+ ?.firstElementChild,
).to.have.attribute('aria-expanded', 'false');
});
@@ -426,7 +434,8 @@ describe('', () => {
);
el.expanded = [0];
expect(
- Array.from(el.children).find(child => child.slot === 'invoker')?.firstElementChild,
+ Array.from(getAccordionChildren(el)).find(child => child.slot === 'invoker')
+ ?.firstElementChild,
).to.have.attribute('aria-expanded', 'true');
});
});