Skip to content

Commit

Permalink
fix(accordion-item): support items working across shadowDOM (#7035)
Browse files Browse the repository at this point in the history
**Related Issue:** #6167

## Summary

- Uses `closestElementCrossShadowBoundary` to find the parent
`calcite-accordion` across shadow DOM.
  • Loading branch information
driskull authored May 31, 2023
1 parent 5b40bbf commit 6378e35
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/components/accordion-item/accordion-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ import {
connectConditionalSlotComponent,
disconnectConditionalSlotComponent
} from "../../utils/conditionalSlot";
import { getElementDir, getElementProp, getSlotted, toAriaBoolean } from "../../utils/dom";
import {
closestElementCrossShadowBoundary,
getElementDir,
getElementProp,
getSlotted,
toAriaBoolean
} from "../../utils/dom";
import { CSS_UTILITY } from "../../utils/resources";
import { SLOTS, CSS } from "./resources";
import { FlipContext, Position, Scale } from "../interfaces";
Expand Down Expand Up @@ -298,9 +304,12 @@ export class AccordionItem implements ConditionalSlotComponent {
}

private getItemPosition(): number {
return Array.prototype.indexOf.call(
this.parent.querySelectorAll("calcite-accordion-item"),
this.el
const { el } = this;

const items = closestElementCrossShadowBoundary(el, "calcite-accordion")?.querySelectorAll(
"calcite-accordion-item"
);

return items ? Array.from(items).indexOf(el) : -1;
}
}

0 comments on commit 6378e35

Please sign in to comment.