Skip to content

Commit 61367cc

Browse files
committed
fix: allow callee to have ref on child of tooltip
1 parent c8126d5 commit 61367cc

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/tooltip.jsx

+8-3
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,13 @@ class Tooltip extends Component {
4343

4444
return (
4545
<span className={this.props.wrapperClassName}>
46-
{cloneElement(Children.only(this.props.children), {
47-
ref: 'target',
46+
{cloneElement(child, {
47+
ref: (node) => {
48+
this._target = node
49+
if (typeof child.ref === 'function') {
50+
child.ref(node)
51+
}
52+
},
4853
...actionProps,
4954
})}
5055
{this._popper()}
@@ -58,7 +63,7 @@ class Tooltip extends Component {
5863
const props = _.omit(this.props, 'wrapperClassName', 'children')
5964

6065
return (
61-
<PortalPopper getTargetNode={() => this.refs.target} {...props} />
66+
<PortalPopper getTargetNode={() => this._target} {...props} />
6267
)
6368
}
6469
}

src/tooltip.spec.jsx

+6
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ describe('<Tooltip />', () => {
6565
expect(onMouseOut).to.be.calledWith(...args)
6666
})
6767

68+
it('allows callee to have ref on child', () => {
69+
const ref = sinon.spy()
70+
mount(createComponent({}, <div ref={ref} />))
71+
expect(ref).to.be.called
72+
})
73+
6874
describe('when visible is not explicitly specified', () => {
6975
let component
7076
beforeEach(() => {

0 commit comments

Comments
 (0)