-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Support .attrs({ ref: ... })
#1720
Conversation
Generated by 🚫 dangerJS |
I think this is a great idea, but it potentially conflicts with what This subtle feature would be a little confusing by calling the attribute |
Well the problem is the directly wrapped element gets either key or innerKey depending on its type. Otherwise I'm fine with either. |
Ah, the ref error is enzymejs/enzyme#1504 |
Description cleaned up, rebased and squashed, tests working (was actually just @kitten I'm going to stick with The confusion is basically over whether you feel |
.attrs({ ref: ... })
.attrs({ ref: ... })
Alright so I looked into this for v4 and I don't think it's possible without adding another component layer above due to how forwardRef works. If you want to do that for your project, that's fine and it'll probably work but we wouldn't want to add it to core due to the perf impact for everyone who isn't using that functionality. |
Fair enough. I haven't looked into it with v4, but I suppose you could also keep the current When you say "another component layer above", you mean a raw component, not a styled component; something like this? const A = styled.input`color: red`;
const B = (props) => (
<A
{...props}
ref={props.refList[props.refIndex]}
onKeyPress={props.handleFocus[props.refIndex + 1]}
/>
); It always feels like I'm doing something wrong when I do that, but I suppose it can't be helped here. |
Well so the issue with forwardRef is the |
Sure, but the inner component also has access to the real component to give to |
I mean I tried redoing your PR against develop and it just didn't work with forwardRef. You're welcome to give it another try though if you can get it working and not regress performance. |
Support using
ref
inside.attrs()
argument, to dynamically generate a ref.Basically the goal is implementing tab order like behavior in react-native:
In theory
key
could be supported in the same way, but that can be a separate PR if wanted.