question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature Request: Allow to move focus across items of a grid

See original GitHub issue

Motivation

I was building an interface with a cards grid and wanted the user to be able to navigate in these cards nonlinearly using the arrow keys. I looked for something to help me in the documentation and here in the repository and even found that in the past Reakit had a Grid component but it was removed. Anyway, I implemented a solution by myself but here is the proposal for you to evaluate.

Current behavior

Currently, Rover components can be grouped horizontally or vertically and the useRoverState hook will move focus across items linearly, respecting the chosen orientation.

function Component() {
  const rover = useRoverState();

  return (
    <Group>
      <Rover {...rover} as={Tabbable}></Rover>
      <Rover {...rover} as={Tabbable}></Rover>
      <Rover {...rover} as={Tabbable}></Rover>
    </Group>
  )
}

cats

Proposal

Add a new “grid” value to the orientation option of useRoverState hook that lets you move focus freely in any direction through the Rover components in a grid.

function Component() {
  const rover = useRoverState({
    orientation: 'grid',
    columns: 3 // Number of columns for hook calculate which item is above and below.
  });

  return (
    <Group className="grid">
      <Rover {...rover} as={Tabbable}></Rover>
      <Rover {...rover} as={Tabbable}></Rover>
      <Rover {...rover} as={Tabbable}></Rover>
      <Rover {...rover} as={Tabbable}></Rover>
      <Rover {...rover} as={Tabbable}></Rover>
      <Rover {...rover} as={Tabbable}></Rover>
    </Group>
  )
}

cats2

Possible implementations

I think this answer in StackOverflow can help you when implementing the new logic.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
Saeriscommented, Sep 17, 2019

Would there be any way we could make this work with CSS Grid? I’m not thrilled about the idea of specifying rows and columns in the HTML markup, because then re-flow logic would have to be calculated as different break-points are reached.

I realize that would be far from simple to implement, I just have to point it out as a major concern of mine for implementing a responsive arrow-key navigable grid.

2reactions
diegohazcommented, Sep 17, 2019

Thank you for opening the issue, @httpiago!

A Grid component is planned. It will follow the WAI-ARIA Grid Pattern. And the API I’m thinking on is something like this:

const grid = useGridState();
return (
  <Grid {...grid}>
    <GridRow {...grid}>
      <GridCell {...grid}>Row 1 / Col 1</GridCell>
      <GridCell {...grid}>Row 1 / Col 2</GridCell>
      <GridCell {...grid}>Row 1 / Col 3</GridCell>
    </GridRow>
    <GridRow {...grid}>
      <GridCell {...grid}>Row 2 / Col 1</GridCell>
      <GridCell {...grid}>Row 2 / Col 2</GridCell>
      <GridCell {...grid}>Row 2 / Col 3</GridCell>
    </GridRow>
  </Grid>
);

It’s open for discussion though. So feel free to suggest a different idea.

cc @Saeris

Read more comments on GitHub >

github_iconTop Results From Across the Web

Set up a Focus on iPhone - Apple Support
Focus is a feature that helps you reduce distractions and set boundaries. When you want to concentrate on a specific activity, you can...
Read more >
How to Use the Focus Subsystem - Oracle Help Center
Move the focus from component to component using the Tab key. You will notice that when the focus moves into the text area,...
Read more >
focus - CSS: Cascading Style Sheets - MDN Web Docs - Mozilla
The :focus CSS pseudo-class represents an element (such as a form input) that has received focus. It is generally triggered when the user ......
Read more >
Tabbing is not correct if ag-grid cells have custom cell renderers
While tabbing through grid cells it is not possible to focus inner cell elements such as a link or a button. Inner cell...
Read more >
27.0.0 - AG Grid
The AG Grid Changelog lists the feature requests implemented and ... AG-6287 - Allow using the keyboard to move columns in the column...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found