Avoid swallowing children's ref property, if it's set. Fixes #83#87
Avoid swallowing children's ref property, if it's set. Fixes #83#87raulrene wants to merge 3 commits intoJedWatson:masterfrom
Conversation
| var self = this; | ||
| props.ref = function (domElement) { | ||
| if (self.props.ref) { | ||
| if (self.props.children && self.props.children.ref) { |
There was a problem hiding this comment.
I'm not sure, whether this is the best solution because ref is a special prop.
Actually, the problem is not only that the child's ref is swallowed but also that self.props.ref will always return undefined (and I would expect the same for self.props.children.ref). A ref callback added to the <Hammer> component will still be executed (but independently, i.e. it will never be called here and if it did, it would be executed twice).
Maybe it is possible to add another prop to the official interface of the Hammer component that will be executed here. Something like
<Hammer
onPan={onPanHandler}
refCallback={domElement => myRef = domElement /* domElement will be the child, i.e. the div below */}
>
<div>something cool</div>
</Hammer>and then
props.ref = function(domElement) {
if (self.props.refCallback) {
self.props.refCallback(domElement);
}
self.domElement = domElement;
}This would still swallow the child's ref but if it's documented that refCallback of the Hammer component will get passed the actual child element, one can just place the child's ref there and it will work as expected. This would also avoid trying to access the ref prop directly.
There was a problem hiding this comment.
I second using a unique prop name such as refCallback as to avoid conflict with React special props.
|
Guys, so what ? |
No description provided.