0.4.1 • Published 3 years ago

keywalk v0.4.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

keywalk

Keywalk let you to walk through HTML elements via up/down arrow keys.

Demo

Codepen

Install

npm i keywalk

# or using yarn

yarn add keywalk
import Keywalk from 'keywalk'

Or include from CDN

<script src="https://cdn.jsdelivr.net/npm/keywalk@0.3.1">

Parameters

ParameterTypeDescriptionDefault
triggerstringThe element to listen the key event. (with CSS selector)document
containerstringRoot container of items. Keywalk will walk on nodes that are direct children of the container. Required-
activeClassstringCSS class name of currently active item.'active'
selectKeystringThe key that trigger the onSelect() event. Can be specified by a key name.'Enter'

Events

EventDescription
onWalk(element, index)Will return the HTML node and index of currently active item.
onSelect(element, index)Will return the HTML node and index of selected item.

Functions

FunctionDescription
reset()Will reset the focus state on the list.

How to use

<input id="input" />
<ul class="list">
  <li>Orange</li>
  <li>Cherry</li>
  <li>Banana</li>
  <li>Apple</li>
  <li>Pineapple</li>
</ul>

<script>
  new Keywalk({
    trigger: '#input',
    container: '.list',
    onWalk: (element, index) => {
      console.log('active item: ', element, ' index: ', index)
    },
    onSelect: (element, index) => {
      console.log('selected item: ', element, ' index: ', index)
    }
  })
</script>

Reset the focus state:

const keywalk = new Keywalk({
  ...
})

btn.addEventListener('click', () => {
  keywalk.reset()
})
0.3.0

3 years ago

0.2.8

3 years ago

0.4.1

3 years ago

0.4.0

3 years ago

0.3.1

3 years ago

0.2.7

3 years ago

0.2.6

3 years ago

0.2.3

3 years ago

0.2.2

3 years ago

0.2.5

3 years ago

0.2.4

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago