Skip to content

Commit

Permalink
fix: trim empty strings
Browse files Browse the repository at this point in the history
fixes #45
  • Loading branch information
quicoto committed Jul 4, 2023
1 parent cba4e68 commit 7af333c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,11 @@ export default (config = {}) => {
value = prop.indexOf(`data`) !== -1 ? $ref.getAttribute(prop) : $ref[prop];
}

setValueByPath(value, [...propPath], dataModel);
setValueByPath(
typeof value === `string` ? value.trim() : value,
[...propPath],
dataModel
);
}
}
}
Expand Down
17 changes: 17 additions & 0 deletions src/tests/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
`<p data-bind="description">
</p>`,
`data-bind`
);

const proxy = twoWayDataBinding({
$context: container
});

expect(proxy.description).toEqual(``);
});
});

0 comments on commit 7af333c

Please sign in to comment.