Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Decouple Modal's scrollbar functionality#33245

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
XhmikosR merged 2 commits intotwbs:mainfromGeoSot:use-scollbarjs-on-modal
Apr 11, 2021

Conversation

GeoSot
Copy link
Member

@GeoSotGeoSot commentedMar 2, 2021
edited
Loading

Scorllbar. js is the exact same code ofmodal.js which handles all the scrollbar functionality.
It is extracted, self-tested and used on Offcanvas with success, and it can be used on modal.js through methods

preview

@GeoSotGeoSot requested review froma team ascode ownersMarch 2, 2021 22:49
@GeoSot
Copy link
MemberAuthor

GeoSot commentedMar 2, 2021
edited
Loading

Please can somebody explain me the usage and the checks of this code block?

if((!isBodyOverflowing&&isModalOverflowing&&!isRTL())||(isBodyOverflowing&&!isModalOverflowing&&isRTL())){this._element.style.paddingLeft=`${scrollbarWidth}px`}if((isBodyOverflowing&&!isModalOverflowing&&!isRTL())||(!isBodyOverflowing&&isModalOverflowing&&isRTL())){this._element.style.paddingRight=`${scrollbarWidth}px`}

@GeoSotGeoSotforce-pushed theuse-scollbarjs-on-modal branch fromeef7dd0 toeac1d74CompareMarch 2, 2021 22:57
@GeoSotGeoSotforce-pushed theuse-scollbarjs-on-modal branch 2 times, most recently fromd1d9489 to02404f7CompareMarch 18, 2021 08:23
@GeoSotGeoSotforce-pushed theuse-scollbarjs-on-modal branch from6d51216 to21dd1e4CompareMarch 23, 2021 23:38
@GeoSotGeoSotforce-pushed theuse-scollbarjs-on-modal branch from21dd1e4 to582d484CompareMarch 31, 2021 09:55
@GeoSotGeoSotforce-pushed theuse-scollbarjs-on-modal branch 2 times, most recently from54f11b1 tofc47b68CompareApril 6, 2021 16:04
@mdomdo requested a review fromrohit2sharma95April 7, 2021 05:03
@alpadev
Copy link
Contributor

alpadev commentedApr 7, 2021
edited
Loading

Please can somebody explain me the usage and the checks of this code block?

if((!isBodyOverflowing&&isModalOverflowing&&!isRTL())||(isBodyOverflowing&&!isModalOverflowing&&isRTL())){this._element.style.paddingLeft=`${scrollbarWidth}px`}if((isBodyOverflowing&&!isModalOverflowing&&!isRTL())||(!isBodyOverflowing&&isModalOverflowing&&isRTL())){this._element.style.paddingRight=`${scrollbarWidth}px`}

I can be wrong about this but I think this got something to do with issues about modal shifting/jumping or not being centered with/without scrollbars on the body.

Found it:#14933

But that's not everything.. I decided to go down the rabbit hole.

So let's begin:

isBodyOverflowing is usinggetBoundingClientRect() to check if the body's width is less than the window'sinnerWidth ("the viewport width including the size of a rendered scroll bar (if any)"). My guess, this was done to see if there is a scrollbar on the document root or not. (I was a bit confused as we compare widths but yeah - the overflow means on the y-axis.)

isModalOverflowing is checking if the element'sscrollHeight ("the height of an element's content, including content not visible on the screen due to overflow.") is bigger than the document root'sclientHeight ("the viewport height excluding the size of a rendered scroll bar (if any)."). My guess, this was done to see if the modal is higher than the document root and would cause a scrollbar.

ThepaddingLeft is set to shift the modal dialog to the right and create a spacing (the size of a scrollbar) and vice versa. My guess, this was done to compensate for a scrollbar on the opposite side.

Thoughts:

So I checked the examples in our documentation and this doesn't seem to work properly. (This is true for older Bootstrap versions too. Maybe it did at some point tho.) The result, the dialog isn't centered properly. (At least in FF and Chrome on Windows. Safari 14 and Chrome on Android is fine tho.)
This is partly caused by the fact that when we meassurescrollHeight the dialog isn't yet visible so it's 0 andisModalOverflowing is always false.

AboutisRTL(). If I adddir="rtl" to the html tag the body's scrollbar is still on the right side. The modal's scrollbar on the left. 🤯 Not sure how that is handled when the OS is set rtl.

In general without those extra paddings it seems to work fine for me.

GeoSot reacted with heart emoji

@GeoSot
Copy link
MemberAuthor

@alpadev what a lovely approach 🛩️

129 line this._adjustDialog() is pointless for sure, cause it hidden as you told

I am not sure for the other two usages (resize 304 / handleUpdate 211)
Did you test it on resize too?

And one more cherry, that is out of this scope: lines 405|407 & 414|419 seems redundant as elementoverflow-y isauto

