Skip to content

Commit

Permalink
fix(ld-accordion): single mode scroll into view
Browse files Browse the repository at this point in the history
  • Loading branch information
borisdiakur committed Mar 28, 2022
1 parent f5bdad7 commit 89deb05
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/liquid/components/ld-accordion/ld-accordion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,21 @@ export class LdAccordion {
const toggle = section.querySelector('ld-accordion-toggle')
const panel = section.querySelector('ld-accordion-panel')

// singleModeDelta is the height of the currently open panel, that needs
// to be subtracted from the scroll amount in single mode.
const allSections = Array.from(section.parentElement.children)
const singleModeDelta =
this.single && !this.scrollIntoViewOnTransitionEnd
? allSections
.slice(
0,
allSections.findIndex((sec) => sec === section)
)
.find((sec) =>
sec.classList.contains('ld-accordion-section--expanded')
)?.children[1].scrollHeight || 0
: 0

const panelOffsetToScrollParent =
scrollParent.scrollTop +
panel.getBoundingClientRect().top -
Expand All @@ -74,7 +89,8 @@ export class LdAccordion {
Math.min(
panel.scrollHeight,
scrollParent.clientHeight - toggle.clientHeight - scrollPaddingTop
)
) -
singleModeDelta

// If an accordion section expands at the bottom end of the accordion
// The scroll container may not have a sufficient height at that time
Expand Down

0 comments on commit 89deb05

Please sign in to comment.