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

How can I programmatically change focus with ref? Or at least change a tabIndex order? #1917

Closed
4 tasks done
alexfrize opened this issue Jul 30, 2021 · 4 comments · Fixed by #2673
Closed
4 tasks done
Assignees
Labels
Note: Good first issue 🤩 Good issue for new contributors

Comments

@alexfrize
Copy link

alexfrize commented Jul 30, 2021

Bugs and Questions

Checklist

  • This is not a victory-native specific issue. (Issues that only appear in victory-native should be opened here)

  • I have read through the FAQ and Guides before asking a question

  • I am using the latest version of Victory

  • I've searched open issues to make sure I'm not opening a duplicate issue

The Problem

This question is about accessibility.

Here is the code:
https://codesandbox.io/s/angry-hermann-13md9

Currently when the user presses TAB multiple times here is what happens: focus changes to a border then to a button inside, then another border. And after all the borders and buttons it starting to set focus on bars inside the border.

How can I change the logic to change it to this:
border->internal bar->button
Or, even better: border->border-> border, but when the user press ENTER on any border, it should focus on the internal bar (element inside the border).

Reproduction

https://codesandbox.io/s/angry-hermann-13md9

In the example above refs I currently have:
barRef_VictoryBar.current does not have a focus() method,
and barRef_Bar.current is null (initial value)

@becca-bailey
Copy link
Contributor

becca-bailey commented Jul 30, 2021

@alexfrize Thanks for calling out this issue! I have run into similar issues with refs, so perhaps we can work on some enhancements in order to better support refs and tabIndex props. At the moment, only the props that are documented for each victory component are getting passed through to the underlying svg component.

For now, you can work around this by using the custom component props on VictoryBar. For example:

<VictoryBar dataComponent={<Bar pathComponent={<path tabIndex={1} ref={ref} />} />} />

It also appears that the Bar component supports a tabIndex prop, but it may not handle refs correctly. https://formidable.com/open-source/victory/docs/victory-primitives#bar

@becca-bailey becca-bailey added Note: Good first issue 🤩 Good issue for new contributors improvement labels Jul 30, 2021
@alexfrize
Copy link
Author

Thank you!

@alexfrize
Copy link
Author

VictoryBar renders the whole data set, so in this case, if I set ref to a Bar, only the last bar will be in focus. Is it possible to split the group and set focus to each of the bars programatically?

@becca-bailey
Copy link
Contributor

There's not anything built into Victory to do this, but you can pass arbitrary properties into the data prop in any chart that can be accessed in a custom child component. I'll need to try this out, but perhaps you can pass a ref through that way?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Note: Good first issue 🤩 Good issue for new contributors
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants