From cdf0870e1f81a5ec5096ddd062cf699e98681880 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Souk=C3=A9ina=20Bojabza?= Date: Mon, 23 Jan 2023 16:20:23 +0000 Subject: [PATCH] [FIX] web_editor: fix the widget state of the Vertical Alignment option Since commit [1], an `align-items-start` class is added when going from grid mode to normal mode in order to always have one of the four choices of the Vertical Alignment option selected. Indeed, without this class, none of them are chosen. However, only a few snippets have this option and it is therefore not possible to modify this class easily in the snippets that do not have it (except removing it from the DOM manually). The real issue in fact comes from the computation of this option widget state, which should select the last button (so the `align-items-stretch` one) if no class is present, since the behaviors are equivalent in these two situations. This commit removes the addition of this `align-items-start` class and fixes the `_computeWidgetState` of the Vertical Alignment option. [1]: https://github.com/odoo/odoo/commit/cc406afcea7bf5846233a9f97a4a8ac5f618f3ec task-3142615 closes odoo/odoo#113949 X-original-commit: 75ef0d5d7ed000cf55b47bebb00cc2d0bb34b581 Signed-off-by: Vray Benjamin (bvr) --- .../static/src/js/editor/snippets.options.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/addons/web_editor/static/src/js/editor/snippets.options.js b/addons/web_editor/static/src/js/editor/snippets.options.js index 97118ceabef..4d1b3ecd259 100644 --- a/addons/web_editor/static/src/js/editor/snippets.options.js +++ b/addons/web_editor/static/src/js/editor/snippets.options.js @@ -5311,9 +5311,6 @@ registry.layout_column = SnippetOptionWidget.extend({ } // Removing the grid properties. delete rowEl.dataset.rowCount; - - // Adding back an align-items-* class. - rowEl.classList.add('align-items-start'); }, /** * Removes the padding highlights that were added when changing the grid @@ -5329,6 +5326,22 @@ registry.layout_column = SnippetOptionWidget.extend({ }, }); +registry.vAlignment = SnippetOptionWidget.extend({ + /** + * @override + */ + async _computeWidgetState(methodName, params) { + const value = await this._super(...arguments); + if (methodName === 'selectClass' && !value) { + // If there is no `align-items-` class on the row, then the `align- + // items-stretch` class is selected, because the behaviors are + // equivalent in both situations. + return 'align-items-stretch'; + } + return value; + }, +}); + /** * Allows snippets to be moved before the preceding element or after the following. */