@veritree/ui 0.7.0 → 0.10.0
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/index.js +18 -9
- package/nuxt.js +21 -0
- package/package.json +1 -1
- package/src/DropdownMenu/VTDropdownMenuContent.vue +1 -0
- package/src/Form/VTFormFeedback.vue +64 -0
- package/src/Form/VTFormGroup.vue +22 -0
- package/src/Listbox/VTListbox.vue +79 -122
- package/src/Listbox/VTListboxContent.vue +151 -0
- package/src/Listbox/VTListboxItem.vue +226 -0
- package/src/Listbox/VTListboxLabel.vue +38 -0
- package/src/Listbox/VTListboxList.vue +63 -0
- package/src/Listbox/VTListboxSearch.vue +138 -0
- package/src/Listbox/VTListboxTrigger.vue +158 -0
- package/src/Listbox/VTListboxButton.vue +0 -81
- package/src/Listbox/VTListboxOption.vue +0 -126
- package/src/Listbox/VTListboxOptions.vue +0 -119
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<li
|
|
3
|
-
:id="id"
|
|
4
|
-
class="Listbox-option"
|
|
5
|
-
role="option"
|
|
6
|
-
@mousedown.prevent="onMouseDown"
|
|
7
|
-
@mousemove="onMousemove"
|
|
8
|
-
@mouseout="onMouseleave"
|
|
9
|
-
>
|
|
10
|
-
<slot></slot>
|
|
11
|
-
</li>
|
|
12
|
-
</template>
|
|
13
|
-
|
|
14
|
-
<script>
|
|
15
|
-
import { scrollElementIntoView } from '../utils/components';
|
|
16
|
-
import { genId } from '../utils/ids';
|
|
17
|
-
import { areObjsEqual, isObj } from '../utils/objects';
|
|
18
|
-
|
|
19
|
-
export default {
|
|
20
|
-
name: 'VTListboxOption',
|
|
21
|
-
|
|
22
|
-
inject: ['api'],
|
|
23
|
-
|
|
24
|
-
props: {
|
|
25
|
-
value: {
|
|
26
|
-
type: [String, Number, Object],
|
|
27
|
-
required: true,
|
|
28
|
-
},
|
|
29
|
-
selected: {
|
|
30
|
-
type: Boolean,
|
|
31
|
-
default: false,
|
|
32
|
-
},
|
|
33
|
-
},
|
|
34
|
-
|
|
35
|
-
data() {
|
|
36
|
-
return {
|
|
37
|
-
id: `listbox-option-${genId()}`,
|
|
38
|
-
focused: false,
|
|
39
|
-
isMousemove: false,
|
|
40
|
-
parent: null,
|
|
41
|
-
};
|
|
42
|
-
},
|
|
43
|
-
|
|
44
|
-
watch: {
|
|
45
|
-
focused(newValue) {
|
|
46
|
-
if (!newValue) return;
|
|
47
|
-
|
|
48
|
-
if (!this.parent) this.parent = this.api().getListbox();
|
|
49
|
-
if (!this.isMousemove) scrollElementIntoView(this.$el, this.parent.$el);
|
|
50
|
-
this.parent.updateActiveDescendant(this.id);
|
|
51
|
-
},
|
|
52
|
-
},
|
|
53
|
-
|
|
54
|
-
mounted() {
|
|
55
|
-
this.api().registerOption(this);
|
|
56
|
-
|
|
57
|
-
if (this.selected) {
|
|
58
|
-
this.select();
|
|
59
|
-
this.focus();
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// todo: make sure it works with other values than objects
|
|
63
|
-
const listboxOptionSelected = this.api().getListboxValue();
|
|
64
|
-
|
|
65
|
-
if (!listboxOptionSelected) {
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (isObj(this.value)) {
|
|
70
|
-
if (areObjsEqual(this.value, listboxOptionSelected)) {
|
|
71
|
-
this.select();
|
|
72
|
-
this.focus();
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
if (this.value === listboxOptionSelected) {
|
|
79
|
-
this.select();
|
|
80
|
-
this.focus();
|
|
81
|
-
}
|
|
82
|
-
},
|
|
83
|
-
|
|
84
|
-
beforeDestroy() {
|
|
85
|
-
this.api().unregisterOption(this.id);
|
|
86
|
-
},
|
|
87
|
-
|
|
88
|
-
methods: {
|
|
89
|
-
focus() {
|
|
90
|
-
this.focused = true;
|
|
91
|
-
this.$el.classList.add('is-focused');
|
|
92
|
-
},
|
|
93
|
-
|
|
94
|
-
unfocus() {
|
|
95
|
-
this.focused = false;
|
|
96
|
-
this.$el.classList.remove('is-focused');
|
|
97
|
-
},
|
|
98
|
-
|
|
99
|
-
select() {
|
|
100
|
-
this.$el.setAttribute('aria-selected', true);
|
|
101
|
-
},
|
|
102
|
-
|
|
103
|
-
unselect() {
|
|
104
|
-
this.$el.setAttribute('aria-selected', false);
|
|
105
|
-
},
|
|
106
|
-
|
|
107
|
-
onMouseDown(event) {
|
|
108
|
-
if (event.buttons === 1) this.api().selectOption(this);
|
|
109
|
-
},
|
|
110
|
-
|
|
111
|
-
// Mousemove instead of mouseover to support keyboard navigation.
|
|
112
|
-
// The problem with mouseover is that when scrolling (scrollIntoView),
|
|
113
|
-
// mouseover event gets triggered.
|
|
114
|
-
onMousemove() {
|
|
115
|
-
this.isMousemove = true;
|
|
116
|
-
this.api().unfocusOptions();
|
|
117
|
-
this.focus();
|
|
118
|
-
},
|
|
119
|
-
|
|
120
|
-
onMouseleave() {
|
|
121
|
-
this.isMousemove = false;
|
|
122
|
-
this.unfocus();
|
|
123
|
-
},
|
|
124
|
-
},
|
|
125
|
-
};
|
|
126
|
-
</script>
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<ul
|
|
3
|
-
v-if="visible"
|
|
4
|
-
aria-orientation="vertical"
|
|
5
|
-
role="listbox"
|
|
6
|
-
class="Listbox-options"
|
|
7
|
-
tabindex="-1"
|
|
8
|
-
@keydown="onKeyDown"
|
|
9
|
-
@blur="onBlur"
|
|
10
|
-
>
|
|
11
|
-
<slot></slot>
|
|
12
|
-
</ul>
|
|
13
|
-
</template>
|
|
14
|
-
|
|
15
|
-
<script>
|
|
16
|
-
import { keys } from '../utils/keyboard';
|
|
17
|
-
let timer = null;
|
|
18
|
-
|
|
19
|
-
export default {
|
|
20
|
-
name: 'VTListboxOptions',
|
|
21
|
-
|
|
22
|
-
inject: ['api'],
|
|
23
|
-
|
|
24
|
-
data() {
|
|
25
|
-
return {
|
|
26
|
-
visible: false,
|
|
27
|
-
filter: '',
|
|
28
|
-
};
|
|
29
|
-
},
|
|
30
|
-
|
|
31
|
-
watch: {
|
|
32
|
-
visible(newValue) {
|
|
33
|
-
if (newValue) {
|
|
34
|
-
this.$nextTick(() => {
|
|
35
|
-
this.$el.focus();
|
|
36
|
-
this.handleOptionFocus();
|
|
37
|
-
});
|
|
38
|
-
} else {
|
|
39
|
-
const listboxButton = this.api().getListboxButton();
|
|
40
|
-
|
|
41
|
-
this.$nextTick(() => {
|
|
42
|
-
listboxButton.focus();
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
},
|
|
46
|
-
},
|
|
47
|
-
|
|
48
|
-
mounted() {
|
|
49
|
-
this.api().registerListbox(this);
|
|
50
|
-
},
|
|
51
|
-
|
|
52
|
-
methods: {
|
|
53
|
-
show() {
|
|
54
|
-
this.visible = true;
|
|
55
|
-
},
|
|
56
|
-
|
|
57
|
-
hide() {
|
|
58
|
-
this.visible = false;
|
|
59
|
-
},
|
|
60
|
-
|
|
61
|
-
handleOptionFocus() {
|
|
62
|
-
const selectedIndex = this.api().getFocusedIndex();
|
|
63
|
-
if (!selectedIndex) this.api().focusFirstOption();
|
|
64
|
-
},
|
|
65
|
-
|
|
66
|
-
updateActiveDescendant(id) {
|
|
67
|
-
this.$el.setAttribute('aria-activedescendant', id);
|
|
68
|
-
},
|
|
69
|
-
|
|
70
|
-
onKeyDown(event) {
|
|
71
|
-
const key = event.key;
|
|
72
|
-
const code = event.code;
|
|
73
|
-
|
|
74
|
-
if (code.includes('Key')) {
|
|
75
|
-
this.filter += code.replace('Key', '');
|
|
76
|
-
|
|
77
|
-
clearTimeout(timer);
|
|
78
|
-
|
|
79
|
-
timer = setTimeout(() => {
|
|
80
|
-
this.api().focusOptionByFilter(this.filter);
|
|
81
|
-
this.filter = '';
|
|
82
|
-
}, 100);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
switch (key) {
|
|
86
|
-
case keys.up:
|
|
87
|
-
event.preventDefault();
|
|
88
|
-
this.api().focusPreviousOption();
|
|
89
|
-
break;
|
|
90
|
-
case keys.down:
|
|
91
|
-
event.preventDefault();
|
|
92
|
-
this.api().focusNextOption();
|
|
93
|
-
break;
|
|
94
|
-
case keys.home:
|
|
95
|
-
event.preventDefault();
|
|
96
|
-
this.api().focusFirstOption();
|
|
97
|
-
break;
|
|
98
|
-
case keys.end:
|
|
99
|
-
event.preventDefault();
|
|
100
|
-
this.api().focusLastOption();
|
|
101
|
-
break;
|
|
102
|
-
case keys.enter:
|
|
103
|
-
event.preventDefault();
|
|
104
|
-
this.api().selectOption();
|
|
105
|
-
break;
|
|
106
|
-
case keys.escape:
|
|
107
|
-
this.hide();
|
|
108
|
-
break;
|
|
109
|
-
default:
|
|
110
|
-
break;
|
|
111
|
-
}
|
|
112
|
-
},
|
|
113
|
-
|
|
114
|
-
onBlur() {
|
|
115
|
-
this.hide();
|
|
116
|
-
},
|
|
117
|
-
},
|
|
118
|
-
};
|
|
119
|
-
</script>
|