diff --git a/src/index.js b/src/index.js index 7139975..b51f870 100644 --- a/src/index.js +++ b/src/index.js @@ -159,7 +159,11 @@ export default (config = {}) => { value = prop.indexOf(`data`) !== -1 ? $ref.getAttribute(prop) : $ref[prop]; } - setValueByPath(value, [...propPath], dataModel); + setValueByPath( + value = typeof value === `string` ? value.trim() : value, + [...propPath], + dataModel + ); } } } diff --git a/src/tests/index.test.js b/src/tests/index.test.js index aa05cc9..5903d48 100644 --- a/src/tests/index.test.js +++ b/src/tests/index.test.js @@ -672,4 +672,21 @@ describe(`twoWayDataBinding`, () => { expect($input.getAttribute(`data-twowayvalue`)).toEqual(`Germany (DE)`); expect($input.value).toEqual(`Spain (ES)`); }); + + it(`Empty HTML line breaks are trimmed when saved to state`, () => { + const { + container + } = render( + `

+ +

`, + `data-bind` + ); + + const proxy = twoWayDataBinding({ + $context: container + }); + + expect(proxy.description).toEqual(``); + }); });