-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
689d95a
commit 98bbd71
Showing
4 changed files
with
786 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Oops, something went wrong.