Skip to content

Commit a65928c

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 5b662b8 commit a65928c

File tree

3 files changed

+51
-5
lines changed

3 files changed

+51
-5
lines changed

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+
}, 500);
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 {
@@ -350,3 +350,32 @@ test("An inner snippet alone in a column should not have overlay options", async
350350
expect(".oe_overlay").toHaveCount(3);
351351
expect(".oe_overlay.oe_active").toHaveCount(1);
352352
});
353+
354+
test("The overlay buttons should be hidden when the toolbar is open", async () => {
355+
const { getEditor } = await setupWebsiteBuilder(`
356+
<section>
357+
<div class="container">
358+
<div class="test-options-target">test here</div>
359+
</div>
360+
</section>
361+
`);
362+
const editor = getEditor();
363+
// Check that the overlay buttons are not hidden.
364+
await contains(":iframe .test-options-target").click();
365+
expect(".o-we-toolbar.o_overlay_options:not(.d-none)").toHaveCount(1);
366+
const text = editor.editable.querySelector(".test-options-target");
367+
const selection = {
368+
anchorNode: text.childNodes[0],
369+
anchorOffset: 2,
370+
focusNode: text.childNodes[0],
371+
focusOffset: 5,
372+
};
373+
setSelection(selection);
374+
await animationFrame();
375+
// Check that the toolbar buttons are shown.
376+
await waitFor(".o-we-toolbar:not(.o_overlay_options)");
377+
expect(".o-we-toolbar:not(.o_overlay_options)").toHaveCount(1);
378+
// Check that the overlay buttons are hidden.
379+
await waitFor(".o-we-toolbar.o_overlay_options.d-none", { timeout: 500 });
380+
expect(".o-we-toolbar.o_overlay_options.d-none").toHaveCount(1);
381+
});

0 commit comments

Comments
 (0)