-
Notifications
You must be signed in to change notification settings - Fork 129
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
Avoid swallowing children's ref property, if it's set. Fixes #83 #87
base: master
Are you sure you want to change the base?
Conversation
@@ -149,7 +149,10 @@ var HammerComponent = function (_React$Component) { | |||
|
|||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I second using a unique prop name such as refCallback
as to avoid conflict with React special props.
Guys, so what ? |
No description provided.