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

feat(Portal): use Ref for handling trigger refs #2219

Merged
merged 1 commit into from
Oct 20, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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