2020-04-27 01:04:08 +00:00
|
|
|
<template lang="pug">
|
|
|
|
.tabset.elevation-2
|
2022-04-03 20:55:11 +00:00
|
|
|
ul.tabset-tabs(ref='tabs', role='tablist')
|
2020-04-27 01:04:08 +00:00
|
|
|
slot(name='tabs')
|
|
|
|
.tabset-content(ref='content')
|
|
|
|
slot(name='content')
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2022-04-03 20:55:11 +00:00
|
|
|
import { customAlphabet } from 'nanoid/non-secure'
|
|
|
|
|
|
|
|
const nanoid = customAlphabet('1234567890abcdef', 10)
|
|
|
|
|
2020-04-27 01:04:08 +00:00
|
|
|
export default {
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
currentTab: 0
|
|
|
|
}
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
currentTab (newValue, oldValue) {
|
|
|
|
this.setActiveTab()
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
setActiveTab () {
|
|
|
|
this.$refs.tabs.childNodes.forEach((node, idx) => {
|
|
|
|
if (idx === this.currentTab) {
|
|
|
|
node.className = 'is-active'
|
2022-04-03 20:55:11 +00:00
|
|
|
node.setAttribute('aria-selected', 'true')
|
2020-04-27 01:04:08 +00:00
|
|
|
} else {
|
|
|
|
node.className = ''
|
2022-04-03 20:55:11 +00:00
|
|
|
node.setAttribute('aria-selected', 'false')
|
2020-04-27 01:04:08 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
this.$refs.content.childNodes.forEach((node, idx) => {
|
|
|
|
if (idx === this.currentTab) {
|
|
|
|
node.className = 'tabset-panel is-active'
|
2022-04-03 20:55:11 +00:00
|
|
|
node.removeAttribute('hidden')
|
2020-04-27 01:04:08 +00:00
|
|
|
} else {
|
|
|
|
node.className = 'tabset-panel'
|
2022-04-03 20:55:11 +00:00
|
|
|
node.setAttribute('hidden', '')
|
2020-04-27 01:04:08 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted () {
|
2021-12-18 04:21:08 +00:00
|
|
|
// Handle scroll to header on load within hidden tab content
|
|
|
|
if (window.location.hash && window.location.hash.length > 1) {
|
|
|
|
const headerId = decodeURIComponent(window.location.hash)
|
|
|
|
let foundIdx = -1
|
|
|
|
this.$refs.content.childNodes.forEach((node, idx) => {
|
|
|
|
if (node.querySelector(headerId)) {
|
|
|
|
foundIdx = idx
|
|
|
|
}
|
|
|
|
})
|
|
|
|
if (foundIdx >= 0) {
|
|
|
|
this.currentTab = foundIdx
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-27 01:04:08 +00:00
|
|
|
this.setActiveTab()
|
2021-12-18 04:21:08 +00:00
|
|
|
|
2022-04-03 20:55:11 +00:00
|
|
|
const tabRefId = nanoid()
|
|
|
|
|
2020-04-27 01:04:08 +00:00
|
|
|
this.$refs.tabs.childNodes.forEach((node, idx) => {
|
2022-04-03 20:55:11 +00:00
|
|
|
node.setAttribute('id', `${tabRefId}-${idx}`)
|
|
|
|
node.setAttribute('role', 'tab')
|
|
|
|
node.setAttribute('aria-controls', `${tabRefId}-${idx}-tab`)
|
|
|
|
node.setAttribute('tabindex', '0')
|
2020-04-27 01:04:08 +00:00
|
|
|
node.addEventListener('click', ev => {
|
|
|
|
this.currentTab = [].indexOf.call(ev.target.parentNode.children, ev.target)
|
|
|
|
})
|
2022-04-03 20:55:11 +00:00
|
|
|
node.addEventListener('keydown', ev => {
|
|
|
|
if (ev.key === 'ArrowLeft' && idx > 0) {
|
|
|
|
this.currentTab = idx - 1
|
|
|
|
this.$refs.tabs.childNodes[idx - 1].focus()
|
|
|
|
} else if (ev.key === 'ArrowRight' && idx < this.$refs.tabs.childNodes.length - 1) {
|
|
|
|
this.currentTab = idx + 1
|
|
|
|
this.$refs.tabs.childNodes[idx + 1].focus()
|
|
|
|
} else if (ev.key === 'Enter' || ev.key === ' ') {
|
|
|
|
this.currentTab = idx
|
|
|
|
node.focus()
|
|
|
|
} else if (ev.key === 'Home') {
|
|
|
|
this.currentTab = 0
|
|
|
|
ev.preventDefault()
|
|
|
|
ev.target.parentNode.children[0].focus()
|
|
|
|
} else if (ev.key === 'End') {
|
|
|
|
this.currentTab = this.$refs.tabs.childNodes.length - 1
|
|
|
|
ev.preventDefault()
|
|
|
|
ev.target.parentNode.children[this.$refs.tabs.childNodes.length - 1].focus()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
this.$refs.content.childNodes.forEach((node, idx) => {
|
|
|
|
node.setAttribute('id', `${tabRefId}-${idx}-tab`)
|
|
|
|
node.setAttribute('role', 'tabpanel')
|
|
|
|
node.setAttribute('aria-labelledby', `${tabRefId}-${idx}`)
|
|
|
|
node.setAttribute('tabindex', '0')
|
2020-04-27 01:04:08 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
.tabset {
|
|
|
|
border-radius: 5px;
|
|
|
|
margin-top: 10px;
|
|
|
|
|
|
|
|
@at-root .theme--dark & {
|
|
|
|
background-color: #292929;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .tabset-tabs {
|
|
|
|
padding-left: 0;
|
|
|
|
margin: 0;
|
|
|
|
display: flex;
|
2020-09-26 23:07:17 +00:00
|
|
|
align-items: stretch;
|
2020-04-27 01:04:08 +00:00
|
|
|
background: linear-gradient(to bottom, #FFF, #FAFAFA);
|
|
|
|
box-shadow: inset 0 -1px 0 0 #DDD;
|
|
|
|
border-radius: 5px 5px 0 0;
|
2020-09-26 23:07:17 +00:00
|
|
|
overflow: auto;
|
2020-04-27 01:04:08 +00:00
|
|
|
|
|
|
|
@at-root .theme--dark & {
|
|
|
|
background: linear-gradient(to bottom, #424242, #333);
|
|
|
|
box-shadow: inset 0 -1px 0 0 #555;
|
|
|
|
}
|
|
|
|
|
|
|
|
> li {
|
|
|
|
display: block;
|
|
|
|
padding: 16px;
|
|
|
|
margin-top: 0;
|
|
|
|
cursor: pointer;
|
|
|
|
transition: color 1s ease;
|
|
|
|
border-right: 1px solid #FFF;
|
|
|
|
font-size: 14px;
|
|
|
|
font-weight: 500;
|
|
|
|
margin-bottom: 1px;
|
|
|
|
user-select: none;
|
|
|
|
|
|
|
|
@at-root .theme--dark & {
|
|
|
|
border-right-color: #555;
|
|
|
|
}
|
|
|
|
|
|
|
|
&.is-active {
|
|
|
|
background-color: #FFF;
|
|
|
|
margin-bottom: 0;
|
|
|
|
padding-bottom: 17px;
|
2022-04-03 20:55:11 +00:00
|
|
|
padding-top: 13px;
|
2020-04-27 01:04:08 +00:00
|
|
|
color: mc('blue', '700');
|
2022-04-03 20:55:11 +00:00
|
|
|
border-top: 3px solid mc('blue', '700');
|
2020-04-27 01:04:08 +00:00
|
|
|
|
|
|
|
@at-root .theme--dark & {
|
|
|
|
background-color: #292929;
|
|
|
|
color: mc('blue', '300');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
&:last-child {
|
|
|
|
border-right: none;
|
|
|
|
|
|
|
|
&.is-active {
|
|
|
|
border-right: 1px solid #EEE;
|
|
|
|
|
|
|
|
@at-root .theme--dark & {
|
|
|
|
border-right-color: #555;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
background-color: rgba(#CCC, .1);
|
|
|
|
|
|
|
|
@at-root .theme--dark & {
|
|
|
|
background-color: rgba(#222, .25);
|
|
|
|
}
|
|
|
|
|
|
|
|
&.is-active {
|
|
|
|
background-color: #FFF;
|
|
|
|
|
|
|
|
@at-root .theme--dark & {
|
|
|
|
background-color: #292929;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
& + li {
|
|
|
|
border-left: 1px solid #EEE;
|
|
|
|
|
|
|
|
@at-root .theme--dark & {
|
|
|
|
border-left-color: #222;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
> .tabset-content {
|
|
|
|
.tabset-panel {
|
|
|
|
padding: 2px 16px 16px;
|
|
|
|
display: none;
|
|
|
|
|
|
|
|
&.is-active {
|
|
|
|
display: block;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|