diff --git a/src/field/index.js b/src/field/index.js index acc2d6d2c..61fa5f82f 100644 --- a/src/field/index.js +++ b/src/field/index.js @@ -491,7 +491,7 @@ export default createComponent({ genWordLimit() { if (this.showWordLimit && this.maxlength) { - const count = this.value.length; + const count = (this.value || '').length; const full = count >= this.maxlength; return ( diff --git a/src/field/test/__snapshots__/index.spec.js.snap b/src/field/test/__snapshots__/index.spec.js.snap index 6e2a72b70..0c1a0458e 100644 --- a/src/field/test/__snapshots__/index.spec.js.snap +++ b/src/field/test/__snapshots__/index.spec.js.snap @@ -79,6 +79,24 @@ exports[`reach max word-limit 1`] = ` `; +exports[`reach max word-limit null 1`] = ` +
+
+
+
0/3
+
+
+`; + +exports[`reach max word-limit undefined 1`] = ` +
+
+
+
0/3
+
+
+`; + exports[`render extra slot 1`] = `
diff --git a/src/field/test/index.spec.js b/src/field/test/index.spec.js index f44aca872..d3050f98f 100644 --- a/src/field/test/index.spec.js +++ b/src/field/test/index.spec.js @@ -310,6 +310,28 @@ test('reach max word-limit', () => { expect(wrapper).toMatchSnapshot(); }); +test('reach max word-limit undefined', () => { + const wrapper = mount(Field, { + propsData: { + value: undefined, + maxlength: 3, + showWordLimit: true, + }, + }); + expect(wrapper).toMatchSnapshot(); +}); + +test('reach max word-limit null', () => { + const wrapper = mount(Field, { + propsData: { + value: null, + maxlength: 3, + showWordLimit: true, + }, + }); + expect(wrapper).toMatchSnapshot(); +}); + test('name prop', () => { const wrapper = mount(Field, { propsData: {