diff --git a/src/components/bottom_bar_sheet/bottom_bar_sheet.ts b/src/components/bottom_bar_sheet/bottom_bar_sheet.ts index fcf84c3fa..a59f6b770 100644 --- a/src/components/bottom_bar_sheet/bottom_bar_sheet.ts +++ b/src/components/bottom_bar_sheet/bottom_bar_sheet.ts @@ -155,13 +155,16 @@ export class BottomBarSheet extends Component { } private stopEdition() { - if (!this.state.isEditing) return; + const input = this.sheetNameRef.el; + if (!this.state.isEditing || !input) return; this.state.isEditing = false; this.editionState = "initializing"; - this.sheetNameRef.el?.blur(); + input.blur(); const inputValue = this.getInputContent() || ""; + input.innerText = inputValue; + interactiveRenameSheet(this.env, this.props.sheetId, inputValue, () => this.startEdition()); } diff --git a/src/components/bottom_bar_sheet/bottom_bar_sheet.xml b/src/components/bottom_bar_sheet/bottom_bar_sheet.xml index 507ee83eb..9fe2f5d41 100644 --- a/src/components/bottom_bar_sheet/bottom_bar_sheet.xml +++ b/src/components/bottom_bar_sheet/bottom_bar_sheet.xml @@ -19,7 +19,7 @@ t-on-dblclick="() => this.onDblClick()" t-on-focusout="() => this.onFocusOut()" t-on-keydown="(ev) => this.onKeyDown(ev)" - t-att-contenteditable="state.isEditing ? 'plaintext-only': 'false'" + t-att-contenteditable="state.isEditing ? 'true': 'false'" /> diff --git a/tests/components/bottom_bar.test.ts b/tests/components/bottom_bar.test.ts index 5d00d3213..0b327b3cd 100644 --- a/tests/components/bottom_bar.test.ts +++ b/tests/components/bottom_bar.test.ts @@ -258,7 +258,7 @@ describe("BottomBar component", () => { expect(sheetName.getAttribute("contenteditable")).toEqual("false"); triggerMouseEvent(sheetName, "dblclick"); await nextTick(); - expect(sheetName.getAttribute("contenteditable")).toEqual("plaintext-only"); + expect(sheetName.getAttribute("contenteditable")).toEqual("true"); expect(document.activeElement).toEqual(sheetName); }); @@ -277,7 +277,7 @@ describe("BottomBar component", () => { await nextTick(); await click(fixture, ".o-menu-item[data-name='rename'"); const sheetName = fixture.querySelector(".o-sheet-name")!; - expect(sheetName.getAttribute("contenteditable")).toEqual("plaintext-only"); + expect(sheetName.getAttribute("contenteditable")).toEqual("true"); expect(document.activeElement).toEqual(sheetName); }); @@ -337,6 +337,22 @@ describe("BottomBar component", () => { expect(window.getSelection()?.toString()).toEqual("ThisIsASheet"); expect(document.activeElement).toEqual(sheetName); }); + + test("Pasting styled content in sheet name and renaming sheet does not throw a trackback", async () => { + const HTML = `HELLO`; + + const sheetName = fixture.querySelector(".o-sheet-name")!; + triggerMouseEvent(sheetName, "dblclick"); + await nextTick(); + + sheetName.innerHTML = HTML; + await keyDown({ key: "Enter" }); + + expect(sheetName.getAttribute("contenteditable")).toEqual("false"); + await nextTick(); + + expect(sheetName.innerText).toEqual("HELLO"); + }); }); test("Can't rename a sheet in readonly mode", async () => { diff --git a/tests/setup/jest.setup.ts b/tests/setup/jest.setup.ts index b2ec794c8..58864c3e6 100644 --- a/tests/setup/jest.setup.ts +++ b/tests/setup/jest.setup.ts @@ -12,6 +12,15 @@ export let OWL_TEMPLATES: Document; beforeAll(() => { OWL_TEMPLATES = getParsedOwlTemplateBundle(); setDefaultSheetViewSize(1000); + Object.defineProperty(Element.prototype, "innerText", { + get: function myProperty() { + return this.textContent; + }, + set: function myProperty(value) { + this.textContent = value; + this.innerHTML = value; + }, + }); }); beforeEach(() => {