Skip to content

Commit

Permalink
Add navigation list functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
tajakobsen committed Nov 17, 2017
1 parent 98bbd71 commit 3388b24
Show file tree
Hide file tree
Showing 8 changed files with 4,043 additions and 141 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "airbnb-base"
}
13 changes: 13 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
language: node_js
node_js:
- 8
env:
- FRESH_DEPS=false
cache:
directories:
- $HOME/.npm
before_install:
- npm install --global [email protected]
- npm --version
install:
- if [[ ${FRESH_DEPS} == "true" ]]; then npm install --no-shrinkwrap --prefer-online; else npm install --prefer-offline; fi
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,36 @@
# VueJS Roving Tabindex Mixin

A VueJS mixin for handling roving tabindex

## Usage

Add `v-navigation-list="<list-name>"` to elements, to create a roving tabindex for the elements with the same `<list-name>`.

*Example:*

```html
<template>
<div>
<ul>
<li v-navigation-list="'myList'">Element 1</li>
<li v-navigation-list="'myList'">Element 2</li>
<li v-navigation-list="'myList'">Element 3</li>
</ul>

<ul>
<li v-navigation-list="'myOtherList'">Element 4</li>
<li v-navigation-list="'myOtherList'">Element 5</li>
</ul>
</div>
</template>
<script>
import rovingTabIndexMixin from 'vue-mixin-roving-tabindex'
export default {
mixins: [rovingTabIndexMixin],
data: () => ({})
}
</script>
```

In the example above there are two seperate roving tabindex lists (`myList` and `myOtherList`);
46 changes: 3 additions & 43 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,5 @@
import { __, always, defaultTo, ifElse, equals, prop } from 'ramda';
import NavigationList from 'roving-tabindex-element-list';
import navigationListDirective from './src/navigation-list-directive';


/**
* @type {object.<string, NavigationList>}
*/
const navigationLists = {};

/**
* Gets the key from the binding, or 'default
*
* @param {*} binding
* @return {string}
*/
const getKeyFromBinding = ifElse(equals('true'), always('default'), prop('value'));


/**
* Appends a value to an array, creating the array if it is undefined
*/
const keyboard = {
bind: function(el, binding, vnode) {
const key = getKeyFromBinding(binding);

if(!navigationLists[key]) {
navigationLists[key] = new NavigationList({
sortBeforeUpdate: defaultTo(false, binding.modifiers.sort)
});
}

navigationLists[key].registerElement(el);
},

unbind: function(el, binding) {
const key = getKeyFromBinding(binding);
navigationLists[key].unregisterElement(el);
}
export default {
directives: { navigationList: navigationListDirective },
};

const KeyboardMixin = {
directives: { keyboard }
};

export default KeyboardMixin;
Loading

0 comments on commit 3388b24

Please sign in to comment.