alpadev reacted with heart emoji

@alpadev
Copy link
Contributor

I am not sure for the other two usages (resize 304 / handleUpdate 211)
Did you test it on resize too?

So I made a codepen for the case when the body doesn't overflow. SinceisModalOverflowing is false there is no padding added so it looks good. If I resizeisModalOverflowing becomes true and it's adding padding-left that makes it not centered. (Case!isBodyOverflowing && isModalOverflowing && !isRTL())

I tried it on the documentation page. There is padding-right added because the body does overflow (CaseisBodyOverflowing && !isModalOverflowing && !isRTL()).

There is no case for when both are overflowing or both are not overflowing.

Also the_adjustDialog is only adding paddings but never take them away. So at some point it's adding paddings making it uncentered and they will never go away until closed.

@alpadev
Copy link
Contributor

And one more cherry, that is out of this scope: lines 405|407 & 414|419 seems redundant as elementoverflow-y isauto

My guess this was added so in case when you click on a static backdrop and it would do this little animation, it's not causing any scrollbars on the backdrop if it reaches outside but not sure.

GeoSot reacted with thumbs up emoji

@alpadev
Copy link
Contributor

Likely related:#31845

@GeoSotGeoSotforce-pushed theuse-scollbarjs-on-modal branch 2 times, most recently fromee866fe to8538f88CompareApril 7, 2021 09:35
@GeoSot
Copy link
MemberAuthor

GeoSot commentedApr 7, 2021
edited
Loading

@alpadev REALLY HELPFUL
I will not touch it on this pr but nice to have it in mind too
Issue created#33580

Any other comments over the changes?

Copy link
Contributor

@alpadevalpadev left a comment
edited
Loading

Choose a reason for hiding this comment

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

Everything else LGTM 👍

This comment was marked as resolved.

Copy link
MemberAuthor

@GeoSotGeoSotApr 8, 2021
edited
Loading

Choose a reason for hiding this comment

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

I wish would be me :P

In this PR I just remove the copied the code, out of modal.
It was written like this. I am trying to finish this and a new issue waits#33580 (afraid of how many tests need to tweak)

This comment was marked as resolved.

@rohit2sharma95
Copy link
Contributor

My guess this was added so in case when you click on a static backdrop and it would do this little animation

That animation is transform scale, and transforming any element does not affect the layout of the real DOM element 🤔

Copy link
Contributor

@rohit2sharma95rohit2sharma95Apr 9, 2021
edited
Loading

Choose a reason for hiding this comment

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

I was just thinking if the value was not stored on the data attribute then why the style prop it is being removed from the element? 🤔

Since if thevalue here:

constvalue=Manipulator.getDataAttribute(element,styleProp)

isundefined, it means that the style prop was not added by the bootstrap and that's why should not be removed (that style prop might be present on the dom element already added by the end-user)

Copy link
MemberAuthor

@GeoSotGeoSotApr 9, 2021
edited
Loading

Choose a reason for hiding this comment

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

you are right on this.
I will keep it as default, and we can discuss it on a next PR

@GeoSotGeoSotforce-pushed theuse-scollbarjs-on-modal branch from0302957 toc197559CompareApril 9, 2021 11:40
@alpadev
Copy link
Contributor

alpadev commentedApr 9, 2021
edited
Loading

My guess this was added so in case when you click on a static backdrop and it would do this little animation

That animation is transform scale, and transforming any element does not affect the layout of the real DOM element 🤔

@rohit2sharma95 Check for yourself 🙂https://jsfiddle.net/z1pb7c9w/

@GeoSotGeoSotforce-pushed theuse-scollbarjs-on-modal branch fromc197559 to28e0101CompareApril 10, 2021 23:38
@XhmikosRXhmikosR changed the titleDecouple scrollbar functionality on Modal.js using Scrollbar.jsDecouple Modal's scrollbar functionalityApr 11, 2021
@XhmikosRXhmikosR merged commit7b7f4a5 intotwbs:mainApr 11, 2021
@XhmikosR
Copy link
Member

XhmikosR commentedApr 11, 2021
edited
Loading

@GeoSot BrowserStack tests broke. Please temporarily push any PRs that are not made from an upstream branch so that you check if everything is fine before we merge :)

EDIT: NVM, it seems it was just a fluke. That being said, let's make sure BrowserStack tests pass for PRs coming from your fork.

@GeoSotGeoSot deleted the use-scollbarjs-on-modal branchApril 11, 2021 19:08
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

2 more reviewers

@alpadevalpadevalpadev approved these changes

@rohit2sharma95rohit2sharma95rohit2sharma95 approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

4 participants

@GeoSot@alpadev@rohit2sharma95@XhmikosR

[8]ページ先頭

©2009-2025 Movatter.jp