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(modal): fix scrollbar compensation in some scaling situations #3498

Merged
merged 2 commits into from Dec 5, 2019

Conversation

ymeine
Copy link
Contributor

@ymeine ymeine commented Dec 2, 2019

Now the actual width of the scrollbar is used to detect if it is present or not, instead of using the wrong hypothesis that if body's rect's width is smaller than viewport's width then there is a scrollbar. Now the difference in width is compared to the width of the scrollbar.

Closes #3448


I am sorry I am mixing the fix along with a bit of variables renaming and comments rewriting (but I felt separating commits/PRs would be too cumbersome, and at the same time the code was not self-explanatory enough).

The core of the fix really resides:

  • in compensate which now passes the scrollbar width not only to _adjustBody but also to _isPresent
  • and in _isPresent which now uses this width to refine widths comparison and more accurately determine if a scrollbar is present or not

Now the actual width of the scrollbar is used to detect if it is present or not, instead of using the wrong hypothesis that if body's rect's width is smaller than viewport's width then there is a scrollbar. Now the difference in width is compared to the width of the scrollbar.

Closes ng-bootstrap#3448
@codecov-io
Copy link

codecov-io commented Dec 2, 2019

Codecov Report

Merging #3498 into master will increase coverage by 0.25%.
The diff coverage is 44.44%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3498      +/-   ##
==========================================
+ Coverage   91.14%   91.39%   +0.25%     
==========================================
  Files          96       96              
  Lines        2800     2800              
  Branches      516      517       +1     
==========================================
+ Hits         2552     2559       +7     
+ Misses        190      183       -7     
  Partials       58       58
Flag Coverage Δ
#e2e 56.46% <44.44%> (+0.25%) ⬆️
#unit 88.24% <44.44%> (+0.25%) ⬆️
Impacted Files Coverage Δ
src/util/scrollbar.ts 71.42% <44.44%> (+43.65%) ⬆️
src/datepicker/datepicker-input.ts 96.37% <0%> (-0.03%) ⬇️
src/tooltip/tooltip.ts 98.43% <0%> (-0.03%) ⬇️
src/popover/popover.ts 100% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c8c6be9...c6493c3. Read the comment docs.

@fbasso
Copy link
Member

fbasso commented Dec 3, 2019

Just an idea, but maybe a pure css solution would be simplier:

https://stackoverflow.com/questions/1417934/how-to-prevent-scrollbar-from-repositioning-web-page

The point is to apply : padding-left: calc(100vw - 100%); on the body.

Adding uncertainty, because the scaling can make the gap just slightly smaller than a scrollbar size.

Closes ng-bootstrap#3448
@benouat benouat merged commit 3dd96da into ng-bootstrap:master Dec 5, 2019
@maxokorokov maxokorokov added this to the 5.1.5 milestone Jan 3, 2020
maxokorokov pushed a commit that referenced this pull request Jan 7, 2020
)

Now the actual width of the scrollbar is used to detect if it is present or not, instead of using the wrong hypothesis that if body's rect's width is smaller than viewport's width then there is a scrollbar. Now the difference in width is compared to the width of the scrollbar.

Adding uncertainty, because the scaling can make the gap just slightly smaller than a scrollbar size.

Closes #3448
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.

Bad scrollbar replacement on non-integer width windows
5 participants