feat(Field): add clear-trigger prop (#6699)

This commit is contained in:
neverland
2020-07-04 12:18:25 +08:00
committed by GitHub
parent ebe4036e1a
commit db09f29aa8
5 changed files with 36 additions and 17 deletions
+12 -7
View File
@@ -69,6 +69,10 @@ export default createComponent({
type: Boolean,
default: null,
},
clearTrigger: {
type: String,
default: 'focus',
},
formatTrigger: {
type: String,
default: 'onChange',
@@ -109,13 +113,14 @@ export default createComponent({
computed: {
showClear() {
return (
this.clearable &&
this.focused &&
this.value !== '' &&
isDef(this.value) &&
!this.readonly
);
if (this.clearable && !this.readonly) {
const hasValue = isDef(this.value) && this.value !== '';
const trigger =
this.clearTrigger === 'always' ||
(this.clearTrigger === 'focus' && this.focused);
return hasValue && trigger;
}
},
showError() {