Skip to content

Commit cb92d82

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

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
@@ -8,6 +8,7 @@
88
t-on-pointerdown="(ev) => this.onMouseDown(ev)"
99
t-on-contextmenu.prevent="(ev) => this.onContextMenu(ev)"
1010
t-ref="sheetDiv"
11+
t-key="sheetName"
1112
t-att-style="props.style"
1213
t-att-title="sheetName"
1314
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
@@ -57,6 +57,10 @@ async function mountBottomBar(
5757
return { parent, model, env };
5858
}
5959

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

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

344348
sheetName.innerHTML = HTML;
345349
await keyDown({ key: "Enter" });
346-
347-
expect(sheetName.getAttribute("contenteditable")).toEqual("false");
350+
expect(getSheetNameSpan()!.getAttribute("contenteditable")).toEqual("false");
348351
await nextTick();
349352

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

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

0 commit comments

Comments
 (0)