-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New component b-button-toolbar (#367)
* [button-toolbar] New component * [button-toolbar] sizing must be on children * [components] New button-toolbar * [components] New button-toolbar * [components] New button-toolbar * [button-group] Removed toolbar option & key nav Moved to new button-toolbar wrapper component * Update button-group.vue
- Loading branch information
1 parent
45362fb
commit 747a801
Showing
3 changed files
with
111 additions
and
92 deletions.
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
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,107 @@ | ||
<template> | ||
<div :class="classObject" | ||
role="toolbar" | ||
:tabindex="keyNav ? '0' : null" | ||
@focusin.self="focusFirst" | ||
@keydown.left="focusNext($event,true)" | ||
@keydown.up="focusNext($event,true)" | ||
@keydown.right="focusNext($event,false)" | ||
@keydown.down="focusNext($event,false)" | ||
@keydown.shift.left="focusFirst($event)" | ||
@keydown.shift.up="focusFirst($event)" | ||
@keydown.shift.right="focusLast($event)" | ||
@keydown.shift.down="focusLast($event)" | ||
> | ||
<slot></slot> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
const ITEM_SELECTOR = [ | ||
'.btn:not(.disabled):not([disabled]):not([style*="display: none"]):not([style*="display:none"])', | ||
'.form-control:not(.disabled):not([disabled]):not([style*="display: none"]):not([style*="display:none"])', | ||
'select:not(.disabled):not([disabled]):not([style*="display: none"]):not([style*="display:none"])', | ||
'input[type="checkbox"]:not(.disabled):not([disabled]):not([style*="display: none"]):not([style*="display:none"])', | ||
'input[type="radio"]:not(.disabled):not([disabled]):not([style*="display: none"]):not([style*="display:none"])' | ||
].join(','); | ||
export default { | ||
computed: { | ||
classObject() { | ||
return [ | ||
'btn-toolbar', | ||
(this.justify && !this.vertical) ? 'justify-content-between' : '' | ||
]; | ||
} | ||
}, | ||
props: { | ||
justify: { | ||
type: Boolean, | ||
default: false | ||
}, | ||
KeyNav: { | ||
type: Boolean, | ||
default: false | ||
} | ||
}, | ||
methods: { | ||
focusNext(e, prev) { | ||
if (!this.keyNav) { | ||
return; | ||
} | ||
e.preventDefault(); | ||
e.stopPropagation(); | ||
const items = this.getItems(); | ||
if (items.length < 1) { | ||
return; | ||
} | ||
let index = items.indexOf(e.target); | ||
if (prev && index > 0) { | ||
index--; | ||
} else if (!prev && index < items.length - 1) { | ||
index++; | ||
} | ||
if (index < 0) { | ||
index = 0; | ||
} | ||
items[index].focus(); | ||
}, | ||
focusFirst(e) { | ||
if (!this.keyNav) { | ||
return; | ||
} | ||
e.preventDefault(); | ||
e.stopPropagation(); | ||
const items = this.getItems(); | ||
if (items.length > 0) { | ||
items[0].focus(); | ||
} | ||
}, | ||
focusLast(e) { | ||
if (!this.keyNav) { | ||
return; | ||
} | ||
e.preventDefault(); | ||
e.stopPropagation(); | ||
const items = this.getItems(); | ||
if (items.length > 0) { | ||
items[items.length - 1].focus(); | ||
} | ||
}, | ||
getItems() { | ||
const items = Array.prototype.slice.call(this.$el.querySelectorAll(ITEM_SELECTOR)); | ||
items.forEach(item => { | ||
// Ensure tabfocus is -1 on any new elements | ||
item.tabIndex = -1; | ||
}); | ||
return items; | ||
} | ||
}, | ||
mounted() { | ||
if (this.keyNav) { | ||
// Pre-set the tabindexes if the markup does not include tabindex="-1" on the toolbar items | ||
this.getItems(); | ||
} | ||
} | ||
}; | ||
</script> |
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