Radio w3c keyboard WIP
This commit is contained in:
parent
f4e2506905
commit
36d2470132
5 changed files with 60 additions and 8 deletions
|
@ -43,9 +43,9 @@
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
single: true,
|
single: true,
|
||||||
phone: 'apple',
|
phone: '',
|
||||||
button2: '北京',
|
button2: '北京',
|
||||||
}
|
};
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@
|
||||||
"tinycolor2": "^1.4.1"
|
"tinycolor2": "^1.4.1"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"vue": "^2.5.2"
|
"vue": "^2.5.13"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"autoprefixer-loader": "^2.0.0",
|
"autoprefixer-loader": "^2.0.0",
|
||||||
|
|
|
@ -1,5 +1,11 @@
|
||||||
<template>
|
<template>
|
||||||
<div :class="classes">
|
<div
|
||||||
|
:class="classes" tabindex="0"
|
||||||
|
@keydown.left="onLeft"
|
||||||
|
@keydown.right="onRight"
|
||||||
|
@keydown.up="onUp"
|
||||||
|
@keydown.down="onDown"
|
||||||
|
@keydown.tab="onTab">
|
||||||
<slot></slot>
|
<slot></slot>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
@ -35,7 +41,8 @@
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
currentValue: this.value,
|
currentValue: this.value,
|
||||||
childrens: []
|
childrens: [],
|
||||||
|
preventDefaultTab: true
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
|
@ -72,7 +79,52 @@
|
||||||
this.$emit('input', data.value);
|
this.$emit('input', data.value);
|
||||||
this.$emit('on-change', data.value);
|
this.$emit('on-change', data.value);
|
||||||
this.dispatch('FormItem', 'on-form-change', data.value);
|
this.dispatch('FormItem', 'on-form-change', data.value);
|
||||||
}
|
},
|
||||||
|
findRadio(value) {
|
||||||
|
return this.childrens && this.childrens.length ? this.childrens.find((child) => child.value === value) : undefined;
|
||||||
|
},
|
||||||
|
findIndexRadio(value) {
|
||||||
|
return this.childrens && this.childrens.length ? this.childrens.findIndex((child) => child.value === value) : -1;
|
||||||
|
},
|
||||||
|
includesRadio(value) {
|
||||||
|
return this.childrens && this.childrens.length ? this.childrens.includes((child) => child.value === value) : false;
|
||||||
|
},
|
||||||
|
nextRadio() {
|
||||||
|
if (this.includesRadio(this.currentValue)) {
|
||||||
|
console.log('get next');
|
||||||
|
} else {
|
||||||
|
return this.childrens && this.childrens.length ? this.childrens[0] : undefined;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onLeft() {
|
||||||
|
console.log('left', this.currentValue);
|
||||||
|
},
|
||||||
|
onRight() {
|
||||||
|
console.log('right', this.currentValue);
|
||||||
|
},
|
||||||
|
onUp() {
|
||||||
|
console.log('up', this.currentValue);
|
||||||
|
},
|
||||||
|
onDown() {
|
||||||
|
console.log('down', this.currentValue);
|
||||||
|
},
|
||||||
|
onTab(event) {
|
||||||
|
if (!this.preventDefaultTab) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
event.preventDefault();
|
||||||
|
this.preventDefaultTab = false;
|
||||||
|
this.currentValue = this.nextRadio();
|
||||||
|
if (this.currentValue) {
|
||||||
|
this.change({
|
||||||
|
value: this.currentValue.label
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('tab', this);
|
||||||
|
|
||||||
|
},
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
value () {
|
value () {
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
<template>
|
<template>
|
||||||
<label
|
<label
|
||||||
:class="wrapClasses"
|
:class="wrapClasses"
|
||||||
:tabindex="disabled ? -1 : 0"
|
:tabindex="disabled || group ? -1 : 0">
|
||||||
@keyup.space="change">
|
|
||||||
<span :class="radioClasses">
|
<span :class="radioClasses">
|
||||||
<span :class="innerClasses"></span>
|
<span :class="innerClasses"></span>
|
||||||
<input
|
<input
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
font-size: @font-size-small;
|
font-size: @font-size-small;
|
||||||
vertical-align: middle;
|
vertical-align: middle;
|
||||||
|
//outline: 0;
|
||||||
&-vertical{
|
&-vertical{
|
||||||
.@{radio-prefix-cls}-wrapper {
|
.@{radio-prefix-cls}-wrapper {
|
||||||
display: block;
|
display: block;
|
||||||
|
|
Loading…
Add table
Reference in a new issue