Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to Dialog to permit/disable page scrolling #3145

Merged
merged 10 commits into from
Oct 17, 2024

Conversation

camertron
Copy link
Contributor

@camertron camertron commented Oct 10, 2024

What are you trying to accomplish?

The SelectPanel component uses parts of the Dialog component under the hood, which comes with custom CSS that prevents the page from scrolling when the dialog is opened as a modal. This means that SelectPanels, despite behaving more like popovers, prevent page scrolling too. We'd like to enable scrolling for SelectPanels but keep the existing behavior for other dialogs.

Integration

No changes necessary in production.

List the issues that this change affects.

Closes https://github.com/github/primer/issues/4126

Risk Assessment

  • Low risk the change is small, highly observable, and easily rolled back.
  • Medium risk changes that are isolated, reduced in scope or could impact few users. The change will not impact library availability.
  • High risk changes are those that could impact customers and SLOs, low or no test coverage, low observability, or slow to rollback.

What approach did you choose and why?

I refactored our CSS rules and added a parameter to Dialog that conditionally adds the .Overlay--disableScroll CSS class to the <dialog> element. The parameter defaults to true to preserve existing behavior.

Since we can use it now, I also switched to using body:has(...) instead of the hackish body.has-modal selector for applying the scroll gutter and scroll disabling rules.

Anything you want to highlight for special attention from reviewers?

I really tried to write a test for this, but wasn't able to figure out how to simulate scrolling appropriately. If scrolling is disabled in CSS via overflow: hidden, JavaScript's scroll, scrollTo, and scrollBy functions scroll the page anyway. Firing manually-created wheel and touch events also didn't work - the page never scrolls, even when overflow is not set to hidden. If y'all have any ideas here, I'm all ears.

Accessibility

  • No new axe scan violation - This change does not introduce any new axe scan violations.

Merge checklist

- [ ] Added/updated tests

  • Added/updated documentation
  • Added/updated previews (Lookbook)
  • Tested in Chrome
  • Tested in Firefox
  • Tested in Safari
  • Tested in Edge

Take a look at the What we look for in reviews section of the contributing guidelines for more information on how we review PRs.

Copy link

changeset-bot bot commented Oct 10, 2024

🦋 Changeset detected

Latest commit: f2980ea

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@primer/view-components Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@camertron camertron marked this pull request as ready for review October 11, 2024 22:09
@camertron camertron requested review from a team as code owners October 11, 2024 22:09
@camertron camertron requested review from lukasoppermann and TylerJDev and removed request for a team October 11, 2024 22:09
Copy link
Member

@jonrohan jonrohan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:has is technically supported now, think you should try and test this on a browser that doesn't support :has just to see what a fail case might look like

@camertron
Copy link
Contributor Author

@jonrohan just verified that the failure case simply allows the page to scroll, which I don't think is a blocker. There's also a scroll gutter property that won't apply, but that also doesn't seem to affect functionality.

@camertron camertron merged commit a6bacb5 into main Oct 17, 2024
34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants