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

modal: don't add margin & padding when sticky is not full width #30621

Merged
merged 5 commits into from
Feb 23, 2021

Conversation

muhamadamin1992
Copy link
Contributor

@muhamadamin1992 muhamadamin1992 commented Apr 20, 2020

fix #27071

@muhamadamin1992 muhamadamin1992 requested a review from a team as a code owner April 20, 2020 18:24
@XhmikosR XhmikosR added the js label May 14, 2020
@XhmikosR
Copy link
Member

@muhamadamin1992 Thanks for the patch 🙂 Can you also add a test please?

@muhamadamin1992
Copy link
Contributor Author

@muhamadamin1992 Thanks for the patch Can you also add a test please?

I can try)

@muhamadamin1992
Copy link
Contributor Author

muhamadamin1992 commented Jun 7, 2020

@muhamadamin1992 Thanks for the patch 🙂 Can you also add a test please?
The project already has a test that may conflict with my code. What should I do? https://github.com/twbs/bootstrap/blob/main/js/tests/unit/modal.spec.js#L114

@muhamadamin1992
Copy link
Contributor Author

@muhamadamin1992 Thanks for the patch 🙂 Can you also add a test please?

I was add test can you review please?)

@mdo
Copy link
Member

mdo commented Sep 16, 2020

@twbs/js-review any chance you can check this out? Wondering if this is ready for alpha 2 or 3.

@XhmikosR
Copy link
Member

XhmikosR commented Nov 3, 2020

@Johann-S friendly ping for a review :)

@XhmikosR XhmikosR changed the title don't add margin and padding when sticky not full width modal: don't add margin and padding when sticky is not full width Nov 9, 2020
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) {
Copy link
Member

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?

Copy link
Contributor Author

@muhamadamin1992 muhamadamin1992 Nov 21, 2020

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',
  });
});

Copy link
Collaborator

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

Copy link
Contributor Author

@muhamadamin1992 muhamadamin1992 Dec 12, 2020

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`
}

Comment on lines 163 to 170
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()
})
Copy link
Collaborator

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>',
Copy link
Collaborator

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 😄

GeoSot added a commit to GeoSot/bootstrap that referenced this pull request Feb 24, 2021
XhmikosR pushed a commit to GeoSot/bootstrap that referenced this pull request Mar 2, 2021
XhmikosR added a commit that referenced this pull request Mar 2, 2021
* 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]>
XhmikosR pushed a commit that referenced this pull request Oct 22, 2021
modal: don't add margin & padding when sticky is not full width
XhmikosR pushed a commit that referenced this pull request Oct 22, 2021
modal: don't add margin & padding when sticky is not full width
XhmikosR pushed a commit that referenced this pull request Oct 26, 2021
modal: don't add margin & padding when sticky is not full width
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.

Modal script adds margin-right and padding-right for .sticky-top
4 participants