Skip to content

Commit

Permalink
[FIX] web_editor: fix selectStyle with conflicting extraClass
Browse files Browse the repository at this point in the history
Since [1] when `extraClass` was introduced, styles are wrongly applied
if an `extraClass` is defined on a `selectStyle` option, but both the
class and the option modify the same CSS property.

Typically, the "Round Corners" option sets the `border-radius` property
and uses the `rounded` extra class. But that extra class specifies
values for the `border-radius` properties.
Without the class, `applyCSS` determines that the style of some corners
is already `0px` and does therefore not need to be added to the inline
style.
But once the class is added, this is not true anymore - and the `0px`
should have been specified.

This commit avoids this issue by applying the CSS again once the
`extraClass` is added.

Steps to reproduce:
- Drop a "Text - Image" snippet.
- Select the image.
- Set the "Round Corners" to "50 0 0 0".
- Press tab to leave the field.

=> The entered field values was transformed.

[1]: bf5b4b6

task-3800288

X-original-commit: 00cfbc5
Part-of: #159331
  • Loading branch information
bso-odoo committed Mar 27, 2024
1 parent 01197eb commit 2a6355c
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions addons/web_editor/static/src/js/editor/snippets.options.js
Original file line number Diff line number Diff line change
Expand Up @@ -3421,10 +3421,14 @@ const SnippetOptionWidget = Widget.extend({
}

let hasUserValue = false;
for (let i = cssProps.length - 1; i > 0; i--) {
hasUserValue = applyCSS.call(this, cssProps[i], values.pop(), styles) || hasUserValue;
const applyAllCSS = (values) => {
for (let i = cssProps.length - 1; i > 0; i--) {
hasUserValue = applyCSS.call(this, cssProps[i], values.pop(), styles) || hasUserValue;
}
hasUserValue = applyCSS.call(this, cssProps[0], values.join(' '), styles) || hasUserValue;
}
hasUserValue = applyCSS.call(this, cssProps[0], values.join(' '), styles) || hasUserValue;

applyAllCSS([...values]);

function applyCSS(cssProp, cssValue, styles) {
if (typeof params.forceStyle !== 'undefined') {
Expand Down Expand Up @@ -3468,6 +3472,13 @@ const SnippetOptionWidget = Widget.extend({

if (params.extraClass) {
this.$target.toggleClass(params.extraClass, hasUserValue);
if (hasUserValue) {
// Might have changed because of the class.
for (const cssProp of cssProps) {
this.$target[0].style.removeProperty(cssProp);
}
applyAllCSS(values);
}
}

_restoreTransitions();
Expand Down

0 comments on commit 2a6355c

Please sign in to comment.