Skip to content

Commit

Permalink
Merge pull request #623 from GoOz/feat/bodyScrollLockModal
Browse files Browse the repository at this point in the history
feat: ✨ Add Body Scroll Lock for Modals
  • Loading branch information
CPatchane authored Oct 5, 2018
2 parents 1f3f87a + 1a1458f commit a03d9fd
Show file tree
Hide file tree
Showing 3 changed files with 704 additions and 746 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
},
"dependencies": {
"babel-preset-cozy-app": "^0.3.1",
"body-scroll-lock": "^2.5.8",
"classnames": "^2.2.5",
"date-fns": "^1.28.5",
"hammerjs": "^2.0.8",
Expand Down
5 changes: 3 additions & 2 deletions react/Modal/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import migrateProps from '../helpers/migrateProps'
import palette from '../../stylus/settings/palette.json'
import Portal from 'preact-portal'
import uniqueId from 'lodash/uniqueId'
import { disableBodyScroll, clearAllBodyScrollLocks } from 'body-scroll-lock'

class AnimatedContentHeader extends Component {
render() {
Expand Down Expand Up @@ -56,12 +57,12 @@ class ModalContent extends Component {
this.scrollingContent.addEventListener('scroll', this.handleScroll, {
passive: true
})
document.body.classList.add('has-modal')
disableBodyScroll(this.scrollingContent)
}

componentWillUnmount() {
this.scrollingContent.removeEventListener('scroll', this.handleScroll)
document.body.classList.remove('has-modal')
clearAllBodyScrollLocks()
}

handleScroll = () => {
Expand Down
Loading

0 comments on commit a03d9fd

Please sign in to comment.