Skip to content

Commit

Permalink
reduce cost of style calc+layout in --dialog-scrollgutter
Browse files Browse the repository at this point in the history
Co-authored-by: Aaron Ballard <[email protected]>
Co-authored-by: AdamShwert <[email protected]>
Co-authored-by: Arelia Jones <[email protected]>
Co-authored-by: Ariel Valentin <[email protected]>
Co-authored-by: Chris Gavin <[email protected]>
Co-authored-by: Cody Bodfield <[email protected]>
Co-authored-by: Daniel Colson <[email protected]>
Co-authored-by: Daniel Garman <[email protected]>
Co-authored-by: Dusty Greif <[email protected]>
Co-authored-by: Erinna Chen <[email protected]>
Co-authored-by: George Brocklehurst <[email protected]>
Co-authored-by: Jibran Garcia <[email protected]>
Co-authored-by: Jonathan Fuchs <[email protected]>
Co-authored-by: Kate Higa <[email protected]>
Co-authored-by: Manuel Puyol <[email protected]>
Co-authored-by: Matthew Costabile <[email protected]>
Co-authored-by: Matthew Reyes <[email protected]>
Co-authored-by: Melissa Pastore <[email protected]>
Co-authored-by: Ned Schwartz <[email protected]>
Co-authored-by: Phill MV <[email protected]>
Co-authored-by: Raffaele Di Fazio <[email protected]>
Co-authored-by: Sarah Vessels <[email protected]>
Co-authored-by: Simon Taranto <[email protected]>
  • Loading branch information
1 parent 50fe6a5 commit 9e8b6fd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
6 changes: 6 additions & 0 deletions app/components/primer/alpha/dialog.pcss
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@

/* Overlay */

@property --dialog-scrollgutter {
initial-value: 0;
inherits: false;
syntax: "<length>";
}

/* TODO: One day this can be :has(:modal), when it is better supported */
body.has-modal {
padding-right: var(--dialog-scrollgutter) !important;
Expand Down
12 changes: 8 additions & 4 deletions app/components/primer/dialog_helper.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
let dialogScrollGutterSet = false
function dialogInvokerButtonHandler(event: Event) {
if (!dialogScrollGutterSet) {
this.ownerDocument.body.style.setProperty(

Check failure on line 4 in app/components/primer/dialog_helper.ts

View workflow job for this annotation

GitHub Actions / npm / Canary

'this' implicitly has type 'any' because it does not have a type annotation.
'--dialog-scrollgutter',
`${window.innerWidth - this.ownerDocument.body.clientWidth}px`,

Check failure on line 6 in app/components/primer/dialog_helper.ts

View workflow job for this annotation

GitHub Actions / npm / Canary

'this' implicitly has type 'any' because it does not have a type annotation.
)
dialogScrollGutterSet = true;
}
const target = event.target as HTMLElement
const button = target?.closest('button')

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 9e8b6fd

Please sign in to comment.