Skip to content

Commit

Permalink
fix(core): set style property value to empty string instead of an inv…
Browse files Browse the repository at this point in the history
…alid value (#49460)

Currently when the value of a styling property that has a unit is empty string a invalid value is generated.

Example:
`[style.width.px] = ""` will generate a value of `"px"`, when instead it should be `""`.

This causes browser to reset the value to an empty string. This is however not the case in Domino with changes in angular/domino@bfc9114.

This commit fixes the issues and generate correct values.

PR Close #49460
  • Loading branch information
alan-agius4 authored and atscott committed Mar 28, 2023
1 parent 6d6fc12 commit d201fc2
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/core/src/render3/instructions/styling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -833,8 +833,11 @@ function isStylingValuePresent(value: any): boolean {
* @param suffix
*/
function normalizeSuffix(value: any, suffix: string|undefined|null): string|null|undefined|boolean {
if (value == null /** || value === undefined */) {
if (value == null || value === '') {
// do nothing
// Do not add the suffix if the value is going to be empty.
// As it produce invalid CSS, which the browsers will automatically omit but Domino will not.
// Example: `"left": "px;"` instead of `"left": ""`.
} else if (typeof suffix === 'string') {
value = value + suffix;
} else if (typeof value === 'object') {
Expand Down

0 comments on commit d201fc2

Please sign in to comment.