Skip to content

Commit 5fafd0e

Browse files
committed
[IMP] website, *: hide overlay button when toolbar is active
`*=html_builder, html_editor` - Hide overlay buttons when editor toolbar is active as this leads to a confusion for users. task-4789254
1 parent 506d968 commit 5fafd0e

File tree

4 files changed

+51
-6
lines changed

4 files changed

+51
-6
lines changed

addons/html_builder/static/src/core/overlay_buttons/overlay_buttons.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
<div t-att-class="{'d-none': !state.showUi or !state.isVisible}" class="o-we-toolbar o_overlay_options shadow rounded my-2">
55
<t t-foreach="state.buttons" t-as="button" t-key="button_index">
66
<!-- Disabled buttons do not display their title -->
7-
<span class="o-we-toolbar-vertical-separator"></span>
87
<span class="btn-group" t-att-title="button.disabledReason" t-att-aria-label="button.disabledReason">
98
<t t-if="button.Component" t-component="button.Component" t-props="button.props || {}"/>
109
<t t-else="">

addons/html_builder/static/src/core/overlay_buttons/overlay_buttons_plugin.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@ import { withSequence } from "@html_editor/utils/resource";
88

99
export class OverlayButtonsPlugin extends Plugin {
1010
static id = "overlayButtons";
11-
static dependencies = ["selection", "overlay", "history", "operation"];
11+
static dependencies = ["selection", "overlay", "history", "operation", "toolbar"];
1212
static shared = [
1313
"hideOverlayButtons",
1414
"showOverlayButtons",
1515
"hideOverlayButtonsUi",
1616
"showOverlayButtonsUi",
1717
];
1818
resources = {
19+
selectionchange_handlers: this.shouldShowToolbar.bind(this),
20+
selection_leave_handlers: this.showOverlayButtonsUi.bind(this),
1921
step_added_handlers: this.refreshButtons.bind(this),
2022
change_current_options_containers_listeners: this.addOverlayButtons.bind(this),
2123
on_mobile_preview_clicked: withSequence(20, this.refreshButtons.bind(this)),
@@ -123,6 +125,17 @@ export class OverlayButtonsPlugin extends Plugin {
123125
this.overlay.updatePosition();
124126
}
125127

128+
shouldShowToolbar() {
129+
clearTimeout(this.toolbarTimeout);
130+
this.toolbarTimeout = setTimeout(() => {
131+
if (this.dependencies.toolbar.getIsToolbarOpen()) {
132+
this.hideOverlayButtonsUi();
133+
} else {
134+
this.showOverlayButtonsUi();
135+
}
136+
}, 300);
137+
}
138+
126139
hideOverlayButtons() {
127140
this.state.isVisible = false;
128141
}

addons/html_editor/static/src/main/toolbar/toolbar_plugin.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ const MIN_SIZE_FOR_COMPACT = 7;
143143
export class ToolbarPlugin extends Plugin {
144144
static id = "toolbar";
145145
static dependencies = ["overlay", "selection", "userCommand"];
146-
static shared = ["getToolbarInfo"];
146+
static shared = ["getToolbarInfo", "getIsToolbarOpen"];
147147
resources = {
148148
selectionchange_handlers: this.handleSelectionChange.bind(this),
149149
selection_leave_handlers: () => this.closeToolbar(),
@@ -328,6 +328,10 @@ export class ToolbarPlugin extends Plugin {
328328
};
329329
}
330330

331+
getIsToolbarOpen() {
332+
return this.overlay.isOpen;
333+
}
334+
331335
handleSelectionChange(selectionData) {
332336
if (this.onSelectionChangeActive) {
333337
this.updateToolbar(selectionData);

addons/website/static/tests/builder/overlay_buttons.test.js

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { undo } from "@html_editor/../tests/_helpers/user_actions";
22
import { Plugin } from "@html_editor/plugin";
3-
import { setContent } from "@html_editor/../tests/_helpers/selection";
4-
import { expect, test } from "@odoo/hoot";
5-
import { Deferred, tick } from "@odoo/hoot-dom";
3+
import { setContent, setSelection } from "@html_editor/../tests/_helpers/selection";
4+
import { animationFrame, expect, test } from "@odoo/hoot";
5+
import { Deferred, tick, waitFor } from "@odoo/hoot-dom";
66
import { xml } from "@odoo/owl";
77
import { contains } from "@web/../tests/web_test_helpers";
88
import {
@@ -352,3 +352,32 @@ test("An inner snippet alone in a column should not have overlay options", async
352352
expect(".oe_overlay").toHaveCount(3);
353353
expect(".oe_overlay.oe_active").toHaveCount(1);
354354
});
355+
356+
test("The overlay buttons should be hidden when the toolbar is open", async () => {
357+
const { getEditor } = await setupWebsiteBuilder(`
358+
<section>
359+
<div class="container">
360+
<div class="test-options-target">test here</div>
361+
</div>
362+
</section>
363+
`);
364+
const editor = getEditor();
365+
// Check that the overlay buttons are not hidden.
366+
await contains(":iframe .test-options-target").click();
367+
expect(".o-we-toolbar.o_overlay_options:not(.d-none)").toHaveCount(1);
368+
const text = editor.editable.querySelector(".test-options-target");
369+
const selection = {
370+
anchorNode: text.childNodes[0],
371+
anchorOffset: 2,
372+
focusNode: text.childNodes[0],
373+
focusOffset: 5,
374+
};
375+
setSelection(selection);
376+
await animationFrame();
377+
// Check that the toolbar buttons are shown.
378+
await waitFor(".o-we-toolbar:not(.o_overlay_options)");
379+
expect(".o-we-toolbar:not(.o_overlay_options)").toHaveCount(1);
380+
// Check that the overlay buttons are hidden.
381+
await waitFor(".o-we-toolbar.o_overlay_options.d-none", { timeout: 300 });
382+
expect(".o-we-toolbar.o_overlay_options.d-none").toHaveCount(1);
383+
});

0 commit comments

Comments
 (0)