Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FW][FIX] BottomBarSheet: Rename a sheet with style content on Firefox #3921

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/components/bottom_bar_sheet/bottom_bar_sheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,16 @@ export class BottomBarSheet extends Component<Props, SpreadsheetChildEnv> {
}

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());
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/bottom_bar_sheet/bottom_bar_sheet.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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'"
/>
<span class="o-sheet-icon ms-1" t-on-click.stop="(ev) => this.onIconClick(ev)">
<t t-call="o-spreadsheet-Icon.TRIANGLE_DOWN"/>
Expand Down
21 changes: 19 additions & 2 deletions tests/bottom_bar/bottom_bar_component.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,8 @@ describe("BottomBar component", () => {
const sheetName = fixture.querySelector<HTMLElement>(".o-sheet-name")!;
expect(sheetName.getAttribute("contenteditable")).toEqual("false");
await doubleClick(sheetName);
expect(sheetName.getAttribute("contenteditable")).toEqual("plaintext-only");
await nextTick();
expect(sheetName.getAttribute("contenteditable")).toEqual("true");
expect(document.activeElement).toEqual(sheetName);
});

Expand All @@ -272,7 +273,7 @@ describe("BottomBar component", () => {
await nextTick();
await click(fixture, ".o-menu-item[data-name='rename'");
const sheetName = fixture.querySelector<HTMLElement>(".o-sheet-name")!;
expect(sheetName.getAttribute("contenteditable")).toEqual("plaintext-only");
expect(sheetName.getAttribute("contenteditable")).toEqual("true");
expect(document.activeElement).toEqual(sheetName);
});

Expand Down Expand Up @@ -337,6 +338,22 @@ describe("BottomBar component", () => {
expect(raiseError).not.toHaveBeenCalled();
expect(sheetName.textContent).toEqual("SHEET1");
});

test("Pasting styled content in sheet name and renaming sheet does not throw a trackback", async () => {
const HTML = `<span style="color: rgb(242, 44, 61); background-color: rgb(0, 0, 0);">HELLO</span>`;

const sheetName = fixture.querySelector<HTMLElement>(".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 () => {
Expand Down
9 changes: 9 additions & 0 deletions tests/setup/jest.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ beforeAll(() => {
(str, ...values) => str,
() => true
);
Object.defineProperty(Element.prototype, "innerText", {
get: function () {
return this.textContent;
},
set: function (value) {
this.textContent = value;
this.innerHTML = value;
},
});
});

beforeEach(() => {
Expand Down