Skip to content

Commit 98cf4fb

Browse files
committed
[FIX] BottomBarSheet: sheet name should update on foreign changes
How to reproduce: On Firefox, - double click the bottom bar to rename a sheet - Undo the change (button or through Ctrl-Z) => the sheetName is not rolled back to its previous value The issue seems to lie in the fact that in FF, setting a t-esc on an Element that was previously `contenteditable=true` creates weird behaviour. I suspect some internal state of the div that is not cleared. On the other hand, changing the contenteditable state of the span element might not be the best idea and one could consider that it's safer to simply regenerate the span altogether when switching editing state. This commit takes the last suggested approach. closes #7544 Task: 5016252 X-original-commit: f0b3792 Signed-off-by: Pierre Rousseau (pro) <pro@odoo.com>
1 parent 27966e6 commit 98cf4fb

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

src/components/bottom_bar/bottom_bar_sheet/bottom_bar_sheet.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
t-on-click="onClick"
1010
t-on-contextmenu.prevent="(ev) => this.onContextMenu(ev)"
1111
t-ref="sheetDiv"
12+
t-key="sheetName"
1213
t-att-style="props.style"
1314
t-att-title="sheetName"
1415
t-att-data-id="props.sheetId"

tests/bottom_bar/bottom_bar_component.test.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ async function mountBottomBar(
5959
return { parent, model, env };
6060
}
6161

62+
function getSheetNameSpan(): HTMLSpanElement | null {
63+
return fixture.querySelector<HTMLSpanElement>(".o-sheet-name");
64+
}
65+
6266
describe("BottomBar component", () => {
6367
test("simple rendering", async () => {
6468
await mountBottomBar();
@@ -339,14 +343,13 @@ describe("BottomBar component", () => {
339343
test("Pasting styled content in sheet name and renaming sheet does not throw a trackback", async () => {
340344
const HTML = `<span style="color: rgb(242, 44, 61); background-color: rgb(0, 0, 0);">HELLO</span>`;
341345

342-
const sheetName = fixture.querySelector<HTMLElement>(".o-sheet-name")!;
346+
const sheetName = getSheetNameSpan()!;
343347
triggerMouseEvent(sheetName, "dblclick");
344348
await nextTick();
345349

346350
sheetName.innerHTML = HTML;
347351
await keyDown({ key: "Enter" });
348-
349-
expect(sheetName.getAttribute("contenteditable")).toEqual("false");
352+
expect(getSheetNameSpan()!.getAttribute("contenteditable")).toEqual("false");
350353
await nextTick();
351354

352355
expect(sheetName.innerText).toEqual("HELLO");
@@ -368,6 +371,21 @@ describe("BottomBar component", () => {
368371
expect(focusableElementStore.focus).toHaveBeenCalled();
369372
}
370373
);
374+
375+
test("Displayed sheet name is udpated on undo/redo", async () => {
376+
const sheetName = getSheetNameSpan()!;
377+
expect(sheetName.textContent).toEqual("Sheet1");
378+
await doubleClick(sheetName);
379+
sheetName.textContent = "ThisIsASheet";
380+
await keyDown({ key: "Enter" });
381+
expect(getSheetNameSpan()!.textContent).toEqual("ThisIsASheet");
382+
undo(model);
383+
await nextTick();
384+
expect(getSheetNameSpan()!.textContent).toEqual("Sheet1");
385+
redo(model);
386+
await nextTick();
387+
expect(getSheetNameSpan()!.textContent).toEqual("ThisIsASheet");
388+
});
371389
});
372390

373391
test("Can't rename a sheet in readonly mode", async () => {

0 commit comments

Comments
 (0)