diff --git a/examples/views/radio/Radio.vue b/examples/views/radio/Radio.vue index dea979768..892d8409b 100644 --- a/examples/views/radio/Radio.vue +++ b/examples/views/radio/Radio.vue @@ -26,6 +26,16 @@

+

+ + + + + + + +

+

@@ -37,12 +47,12 @@ - + - + @@ -81,6 +91,7 @@ export default { value5: null, value6: '1', value7: '1', + value9: '', demoCodes: [ `

diff --git a/packages/radio/src/button.js b/packages/radio/src/button.js index e49756ab1..15757e478 100644 --- a/packages/radio/src/button.js +++ b/packages/radio/src/button.js @@ -9,7 +9,8 @@ export default { title: [String, Number], content: [String, Number], disabled: Boolean, - size: { type: String, default: () => GlobalConfig.radio.size || GlobalConfig.size } + strict: { type: Boolean, default: () => GlobalConfig.radioButton.strict }, + size: { type: String, default: () => GlobalConfig.radioButton.size || GlobalConfig.size } }, inject: { $xeradiogroup: { @@ -23,6 +24,10 @@ export default { isDisabled () { const { $xeradiogroup } = this return this.disabled || ($xeradiogroup && $xeradiogroup.disabled) + }, + isStrict () { + const { $xeradiogroup } = this + return $xeradiogroup ? $xeradiogroup.strict : this.strict } }, render (h) { @@ -49,7 +54,8 @@ export default { checked: $xeradiogroup ? $xeradiogroup.value === label : value === label }, on: { - change: this.changeEvent + change: this.changeEvent, + click: this.clickEvent } }), h('span', { @@ -58,15 +64,27 @@ export default { ]) }, methods: { + handleValue (label, evnt) { + const { $xeradiogroup } = this + const params = { label, $event: evnt } + if ($xeradiogroup) { + $xeradiogroup.handleChecked(params) + } else { + this.$emit('input', label) + this.$emit('change', params) + } + }, changeEvent (evnt) { - const { $xeradiogroup, isDisabled, label } = this + const { isDisabled } = this if (!isDisabled) { - const params = { label, $event: evnt } - if ($xeradiogroup) { - $xeradiogroup.handleChecked(params) - } else { - this.$emit('input', label) - this.$emit('change', params) + this.handleValue(this.label, evnt) + } + }, + clickEvent (evnt) { + const { $xeradiogroup, isDisabled, isStrict } = this + if (!isDisabled && !isStrict) { + if (this.label === ($xeradiogroup ? $xeradiogroup.value : this.value)) { + this.handleValue(null, evnt) } } } diff --git a/packages/radio/src/group.js b/packages/radio/src/group.js index 9686215c9..225980957 100644 --- a/packages/radio/src/group.js +++ b/packages/radio/src/group.js @@ -6,7 +6,8 @@ export default { props: { value: [String, Number, Boolean], disabled: Boolean, - size: { type: String, default: () => GlobalConfig.radio.size || GlobalConfig.size } + strict: { type: Boolean, default: () => GlobalConfig.radioGroup.strict }, + size: { type: String, default: () => GlobalConfig.radioGroup.size || GlobalConfig.size } }, provide () { return { diff --git a/packages/radio/src/radio.js b/packages/radio/src/radio.js index c56102030..737b34961 100644 --- a/packages/radio/src/radio.js +++ b/packages/radio/src/radio.js @@ -12,6 +12,7 @@ export default { content: [String, Number], disabled: Boolean, name: String, + strict: { type: Boolean, default: () => GlobalConfig.radio.strict }, size: { type: String, default: () => GlobalConfig.radio.size || GlobalConfig.size } }, inject: { @@ -23,6 +24,10 @@ export default { isDisabled () { const { $xeradiogroup } = this return this.disabled || ($xeradiogroup && $xeradiogroup.disabled) + }, + isStrict () { + const { $xeradiogroup } = this + return $xeradiogroup ? $xeradiogroup.strict : this.strict } }, render (h) { @@ -49,17 +54,8 @@ export default { checked: $xeradiogroup ? $xeradiogroup.value === label : value === label }, on: { - change: evnt => { - if (!isDisabled) { - const params = { label, $event: evnt } - if ($xeradiogroup) { - $xeradiogroup.handleChecked(params) - } else { - this.$emit('input', label) - this.$emit('change', params) - } - } - } + change: this.changeEvent, + click: this.clickEvent } }), h('span', { @@ -71,15 +67,27 @@ export default { ]) }, methods: { + handleValue (label, evnt) { + const { $xeradiogroup } = this + const params = { label, $event: evnt } + if ($xeradiogroup) { + $xeradiogroup.handleChecked(params) + } else { + this.$emit('input', label) + this.$emit('change', params) + } + }, changeEvent (evnt) { - const { $xeradiogroup, isDisabled, label } = this + const { isDisabled } = this if (!isDisabled) { - const params = { label, $event: evnt } - if ($xeradiogroup) { - $xeradiogroup.handleChecked(params) - } else { - this.$emit('input', label) - this.$emit('change', params) + this.handleValue(this.label, evnt) + } + }, + clickEvent (evnt) { + const { $xeradiogroup, isDisabled, isStrict } = this + if (!isDisabled && !isStrict) { + if (this.label === ($xeradiogroup ? $xeradiogroup.value : this.value)) { + this.handleValue(null, evnt) } } } diff --git a/packages/v-x-e-table/src/conf.js b/packages/v-x-e-table/src/conf.js index 255c3e29e..1a1a10a41 100644 --- a/packages/v-x-e-table/src/conf.js +++ b/packages/v-x-e-table/src/conf.js @@ -292,7 +292,16 @@ export default { // transfer: false }, radio: { - // size: null + // size: null, + strict: true + }, + radioButton: { + // size: null, + strict: true + }, + radioGroup: { + // size: null, + strict: true }, checkbox: { // size: null