-
-
Notifications
You must be signed in to change notification settings - Fork 78.9k
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
modal: don't add margin & padding when sticky is not full width #30621
Conversation
@muhamadamin1992 Thanks for the patch 🙂 Can you also add a test please? |
I can try) |
|
a38408f
to
f1dc149
Compare
I was add test can you review please?) |
@twbs/js-review any chance you can check this out? Wondering if this is ready for alpha 2 or 3. |
@Johann-S friendly ping for a review :) |
js/src/modal.js
Outdated
@@ -471,6 +471,10 @@ class Modal { | |||
// Adjust fixed content padding | |||
SelectorEngine.find(SELECTOR_FIXED_CONTENT) | |||
.forEach(element => { | |||
if (window.innerWidth > element.clientWidth + this._scrollbarWidth) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should move this to a private function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe better move to private function like this?
function setModalSpaces({ element, attributeName, cssPropName }) {
if (window.innerWidth > element.clientWidth + this._scrollbarWidth) {
return
}
const actualValue = element.style[attributeName]
const calculatedPadding = window.getComputedStyle(element)[cssPropName]
Manipulator.setDataAttribute(element, `bs-${cssPropName}`, actualValue)
element.style[attributeName] = `${Number.parseFloat(calculatedPadding) + this._scrollbarWidth}px`
}
and call this here like
SelectorEngine.find(SELECTOR_FIXED_CONTENT)
.forEach(element => { setModalSpaces({
element,
attributeName: 'paddingRight',
cssPropName: 'padding-right',
});
});
SelectorEngine.find(SELECTOR_STICKY_CONTENT)
.forEach(element => { setModalSpaces({
element,
attributeName: 'marginRight',
cssPropName: 'margin-right',
});
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you make the update, please? @muhamadamin1992
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes) Sorry I wrote comment above 3 weeks ago, but forgot submit(
setModalSpaces({ element, attributeName, cssPropName }) {
if (window.innerWidth > element.clientWidth + this._scrollbarWidth) {
return
}
const actualPadding = element.style[attributeName]
const calculatedPadding = window.getComputedStyle(element)[cssPropName]
Manipulator.setDataAttribute(element, cssPropName, actualPadding)
element.style[attributeName] = `${Number.parseFloat(calculatedPadding) + this._scrollbarWidth}px`
}
9fcccad
to
0253cc5
Compare
js/tests/unit/modal.spec.js
Outdated
modalEl.addEventListener('hidden.bs.modal', () => { | ||
const currentMargin = Number.parseInt(window.getComputedStyle(stickyTopEl).marginRight, 10) | ||
|
||
expect(stickyTopEl.getAttribute('data-margin-right')).toEqual(null, 'data-margin-right should be cleared after closing') | ||
expect(currentMargin).toEqual(originalMargin, 'sticky element margin should be reset after closing') | ||
done() | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the margin is not adjusted while showing modal then IMO, you should not check after the modal is hidden. It seems unnecessary 🤔
@@ -142,6 +142,30 @@ describe('Modal', () => { | |||
modal.toggle() | |||
}) | |||
|
|||
it('should not adjust the inline margin and padding of sticky and fixed elements when element do not have full width', done => { | |||
fixtureEl.innerHTML = [ | |||
'<div class="sticky-top" style="margin-right: 0px; padding-right: 0px; width: calc(100vw - 50%)"></div>', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While debugging I found that the test was failed because the clientWidth
of the element
was greater than window.innerWidth
. So I changed it to width: calc(100vw - 50%)
. I am not sure about it, seems like a hack to me 😄
* Add a new offcanvas component * offcanvas.js: switch to string constants and `event.key` * Remove unneeded code * Sass optimizations * Fixes Make sure the element is hidden and not offscreen when inactive fix close icon negative margins Add content in right & bottom examples Re-fix bottom offcanvas height not to cover all viewport * Wording tweaks * update tests and offcanvas class * separate scrollbar functionality and use it in offcanvas * Update .bundlewatch.config.json * fix focus * update btn-close / fix focus on close * add aria-modal and role return focus on trigger when offcanvas is closed change body scrolling timings * move common code to reusable functions * add aria-labelledby * Replace lorem ipsum text * fix focus when offcanvas is closed * updates * revert modal, add tests for scrollbar * show backdrop by default * Update offcanvas.md * Update offcanvas CSS to better match modals - Add background-clip for borders - Move from outline to border (less clever, more consistent) - Add scss-docs in vars * Revamp offcanvas docs - Add static example to show and explain the components - Split live examples and rename them - Simplify example content - Expand docs notes elsewhere - Add sass docs * Add .offcanvas-title instead of .modal-title * Rename offcanvas example to offcanvas-navbar to reflect it's purpose * labelledby references title and not header * Add default shadow to offcanvas * enable offcanvas-body to fill all the remaining wrapper area * Be more descriptive, on Accessibility area * remove redundant classes * ensure in case of an already open offcanvas, not to open another one * bring back backdrop|scroll combinations * bring back toggling class * refactor scrollbar method, plus tests * add check if element is not full-width, according to #30621 * revert all in modal * use documentElement innerWidth * Rename classes to -start and -end Also copyedit some docs wording * omit some things on scrollbar * PASS BrowserStack tests -- IOS devices, Android devices and Browsers on Mac, hide scrollbar by default and appear it, only while scrolling. * Rename '_handleClosing' to '_addEventListeners' * change pipe usage to comma * change Data.getData to Data.get Co-authored-by: XhmikosR <[email protected]> Co-authored-by: Martijn Cuppens <[email protected]> Co-authored-by: Mark Otto <[email protected]>
fix #27071