diff --git a/addons/web_editor/static/src/js/wysiwyg/widgets/link.js b/addons/web_editor/static/src/js/wysiwyg/widgets/link.js index 75b305c4b04..87381b57e09 100644 --- a/addons/web_editor/static/src/js/wysiwyg/widgets/link.js +++ b/addons/web_editor/static/src/js/wysiwyg/widgets/link.js @@ -208,6 +208,13 @@ const Link = Widget.extend({ this.$link.css('border-width', data.customBorderWidth); this.$link.css('border-style', data.customBorderStyle); this.$link.css('border-color', data.customBorder); + } else { + this.$link.css('color', ''); + this.$link.css('background-color', ''); + this.$link.css('background-image', ''); + this.$link.css('border-width', ''); + this.$link.css('border-style', ''); + this.$link.css('border-color', ''); } const attrs = Object.assign({}, this.data.oldAttributes, { href: data.url, diff --git a/addons/web_editor/static/src/js/wysiwyg/widgets/link_tools.js b/addons/web_editor/static/src/js/wysiwyg/widgets/link_tools.js index 99160708d92..0c421861a27 100644 --- a/addons/web_editor/static/src/js/wysiwyg/widgets/link_tools.js +++ b/addons/web_editor/static/src/js/wysiwyg/widgets/link_tools.js @@ -44,9 +44,18 @@ const LinkTools = Link.extend({ /** * @override */ - start: function () { + start: async function () { this._addHintClasses(); - return this._super(...arguments); + const ret = await this._super(...arguments); + const link = this.$link[0]; + const customStyleProps = ['color', 'background-color', 'background-image', 'border-width', 'border-style', 'border-color']; + if (customStyleProps.some(s => link.style[s])) { + // Force custom style if style exists on the link. + const customOption = this.el.querySelector('[name="link_style_color"] we-button[data-value="custom"]'); + this._setSelectOption($(customOption), true); + await this._updateOptionsUI(); + } + return ret; }, destroy: function () { if (!this.el) { @@ -381,15 +390,6 @@ const LinkTools = Link.extend({ if ($target.closest('[name="link_border_style"]').length) { return; } - if ($target.closest('[name="link_style_color"]')) { - // Reset custom styles when changing link style. - this.$link.css('color', ''); - this.$link.css('background-color', ''); - this.$link.css('background-image', ''); - this.$link.css('border-width', ''); - this.$link.css('border-style', ''); - this.$link.css('border-color', ''); - } const $select = $target.closest('we-select'); $select.find('we-selection-items we-button').toggleClass('active', false); this._setSelectOption($target, true);