diff --git a/app/components/primer/alpha/dialog.pcss b/app/components/primer/alpha/dialog.pcss index 6c9cef048b..e5fed4ca8c 100644 --- a/app/components/primer/alpha/dialog.pcss +++ b/app/components/primer/alpha/dialog.pcss @@ -8,6 +8,12 @@ /* Overlay */ +@property --dialog-scrollgutter { + initial-value: 0; + inherits: false; + syntax: ""; +} + /* TODO: One day this can be :has(:modal), when it is better supported */ body.has-modal { padding-right: var(--dialog-scrollgutter) !important; diff --git a/app/components/primer/dialog_helper.ts b/app/components/primer/dialog_helper.ts index e0ff666d83..99561223f2 100644 --- a/app/components/primer/dialog_helper.ts +++ b/app/components/primer/dialog_helper.ts @@ -1,4 +1,12 @@ +let dialogScrollGutterSet = false function dialogInvokerButtonHandler(event: Event) { + if (!dialogScrollGutterSet) { + this.ownerDocument.body.style.setProperty( + '--dialog-scrollgutter', + `${window.innerWidth - this.ownerDocument.body.clientWidth}px`, + ) + dialogScrollGutterSet = true; + } const target = event.target as HTMLElement const button = target?.closest('button') @@ -76,10 +84,6 @@ export class DialogHelperElement extends HTMLElement { const {signal} = (this.#abortController = new AbortController()) document.addEventListener('click', dialogInvokerButtonHandler, true) document.addEventListener('click', this, {signal}) - this.ownerDocument.body.style.setProperty( - '--dialog-scrollgutter', - `${window.innerWidth - this.ownerDocument.body.clientWidth}px`, - ) new MutationObserver(records => { for (const record of records) { if (record.target === this.dialog) {