Skip to content

Commit 46e5d92

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. Task: 5016252
1 parent 5c3234b commit 46e5d92

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
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: 22 additions & 2 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();
@@ -352,8 +356,9 @@ describe("BottomBar component", () => {
352356

353357
sheetName.innerHTML = HTML;
354358
await keyDown({ key: "Enter" });
355-
356-
expect(sheetName.getAttribute("contenteditable")).toEqual("false");
359+
expect(
360+
fixture.querySelector<HTMLElement>(".o-sheet-name")!.getAttribute("contenteditable")
361+
).toEqual("false");
357362
await nextTick();
358363

359364
expect(sheetName.innerText).toEqual("HELLO");
@@ -371,6 +376,21 @@ describe("BottomBar component", () => {
371376
expect(env.focusableElement.focus).toHaveBeenCalled();
372377
}
373378
);
379+
380+
test("Displayed sheet name is udpated on undo/redo", async () => {
381+
const sheetName = getSheetNameSpan()!;
382+
expect(sheetName.textContent).toEqual("Sheet1");
383+
await doubleClick(sheetName);
384+
sheetName.textContent = "ThisIsASheet";
385+
await keyDown({ key: "Enter" });
386+
expect(getSheetNameSpan()!.textContent).toEqual("ThisIsASheet");
387+
undo(model);
388+
await nextTick();
389+
expect(getSheetNameSpan()!.textContent).toEqual("Sheet1");
390+
redo(model);
391+
await nextTick();
392+
expect(getSheetNameSpan()!.textContent).toEqual("ThisIsASheet");
393+
});
374394
});
375395

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

0 commit comments

Comments
 (0)