Skip to content

Commit

Permalink
feat(Portal): use Ref for handling trigger refs (#2219)
Browse files Browse the repository at this point in the history
  • Loading branch information
layershifter authored and levithomason committed Oct 20, 2017
1 parent 470c7b5 commit 1947564
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions src/addons/Portal/Portal.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import _ from 'lodash'
import PropTypes from 'prop-types'
import { Children, cloneElement } from 'react'
import React, { Children, cloneElement } from 'react'
import ReactDOM from 'react-dom'

import {
Expand All @@ -11,6 +11,7 @@ import {
makeDebugger,
META,
} from '../../lib'
import Ref from '../Ref'

const debug = makeDebugger('portal')

Expand Down Expand Up @@ -414,24 +415,23 @@ class Portal extends Component {
_.invoke(this.props, 'onUnmount', null, this.props)
}

handleRef = (c) => {
// TODO: Replace findDOMNode with Ref component when it will be merged
this.triggerNode = ReactDOM.findDOMNode(c) // eslint-disable-line react/no-find-dom-node
}
handleRef = c => (this.triggerNode = c)

render() {
const { trigger } = this.props

if (!trigger) return null

return cloneElement(trigger, {
ref: this.handleRef,
onBlur: this.handleTriggerBlur,
onClick: this.handleTriggerClick,
onFocus: this.handleTriggerFocus,
onMouseLeave: this.handleTriggerMouseLeave,
onMouseEnter: this.handleTriggerMouseEnter,
})
return (
<Ref innerRef={this.handleRef}>
{cloneElement(trigger, {
onBlur: this.handleTriggerBlur,
onClick: this.handleTriggerClick,
onFocus: this.handleTriggerFocus,
onMouseLeave: this.handleTriggerMouseLeave,
onMouseEnter: this.handleTriggerMouseEnter,
})}
</Ref>
)
}
}

Expand Down

0 comments on commit 1947564

Please sign in to comment.