Commit 36d24701325afe4874af14fc559d0445192dbaf5

Authored by Graham Fairweather
1 parent f4e25069

Radio w3c keyboard WIP

examples/routers/radio.vue
... ... @@ -43,9 +43,9 @@
43 43 data () {
44 44 return {
45 45 single: true,
46   - phone: 'apple',
  46 + phone: '',
47 47 button2: '北京',
48   - }
  48 + };
49 49 },
50 50 methods: {
51 51  
... ...
package.json
... ... @@ -48,7 +48,7 @@
48 48 "tinycolor2": "^1.4.1"
49 49 },
50 50 "peerDependencies": {
51   - "vue": "^2.5.2"
  51 + "vue": "^2.5.13"
52 52 },
53 53 "devDependencies": {
54 54 "autoprefixer-loader": "^2.0.0",
... ...
src/components/radio/radio-group.vue
1 1 <template>
2   - <div :class="classes">
  2 + <div
  3 + :class="classes" tabindex="0"
  4 + @keydown.left="onLeft"
  5 + @keydown.right="onRight"
  6 + @keydown.up="onUp"
  7 + @keydown.down="onDown"
  8 + @keydown.tab="onTab">
3 9 <slot></slot>
4 10 </div>
5 11 </template>
... ... @@ -35,7 +41,8 @@
35 41 data () {
36 42 return {
37 43 currentValue: this.value,
38   - childrens: []
  44 + childrens: [],
  45 + preventDefaultTab: true
39 46 };
40 47 },
41 48 computed: {
... ... @@ -72,7 +79,52 @@
72 79 this.$emit('input', data.value);
73 80 this.$emit('on-change', data.value);
74 81 this.dispatch('FormItem', 'on-form-change', data.value);
75   - }
  82 + },
  83 + findRadio(value) {
  84 + return this.childrens && this.childrens.length ? this.childrens.find((child) => child.value === value) : undefined;
  85 + },
  86 + findIndexRadio(value) {
  87 + return this.childrens && this.childrens.length ? this.childrens.findIndex((child) => child.value === value) : -1;
  88 + },
  89 + includesRadio(value) {
  90 + return this.childrens && this.childrens.length ? this.childrens.includes((child) => child.value === value) : false;
  91 + },
  92 + nextRadio() {
  93 + if (this.includesRadio(this.currentValue)) {
  94 + console.log('get next');
  95 + } else {
  96 + return this.childrens && this.childrens.length ? this.childrens[0] : undefined;
  97 + }
  98 + },
  99 + onLeft() {
  100 + console.log('left', this.currentValue);
  101 + },
  102 + onRight() {
  103 + console.log('right', this.currentValue);
  104 + },
  105 + onUp() {
  106 + console.log('up', this.currentValue);
  107 + },
  108 + onDown() {
  109 + console.log('down', this.currentValue);
  110 + },
  111 + onTab(event) {
  112 + if (!this.preventDefaultTab) {
  113 + return;
  114 + }
  115 +
  116 + event.preventDefault();
  117 + this.preventDefaultTab = false;
  118 + this.currentValue = this.nextRadio();
  119 + if (this.currentValue) {
  120 + this.change({
  121 + value: this.currentValue.label
  122 + });
  123 + }
  124 +
  125 + console.log('tab', this);
  126 +
  127 + },
76 128 },
77 129 watch: {
78 130 value () {
... ...
src/components/radio/radio.vue
1 1 <template>
2 2 <label
3 3 :class="wrapClasses"
4   - :tabindex="disabled ? -1 : 0"
5   - @keyup.space="change">
  4 + :tabindex="disabled || group ? -1 : 0">
6 5 <span :class="radioClasses">
7 6 <span :class="innerClasses"></span>
8 7 <input
... ...
src/styles/components/radio.less
... ... @@ -7,6 +7,7 @@
7 7 display: inline-block;
8 8 font-size: @font-size-small;
9 9 vertical-align: middle;
  10 + //outline: 0;
10 11 &-vertical{
11 12 .@{radio-prefix-cls}-wrapper {
12 13 display: block;
... ...