Skip to content

Commit

Permalink
fix(Modal): add/remove dimmer classes in raf
Browse files Browse the repository at this point in the history
  • Loading branch information
levithomason committed Aug 28, 2017
1 parent b60e2aa commit 159eb92
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions src/modules/Modal/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,21 +195,8 @@ class Modal extends Component {

handlePortalMount = (e) => {
debug('handlePortalMount()')
const { dimmer } = this.props
const mountNode = this.getMountNode()

if (dimmer) {
debug('adding dimmer')
mountNode.classList.add('dimmable')
mountNode.classList.add('dimmed')

if (dimmer === 'blurring') {
debug('adding blurred dimmer')
mountNode.classList.add('blurring')
}
}

this.setPosition()
this.setPositionAndClassNames()

const { onMount } = this.props
if (onMount) onMount(e, this.props)
Expand Down Expand Up @@ -237,11 +224,26 @@ class Modal extends Component {

handleRef = c => (this.ref = c)

setPosition = () => {
setPositionAndClassNames = () => {

if (this.ref) {
const { dimmer } = this.props
const mountNode = this.getMountNode()
const { height } = this.ref.getBoundingClientRect()

if (dimmer) {
mountNode.classList.add('dimmable')
mountNode.classList.add('dimmed')

if (dimmer === 'blurring') {
mountNode.classList.add('blurring')
}
} else {
mountNode.classList.add('dimmable')
mountNode.classList.add('dimmed')
mountNode.classList.add('blurring')
}

const marginTop = -Math.round(height / 2)
const scrolling = height >= window.innerHeight

Expand All @@ -264,7 +266,7 @@ class Modal extends Component {
if (Object.keys(newState).length > 0) this.setState(newState)
}

this.animationRequestId = requestAnimationFrame(this.setPosition)
this.animationRequestId = requestAnimationFrame(this.setPositionAndClassNames)
}

renderContent = (rest) => {
Expand Down

0 comments on commit 159eb92

Please sign in to comment.