Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
tajakobsen committed Nov 17, 2017
1 parent 689d95a commit 98bbd71
Show file tree
Hide file tree
Showing 4 changed files with 786 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# vue-mixin-roving-tabindex
# VueJS Roving Tabindex Mixin

A VueJS mixin for handling roving tabindex
45 changes: 45 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { __, always, defaultTo, ifElse, equals, prop } from 'ramda';
import NavigationList from 'roving-tabindex-element-list';


/**
* @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);
}
};

const KeyboardMixin = {
directives: { keyboard }
};

export default KeyboardMixin;
Loading

0 comments on commit 98bbd71

Please sign in to comment.