Skip to content

Commit f0b3792

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 #7381 Task: 5016252 Signed-off-by: Pierre Rousseau (pro) <pro@odoo.com>
1 parent 498c3fc commit f0b3792

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

src/components/bottom_bar_sheet/bottom_bar_sheet.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
t-on-mousedown="(ev) => this.onMouseDown(ev)"
77
t-on-contextmenu.prevent="(ev) => this.onContextMenu(ev)"
88
t-ref="sheetDiv"
9+
t-key="sheetName"
910
t-att-style="props.style"
1011
t-att-title="sheetName"
1112
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
@@ -67,6 +67,10 @@ async function mountBottomBar(
6767
return { parent: parent as Parent, model, env };
6868
}
6969

70+
function getSheetNameSpan(): HTMLSpanElement | null {
71+
return fixture.querySelector<HTMLSpanElement>(".o-sheet-name");
72+
}
73+
7074
describe("BottomBar component", () => {
7175
test("simple rendering", async () => {
7276
await mountBottomBar();
@@ -346,14 +350,13 @@ describe("BottomBar component", () => {
346350
test("Pasting styled content in sheet name and renaming sheet does not throw a trackback", async () => {
347351
const HTML = `<span style="color: rgb(242, 44, 61); background-color: rgb(0, 0, 0);">HELLO</span>`;
348352

349-
const sheetName = fixture.querySelector<HTMLElement>(".o-sheet-name")!;
353+
const sheetName = getSheetNameSpan()!;
350354
triggerMouseEvent(sheetName, "dblclick");
351355
await nextTick();
352356

353357
sheetName.innerHTML = HTML;
354358
await keyDown({ key: "Enter" });
355-
356-
expect(sheetName.getAttribute("contenteditable")).toEqual("false");
359+
expect(getSheetNameSpan()!.getAttribute("contenteditable")).toEqual("false");
357360
await nextTick();
358361

359362
expect(sheetName.innerText).toEqual("HELLO");
@@ -371,6 +374,21 @@ describe("BottomBar component", () => {
371374
expect(env.focusableElement.focus).toHaveBeenCalled();
372375
}
373376
);
377+
378+
test("Displayed sheet name is udpated on undo/redo", async () => {
379+
const sheetName = getSheetNameSpan()!;
380+
expect(sheetName.textContent).toEqual("Sheet1");
381+
await doubleClick(sheetName);
382+
sheetName.textContent = "ThisIsASheet";
383+
await keyDown({ key: "Enter" });
384+
expect(getSheetNameSpan()!.textContent).toEqual("ThisIsASheet");
385+
undo(model);
386+
await nextTick();
387+
expect(getSheetNameSpan()!.textContent).toEqual("Sheet1");
388+
redo(model);
389+
await nextTick();
390+
expect(getSheetNameSpan()!.textContent).toEqual("ThisIsASheet");
391+
});
374392
});
375393

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

0 commit comments

Comments
 (0)