diff --git a/examples/docs/en-US/radio.md b/examples/docs/en-US/radio.md index 9a7be7c3..3702ca1e 100644 --- a/examples/docs/en-US/radio.md +++ b/examples/docs/en-US/radio.md @@ -137,5 +137,7 @@ change | triggers when the bound value changes | the label value of the chosen r ---- | ---- | ---- | ---- | ---- label | the value of radio | string/number | — | — disabled | whether radio is disabled | boolean | — | false +fill | border and background color when button is active | string | — | #20a0ff | +text-color | font color when button is active | string | — | #ffffff | diff --git a/examples/docs/zh-CN/radio.md b/examples/docs/zh-CN/radio.md index 203a27c4..862a0dad 100644 --- a/examples/docs/zh-CN/radio.md +++ b/examples/docs/zh-CN/radio.md @@ -138,3 +138,5 @@ |---------- |-------- |---------- |------------- |-------- | | label | Radio 的 value | string,number | — | — | | disabled | 是否禁用 | boolean | — | false | +| fill | 按钮激活时的填充色和边框色 | string | — | #20a0ff | +| text-color | 按钮激活时的文本颜色 | string | — | #ffffff | diff --git a/packages/radio/src/radio-button.vue b/packages/radio/src/radio-button.vue index 7863eba6..6d9b7ba1 100644 --- a/packages/radio/src/radio-button.vue +++ b/packages/radio/src/radio-button.vue @@ -23,6 +23,13 @@ set(newValue) { this.$parent.$emit('input', newValue); } + }, + activeStyle() { + return { + backgroundColor: this.$parent.fill, + borderColor: this.$parent.fill, + color: this.$parent.textColor + }; } } }; @@ -43,7 +50,7 @@ v-model="value" :name="name" :disabled="disabled"> - + diff --git a/packages/radio/src/radio-group.vue b/packages/radio/src/radio-group.vue index 596d8370..a4df33bf 100644 --- a/packages/radio/src/radio-group.vue +++ b/packages/radio/src/radio-group.vue @@ -10,7 +10,15 @@ props: { value: [String, Number], - size: String + size: String, + fill: { + type: String, + default: '#20a0ff' + }, + textColor: { + type: String, + default: '#fff' + } }, watch: { value(value) { diff --git a/packages/theme-default/src/radio.css b/packages/theme-default/src/radio.css index 0756f2f7..b48c70bb 100644 --- a/packages/theme-default/src/radio.css +++ b/packages/theme-default/src/radio.css @@ -160,15 +160,6 @@ z-index: -1; left: -999px; - &:checked { - & + .el-radio-button__inner { - z-index: 1; - background-color: var(--color-primary); - border-color: @background-color; - color: #fff; - } - } - &:disabled { & + .el-radio-button__inner { color: var(--button-disabled-color); diff --git a/test/unit/specs/radio.spec.js b/test/unit/specs/radio.spec.js index 3d442e05..e6c1207c 100644 --- a/test/unit/specs/radio.spec.js +++ b/test/unit/specs/radio.spec.js @@ -76,28 +76,52 @@ describe('Radio', () => { }); }, 50); }); - it('radio button', done => { - vm = createVue({ - template: ` - - 备选项 - 备选项 - 备选项 - - `, - data() { - return { - radio: 3 - }; - } - }, true); - expect(vm.$refs.radio1.$el.classList.contains('is-active')).to.be.true; - let radio = vm.$refs.radio2; - radio.$el.click(); - vm.$nextTick(_ => { - expect(radio.$el.classList.contains('is-active')).to.be.true; - expect(vm.radio === 6).to.be.true; - done(); + describe('Radio', () => { + it('create', done => { + vm = createVue({ + template: ` + + 备选项 + 备选项 + 备选项 + + `, + data() { + return { + radio: 3 + }; + } + }, true); + expect(vm.$refs.radio1.$el.classList.contains('is-active')).to.be.true; + let radio = vm.$refs.radio2; + radio.$el.click(); + vm.$nextTick(_ => { + expect(radio.$el.classList.contains('is-active')).to.be.true; + expect(vm.radio === 6).to.be.true; + done(); + }); + }); + it('custom color', done => { + vm = createVue({ + template: ` + + 备选项 + 备选项 + 备选项 + + `, + data() { + return { + radio: 3 + }; + } + }, true); + vm.$nextTick(_ => { + expect(vm.$refs.radio1.activeStyle.backgroundColor).to.equal('#000'); + expect(vm.$refs.radio1.activeStyle.borderColor).to.equal('#000'); + expect(vm.$refs.radio1.activeStyle.color).to.equal('#ff0'); + done(); + }); }); }); });