diff --git a/core/static/bundled/core/accordion-index.ts b/core/static/bundled/core/accordion-index.ts deleted file mode 100644 index 39e37564..00000000 --- a/core/static/bundled/core/accordion-index.ts +++ /dev/null @@ -1,25 +0,0 @@ -const setMaxHeight = (element: HTMLDetailsElement) => { - element.setAttribute("style", `max-height: ${element.scrollHeight}px`); -}; - -// Initialize max-height at load -window.addEventListener("DOMContentLoaded", () => { - for (const el of document.querySelectorAll("details.accordion")) { - setMaxHeight(el as HTMLDetailsElement); - } -}); - -// Accordion opened -new MutationObserver((mutations: MutationRecord[]) => { - for (const mutation of mutations) { - const target = mutation.target as HTMLDetailsElement; - if (target.tagName !== "DETAILS" || !target.classList.contains("accordion")) { - continue; - } - setMaxHeight(target); - } -}).observe(document.body, { - attributes: true, - attributeFilter: ["open"], - subtree: true, -}); diff --git a/core/static/core/accordion.scss b/core/static/core/accordion.scss index abdbba02..4f40ba71 100644 --- a/core/static/core/accordion.scss +++ b/core/static/core/accordion.scss @@ -38,18 +38,52 @@ details[open].accordion>summary::before { content: '\f0d7'; } -// ::details-content isn't available on firefox yet -// we use .accordion-content as a workaround details.accordion>.accordion-content { background: #ffffff; color: #333333; padding: 1em 2.2em; - overflow: auto; border: 1px solid #dddddd; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; + overflow: hidden; } -details.accordion { - transition: max-height 300ms ease-in-out; +@mixin animation($selector) { + details.accordion#{$selector} { + opacity: 0; + + @supports (max-height: calc-size(max-content, size)) { + max-height: 0px; + } + } + + details[open].accordion#{$selector} { + opacity: 1; + + // Setting a transition on all states of the content + // will create a strange behavior where the transition + // continues without being shown, creating inconsistenties + transition: all 300ms ease-out; + + @supports (max-height: calc-size(max-content, size)) { + max-height: calc-size(max-content, size); + } + } +} + +// ::details-content isn't available on firefox yet +// we use .accordion-content as a workaround +// But we need to use ::details-content for chrome because it's +// not working correctly otherwise +// it only happen in chrome, not safari or firefox +// Note: `selector` is not supported by scss so we comment it out to +// avoid compiling it and sending it straight to the css +// This is a trick that comes from here : +// https://stackoverflow.com/questions/62665318/using-supports-selector-despite-sass-not-supporting-it +@supports #{'selector(details::details-content)'} { + @include animation("::details-content") +} + +@supports #{'not selector(details::details-content)'} { + @include animation(">.accordion-content") } \ No newline at end of file diff --git a/core/templates/core/base.jinja b/core/templates/core/base.jinja index 0d476689..a3afb49f 100644 --- a/core/templates/core/base.jinja +++ b/core/templates/core/base.jinja @@ -27,7 +27,6 @@ -