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

fix (react-dialog): Use consistent rounding for clientHeight and innerHeight #32480

Merged
merged 2 commits into from
Sep 10, 2024

Conversation

CampbellOwen
Copy link
Contributor

@CampbellOwen CampbellOwen commented Sep 6, 2024

Previous Behavior

When calculating whether scrollbars are present, we compare the body's clientHeight to the window's innerHeight.

In the case when this height is a fractional value, clientHeight rounds to the nearest integer whereas innerHeight always rounds down. This means when the body is set to 100% height and the browser is at a fractional height (usually due to a non-100% zoom factor), clientHeight often reports being 1 pixel taller than innerHeight.

This causes the scrollbar-gutter: stable style to be added, which reserves space for the non-existent scrollbar, shifting the layout.

Repro:

https://stackblitz.com/edit/u47vqq?file=index.html

image
image

New Behavior

Match innerHeight's rounding behaviour by using body.getBoundingClientRect().height and manually rounding down.

According to mdn, getBoundingClientRect() is the equivalent to clientHeight except it returns the real fractional value: https://developer.mozilla.org/en-US/docs/Web/API/Element/clientHeight

Fixes #32481

@CampbellOwen CampbellOwen requested a review from a team as a code owner September 6, 2024 18:29
Copy link
Contributor

@bsunderhus bsunderhus left a comment

Choose a reason for hiding this comment

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

LGTM ✅ I'm not a big fan of the extra style recalc that this introduces but I believe it is unavoidable if we want to fix #32481

Thanks for the PR @CampbellOwen 💪🏻

@emmayjiang emmayjiang merged commit 01cacb0 into microsoft:master Sep 10, 2024
10 checks passed
marcosmoura added a commit to marcosmoura/fluentui that referenced this pull request Sep 12, 2024
* master: (77 commits)
  fix(react-drawer): update scroll state when children changes (microsoft#32818)
  feat(react-storybook-addon): improve addon to more readable names (microsoft#32815)
  chore: cleanup react-carousel-preview (microsoft#32475)
  feat(storybook): add rtl/ltr toggle storybook addon (microsoft#32814)
  Carousel: Storybook updates and fixing exports/focus (microsoft#32457)
  release: applying package updates - react v8
  release: applying package updates - web-components
  Update d3 dependency versions to 3.x.x and 4.x.x (microsoft#32463)
  RFC: Extended Design Tokens for Fluent UI React (microsoft#32058)
  update doc to reflect setTheme function change (microsoft#32490)
  fix (react-dialog): Use consistent rounding for clientHeight and innerHeight (microsoft#32480)
  fix(public-doscite-v9): global styles should not be applied to story elements (microsoft#32472)
  feat(workspace-plugin): implement verify-packaging executor (microsoft#32403)
  release: applying package updates - react-components
  Add strokeDasharray property when optimizeLargeData is true (microsoft#32494)
  fix(TreeItemLayout): Actions should not unmount between successive mouse events (microsoft#32477)
  release: applying package updates - react v8
  bugfix(react-tree): recover from tabIndex=-1 when TreeItem is removed (microsoft#32442)
  Fix onResolveSuggestions not being called after component is remounted in react 18 strict mode (microsoft#28227)
  fix(codeowners): update most packages owned by cxe-red with cxe-prg (microsoft#32445)
  ...
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.

[Bug]: react-dialog shifting layout when body is a fractional height
5 participants