Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/souporserious/use-roving-index

Manage an active index that needs to be contained or wrapped.
https://github.com/souporserious/use-roving-index

Last synced: about 2 months ago
JSON representation

Manage an active index that needs to be contained or wrapped.

Awesome Lists containing this project

README

        

# ⌨️ use-roving-index

Manage an active index that needs to be contained or wrapped.

## Install

```bash
yarn add use-roving-index
```

```bash
npm install use-roving-index
```

## Usage

```jsx
import React from 'react'
import { useRovingIndex } from 'use-roving-index'

const items = ['Item 1', 'Item 2', 'Item 3']

function App() {
const {
activeIndex,
moveActiveIndex,
moveBackward,
moveBackwardDisabled,
moveForward,
moveForwardDisabled,
} = useRovingIndex({ maxIndex: items.length - 1 })
return (
<>

    {
    const multiplier = event.shiftKey ? 3 : 1
    switch (event.key) {
    case 'ArrowUp':
    case 'ArrowLeft':
    moveActiveIndex(-1 * multiplier)
    break
    case 'ArrowDown':
    case 'ArrowRight':
    moveActiveIndex(1 * multiplier)
    break
    }
    }}
    >
    {items.map((title, index) => (

  • {title}

  • ))}


Previous


Next

>
)
}
```