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

@vx/text innerRef prop #338

Closed
martensm opened this issue Aug 23, 2018 · 5 comments · Fixed by #339
Closed

@vx/text innerRef prop #338

martensm opened this issue Aug 23, 2018 · 5 comments · Fixed by #339

Comments

@martensm
Copy link

martensm commented Aug 23, 2018

I need to access the rendered element's ref for the <Text> component. This is currently a showstopper for me using this in an application I'm writing. Would you be able to add support for this?

I can submit a PR but I'm not entirely sure what best approach for this would be or if this isn't a good idea for some reason. The ref could be added to the <svg>, <text> or maybe even both elements?

It appears innerRef props were added in 0955af6 but not for this component.

@loopmode
Copy link

Hi. What I am doing is this: just put a regular ref around the vx components, at a place you control (e.g. <g ref={ref => this.el = ref}>...</g>), then use el.querySelector to get to what I need.
Could it help your case too?

@hshoff
Copy link
Member

hshoff commented Aug 23, 2018

@martensm for now a work around is to pass a ref prop on your <Text />. Example: https://codesandbox.io/s/94w4pzz0r. This works because we take the rest props here: https://github.com/hshoff/vx/blob/master/packages/vx-text/src/Text.js#L85 and spread them to the <text /> here: https://github.com/hshoff/vx/blob/master/packages/vx-text/src/Text.js#L125

For consistency we'll add innerRef prop to @vx/text in the future.

@martensm
Copy link
Author

martensm commented Aug 23, 2018

Sorry, I should have been a bit more clear in the original comment. I need a ref to a real DOM node, not a React component so I'm not sure that will work unless I'm missing something here.

EDIT: Just saw your edit, that should work for now -- going to try it. I also slightly misread the codesandbox and only looked at the first part of the console.log. It's similar to what @loopmode suggested but it should be sufficient. Feel free to close this issue if you want.

@hshoff
Copy link
Member

hshoff commented Aug 23, 2018

The work around I mentioned will give you a reference to the <text/> react component instance not the dom element. The fix in #339 will give you a ref to the svg dom element that contains the text.

@martensm
Copy link
Author

Perfect! Thanks for the really quick turnaround time.

hshoff added a commit that referenced this issue Aug 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants