diff --git a/gatsby-browser.js b/gatsby-browser.js index feb9f696645..a91c72c31f3 100644 --- a/gatsby-browser.js +++ b/gatsby-browser.js @@ -19,3 +19,26 @@ function scrollToAnchor(location, mainNavHeight = 0) { return true; } + +exports.onInitialClientRender = () => { + // h/t https://stackoverflow.com/questions/19646684/force-open-the-details-summary-tag-for-print-in-chrome/75260733#75260733 + window.matchMedia("print").addEventListener("change", (evt) => { + if (evt.matches) { + let detailsElements = document.body.querySelectorAll( + "details:not([open])", + ); + for (let e of detailsElements) { + e.toggleAttribute("open", true); + e.dataset.wasclosed = ""; + } + } else { + let detailsElements = document.body.querySelectorAll( + "details[data-wasclosed]", + ); + for (let e of detailsElements) { + e.removeAttribute("open"); + delete e.dataset.wasclosed; + } + } + }); +}; diff --git a/src/components/prev-next.js b/src/components/prev-next.js index 3642fece43c..2a18b32bcd9 100644 --- a/src/components/prev-next.js +++ b/src/components/prev-next.js @@ -7,7 +7,7 @@ const PrevNext = ({ prevNext }) => { let upLink = prevNext.up; return ( -