Skip to content

Commit

Permalink
fix(Modal): Only set position when modal is open
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffcarbs committed Oct 21, 2016
1 parent b3d47ab commit 9ae0b24
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions src/modules/Modal/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,13 @@ class Modal extends Component {

state = {}

componentDidMount() {
debug('componentDidMount()')
this.setPosition()
}

componentWillUnmount() {
debug('componentWillUnmount()')
this.handleUnmount()
this.handlePortalUnmount()
}

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

Expand All @@ -101,17 +96,21 @@ class Modal extends Component {
mountNode.classList.add('blurring')
}
}

this.setPosition()
}

handleUnmount = () => {
debug('handleUnmount()')
handlePortalUnmount = () => {
debug('handlePortalUnmount()')

const mountNode = this.getMountNode()

// Always remove all dimmer classes.
// If the dimmer value changes while the modal is open,
// then removing its current value could leave cruft classes previously added.
mountNode.classList.remove('blurring', 'dimmable', 'dimmed', 'scrollable')

cancelAnimationFrame(this.animationRequestId)
}

getMountNode = () => {
Expand Down Expand Up @@ -141,7 +140,7 @@ class Modal extends Component {
}
}

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

render() {
Expand Down Expand Up @@ -193,8 +192,8 @@ class Modal extends Component {
{...portalProps}
className={dimmerClasses}
mountNode={this.getMountNode()}
onMount={this.handleMount}
onUnmount={this.handleUnmount}
onMount={this.handlePortalMount}
onUnmount={this.handlePortalUnmount}
>
{modalJSX}
</Portal>
Expand Down

0 comments on commit 9ae0b24

Please sign in to comment.