From 99bb9f3d7e97a852a53fcf2e165111d919d8bac0 Mon Sep 17 00:00:00 2001 From: Graham Fairweather Date: Fri, 19 Jan 2018 08:25:19 +0100 Subject: [PATCH 1/8] Fix focus --- src/components/radio/radio.vue | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/radio/radio.vue b/src/components/radio/radio.vue index 530053fa..0a6af034 100644 --- a/src/components/radio/radio.vue +++ b/src/components/radio/radio.vue @@ -13,6 +13,7 @@ :checked="currentValue" :name="name" @change="change" + @focus="$el.focus()" > {{ label }} From f4e25069055c5dd2ff804e32f61ca8dcabef2d3f Mon Sep 17 00:00:00 2001 From: Graham Fairweather Date: Fri, 19 Jan 2018 12:00:13 +0100 Subject: [PATCH 2/8] Use z-index to show shadow Other ideas are to use :before or :after to create shadow --- src/components/radio/radio-group.vue | 2 +- src/styles/components/radio.less | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/components/radio/radio-group.vue b/src/components/radio/radio-group.vue index a6e8b806..cf04d1eb 100644 --- a/src/components/radio/radio-group.vue +++ b/src/components/radio/radio-group.vue @@ -61,7 +61,7 @@ if (this.childrens) { this.childrens.forEach(child => { - child.currentValue = value == child.label; + child.currentValue = value === child.label; child.group = true; }); } diff --git a/src/styles/components/radio.less b/src/styles/components/radio.less index c1ec6061..20249088 100644 --- a/src/styles/components/radio.less +++ b/src/styles/components/radio.less @@ -32,6 +32,7 @@ &:focus { & .@{radio-inner-prefix-cls} { box-shadow: 0 0 0 2px fade(@primary-color, 20%); + z-index: 1; } } } @@ -183,7 +184,7 @@ span.@{radio-prefix-cls} + * { transition: all @transition-time ease-in-out; cursor: pointer; border: 1px solid @border-color-base; - border-left: 0; + //border-left: 0; background: #fff; > span { @@ -227,6 +228,7 @@ span.@{radio-prefix-cls} + * { &:focus { box-shadow: 0 0 0 2px fade(@primary-color, 20%); + z-index: 1; } .@{radio-prefix-cls}-inner, @@ -240,7 +242,7 @@ span.@{radio-prefix-cls} + * { background: #fff; border-color: @primary-color; color: @primary-color; - box-shadow: -1px 0 0 0 @primary-color; + //box-shadow: -1px 0 0 0 @primary-color; &:first-child { border-color: @primary-color; @@ -249,7 +251,7 @@ span.@{radio-prefix-cls} + * { &:hover { border-color: tint(@primary-color, 20%); - box-shadow: -1px 0 0 0 tint(@primary-color, 20%); + //box-shadow: -1px 0 0 0 tint(@primary-color, 20%); color: tint(@primary-color, 20%); } @@ -259,7 +261,7 @@ span.@{radio-prefix-cls} + * { &:active { border-color: shade(@primary-color, 5%); - box-shadow: -1px 0 0 0 shade(@primary-color, 5%); + //box-shadow: -1px 0 0 0 shade(@primary-color, 5%); color: shade(@primary-color, 5%); } } From 36d24701325afe4874af14fc559d0445192dbaf5 Mon Sep 17 00:00:00 2001 From: Graham Fairweather Date: Fri, 19 Jan 2018 15:16:49 +0100 Subject: [PATCH 3/8] Radio w3c keyboard WIP --- examples/routers/radio.vue | 4 +- package.json | 2 +- src/components/radio/radio-group.vue | 58 ++++++++++++++++++++++++++-- src/components/radio/radio.vue | 3 +- src/styles/components/radio.less | 1 + 5 files changed, 60 insertions(+), 8 deletions(-) diff --git a/examples/routers/radio.vue b/examples/routers/radio.vue index b4e6e215..69fd7b81 100644 --- a/examples/routers/radio.vue +++ b/examples/routers/radio.vue @@ -43,9 +43,9 @@ data () { return { single: true, - phone: 'apple', + phone: '', button2: '北京', - } + }; }, methods: { diff --git a/package.json b/package.json index d22f448c..a9e1e09c 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "tinycolor2": "^1.4.1" }, "peerDependencies": { - "vue": "^2.5.2" + "vue": "^2.5.13" }, "devDependencies": { "autoprefixer-loader": "^2.0.0", diff --git a/src/components/radio/radio-group.vue b/src/components/radio/radio-group.vue index cf04d1eb..4e6715eb 100644 --- a/src/components/radio/radio-group.vue +++ b/src/components/radio/radio-group.vue @@ -1,5 +1,11 @@ @@ -35,7 +41,8 @@ data () { return { currentValue: this.value, - childrens: [] + childrens: [], + preventDefaultTab: true }; }, computed: { @@ -72,7 +79,52 @@ this.$emit('input', data.value); this.$emit('on-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: { value () { diff --git a/src/components/radio/radio.vue b/src/components/radio/radio.vue index 0a6af034..7be686fb 100644 --- a/src/components/radio/radio.vue +++ b/src/components/radio/radio.vue @@ -1,8 +1,7 @@