Skip to content

Commit c5c03e1

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 #7543 Task: 5016252 X-original-commit: f0b3792 Signed-off-by: Pierre Rousseau (pro) <pro@odoo.com>
1 parent d4b38dc commit c5c03e1

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
@@ -58,6 +58,10 @@ async function mountBottomBar(
5858
return { parent, model, env };
5959
}
6060

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

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

345349
sheetName.innerHTML = HTML;
346350
await keyDown({ key: "Enter" });
347-
348-
expect(sheetName.getAttribute("contenteditable")).toEqual("false");
351+
expect(getSheetNameSpan()!.getAttribute("contenteditable")).toEqual("false");
349352
await nextTick();
350353

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

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

0 commit comments

Comments
 (0)