Code Monkey home page Code Monkey logo

react-key-navigation's Introduction

react-key-navigation

Similar to the "Focus Management" of the BBC TAL.

WIP

  • Focusable Component
    • onFocus
    • onBlur
    • onEnterDown
  • Grid
  • Horizontal List
  • Vertical List
  • Horizontal List Scrollable
  • Vertical List Scrollable
  • Use Higher-Order Components?
  • Tests
  • Examples
  • Documentation

Example

import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import Navigation, {VerticalList, HorizontalList, Grid, Focusable} from 'react-key-navigation';

class App extends Component {
  render() {
    return (
      <Navigation>
        <Grid rows={100} columns={100}>
          {Array.from(Array(10000).keys()).map((v, i) => {
            return (
              <Focusable key={i} onFocus={() => console.log('focus ' + i)} onBlur={() => console.log('blur ' + i)} onEnterDown={() => console.log('enter ' + i)}>
                Element {i}
              </Focusable>
            );
          })}
        </Grid>
      </Navigation>
    );
  }
}

ReactDOM.render(<App />, document.getElementById('root'));

react-key-navigation's People

Contributors

dead avatar johneisenheim avatar keks0r avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-key-navigation's Issues

RTL support

I am using this package for focus related to my project. For RTL can I use this same package, as I need to scroll the horizontal list from right to left? Is it possible to use the same package for RTL and provide me the steps?

Language: Reactjs

Lib support

Hi! We are very interested in this library and have some questions about you plans on this lib:

  1. Will you support this repo in future?
  2. When will be next update/release?

Navigation problem after route

Hello! I have a problem with navigation, after route from one component to another.
After my app has loaded, I do an authorization check, then I route to another component.

componentWillMount() { this.props.Auth().then(() => { if (this.props.needSignUp) { this.props.history.push({pathname: '/signup/'}) } }) }

In the signup component, I have an Focusable elements

<div> <Focusable>Button-1</Focusable> <Focusable>Button-2</Focusable> </div>

When I trying to navigate this element, I get an error:

index.js:952 Uncaught TypeError: Cannot read property 'getNextFocusFrom' of undefined at Navigation.focusNext (index.js:952) at Navigation._this.onKeyDown (index.js:917)

What could be the reason?

Warning: React does not recognize the `focusableId` prop on a DOM element ?

Any idea how to solve this issue
react-dom.development.js:506 Warning: React does not recognize the focusableIdprop on a DOM element. If you intentionally want it to appear in the DOM as a custom attribute, spell it as lowercasefocusableid instead. If you accidentally passed it from a parent component, remove it from the DOM element. in span (created by VerticalList) in VerticalList (created by Navigation) in Navigation (created by App) in App (created by ConnectFunction) in ConnectFunction in Provider

Unable to retain last focused element

Hi.. I am using this library for one of my project and really enjoying using this.

I am facing difficulty in retaining the last focused list-item. For example, say in youtube app example, if focus is on the 3rd element of HorizontalList-1 and we move down to HorizontalList-3 and come back to List 1. The focus moves to the first element.

How to retain that focus to the 3rd element?

Force focus back to parent

Hi @dead ,
I'm facing the following issue: let's assume I have something like

<Navigator>
   <HorizontalList>
         <Menu>
              <VerticalList>
                      {...}
             </VerticalList>
        </Menu>
        <HorizontalList focusedId='h-list' retainFocus={true}>
               {...}
        </HorizontalList>
        <Modal>
            <HorizontalList focusedId='modal'>
            </HorizontalList>
       </Modal>
   </HorizontalList>
</Navigator>

Let's assume that Modal component can be rendered with a boolean property: if this prop is true, the component is rendered, null otherwise.

In h-list items, I have:

onEnterDown = (e, nav) => {
    openModal(true);
    nav.forceFocus('modal');
}

In Modal component, when I try to focus the h-list back it's seems that the Modal component itself is still present both in treePath and focusableComponents. So when I try to navigate in h-list component, the last focused item is ok, but when I press left or right focus disappear (logging your code, the modal is still focused, and the next item is a modal focusable item). Any chance to investigate on this problem?

Thank you again!

Set focus programmatically

Hi @dead,
first of all thank you for your awesome work! I've seen that your focus system creates a sort of tree of rendered focusable component, distinguished by a progressive index. My question is: if I have 3 components (a Vertical List, an Horizontal List and a Vertical List again in that order), if horizontal list is focused can I give focus to the second Vertical List when the enter key is pressed?

Thank you!

dynamic focusable element makes problems on navigation

Hello, I'm working with your library.
I found some problems on dynamic focusable element insertion.
If focusable elements is inserted dynamically, focus order doesn't work correctly.
Did you have any chance to meet this problem before??

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.