@policystudio/policy-studio-ui-vue 1.2.0-access.73 → 1.2.0-access.74
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
<div
|
|
3
3
|
class="psui-el-tab-header"
|
|
4
4
|
:class="[getComponentClass, `layout-${layout}`]"
|
|
5
|
-
role="
|
|
5
|
+
role="tablist"
|
|
6
|
+
:aria-label="ariaLabel"
|
|
7
|
+
@keydown="onKeyDown"
|
|
6
8
|
>
|
|
7
9
|
<template v-for="(item, index) in getItems">
|
|
8
10
|
<slot :item="item">
|
|
@@ -14,7 +16,12 @@
|
|
|
14
16
|
<template #trigger>
|
|
15
17
|
<button
|
|
16
18
|
:key="item[keyValue] + index"
|
|
19
|
+
ref="tabButtons"
|
|
17
20
|
type="button"
|
|
21
|
+
role="tab"
|
|
22
|
+
:aria-selected="getSelected === item[keyValue]"
|
|
23
|
+
:tabindex="getSelected === item[keyValue] ? 0 : -1"
|
|
24
|
+
:aria-controls="ariaControlsPrefix ? `${ariaControlsPrefix}${item.id || item[keyValue]}` : undefined"
|
|
18
25
|
@click="selectTab(item)"
|
|
19
26
|
:class="getButtonClass(item).value"
|
|
20
27
|
>
|
|
@@ -31,9 +38,15 @@
|
|
|
31
38
|
</template>
|
|
32
39
|
</PsRichTooltip>
|
|
33
40
|
<button
|
|
34
|
-
v-else
|
|
35
|
-
|
|
41
|
+
v-else
|
|
42
|
+
:id="item.id ? item.id : (idSuffix ? `${item[keyValue]}${idSuffix}` : undefined)"
|
|
36
43
|
:key="item[keyValue] + index"
|
|
44
|
+
ref="tabButtons"
|
|
45
|
+
type="button"
|
|
46
|
+
role="tab"
|
|
47
|
+
:aria-selected="getSelected === item[keyValue]"
|
|
48
|
+
:tabindex="getSelected === item[keyValue] ? 0 : -1"
|
|
49
|
+
:aria-controls="ariaControlsPrefix ? `${ariaControlsPrefix}${item.id || item[keyValue]}` : undefined"
|
|
37
50
|
@click="selectTab(item)"
|
|
38
51
|
:class="getButtonClass(item).value"
|
|
39
52
|
>
|
|
@@ -54,7 +67,7 @@
|
|
|
54
67
|
|
|
55
68
|
<script setup>
|
|
56
69
|
import PsRichTooltip from '../tooltip/PsRichTooltip.vue'
|
|
57
|
-
import { computed } from 'vue'
|
|
70
|
+
import { computed, ref } from 'vue'
|
|
58
71
|
import PsIcon from '../ui/PsIcon.vue'
|
|
59
72
|
|
|
60
73
|
const props = defineProps({
|
|
@@ -98,10 +111,33 @@ const props = defineProps({
|
|
|
98
111
|
* It sets the tab seleced.
|
|
99
112
|
*/
|
|
100
113
|
selected: {},
|
|
114
|
+
/**
|
|
115
|
+
* The aria-label for the tablist.
|
|
116
|
+
*/
|
|
117
|
+
ariaLabel: {
|
|
118
|
+
type: String,
|
|
119
|
+
default: 'Tabs',
|
|
120
|
+
},
|
|
121
|
+
/**
|
|
122
|
+
* Prefix for the aria-controls attribute.
|
|
123
|
+
*/
|
|
124
|
+
ariaControlsPrefix: {
|
|
125
|
+
type: String,
|
|
126
|
+
default: '',
|
|
127
|
+
},
|
|
128
|
+
/**
|
|
129
|
+
* Suffix for the tab ID.
|
|
130
|
+
*/
|
|
131
|
+
idSuffix: {
|
|
132
|
+
type: String,
|
|
133
|
+
default: '',
|
|
134
|
+
},
|
|
101
135
|
})
|
|
102
136
|
|
|
103
137
|
const emit = defineEmits(['change', 'update:selected'])
|
|
104
138
|
|
|
139
|
+
const tabButtons = ref([])
|
|
140
|
+
|
|
105
141
|
const getComponentClass = computed(() => {
|
|
106
142
|
if (props.disabled) {
|
|
107
143
|
return 'status-disabled'
|
|
@@ -146,6 +182,46 @@ const selectTab = (item) => {
|
|
|
146
182
|
}
|
|
147
183
|
}
|
|
148
184
|
|
|
185
|
+
const onKeyDown = (e) => {
|
|
186
|
+
const tabs = tabButtons.value.filter(btn => btn !== null)
|
|
187
|
+
let currentIndex = tabs.findIndex(btn => btn === document.activeElement)
|
|
188
|
+
|
|
189
|
+
if (currentIndex === -1) return
|
|
190
|
+
|
|
191
|
+
let nextIndex
|
|
192
|
+
|
|
193
|
+
switch (e.key) {
|
|
194
|
+
case 'ArrowRight':
|
|
195
|
+
case 'ArrowDown':
|
|
196
|
+
e.preventDefault()
|
|
197
|
+
nextIndex = (currentIndex + 1) % tabs.length
|
|
198
|
+
break
|
|
199
|
+
case 'ArrowLeft':
|
|
200
|
+
case 'ArrowUp':
|
|
201
|
+
e.preventDefault()
|
|
202
|
+
nextIndex = (currentIndex - 1 + tabs.length) % tabs.length
|
|
203
|
+
break
|
|
204
|
+
case 'Home':
|
|
205
|
+
e.preventDefault()
|
|
206
|
+
nextIndex = 0
|
|
207
|
+
break
|
|
208
|
+
case 'End':
|
|
209
|
+
e.preventDefault()
|
|
210
|
+
nextIndex = tabs.length - 1
|
|
211
|
+
break
|
|
212
|
+
default:
|
|
213
|
+
return
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if (nextIndex !== undefined) {
|
|
217
|
+
const nextTab = nextIndex >= 0 && nextIndex < getItems.value.length ? getItems.value[nextIndex] : null
|
|
218
|
+
if (nextTab && nextTab.disabled !== true) {
|
|
219
|
+
selectTab(nextTab)
|
|
220
|
+
tabs[nextIndex].focus()
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
149
225
|
const getButtonClass = (item) => {
|
|
150
226
|
return computed(() => {
|
|
151
227
|
if (item.disabled) {
|