Skip to content

Commit b3b7064

Browse files
committed
[FIX] topbar: close font size editor dropdown and focus grid
Pressing Tab in the font size editor could move focus to the hidden “add more rows” footer. The browser then auto-scrolled to the footer while the grid viewport state stayed unchanged, making the footer appear floating above the grid. The font size editor now closes its dropdown when it loses focus (blur/Tab), and focus is redirected back to the grid instead of going to the footer, preventing the layout from breaking when tabbing from the toolbar. Task: 5263792
1 parent 60a66b6 commit b3b7064

File tree

6 files changed

+27
-4
lines changed

6 files changed

+27
-4
lines changed

src/components/font_size_editor/font_size_editor.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ export class FontSizeEditor extends Component<Props, SpreadsheetChildEnv> {
4949

5050
dropdown: State = useState({ isOpen: false });
5151

52-
private inputRef = useRef("inputFontSize");
5352
private rootEditorRef = useRef("FontSizeEditor");
5453

5554
setup() {
@@ -70,7 +69,7 @@ export class FontSizeEditor extends Component<Props, SpreadsheetChildEnv> {
7069
const isOpen = this.dropdown.isOpen;
7170
if (!isOpen) {
7271
this.props.onToggle();
73-
this.inputRef.el!.focus();
72+
this.dropdown.isOpen = true;
7473
} else {
7574
this.closeFontList();
7675
}
@@ -110,6 +109,11 @@ export class FontSizeEditor extends Component<Props, SpreadsheetChildEnv> {
110109
this.props.onToggle();
111110
}
112111
}
112+
113+
onInputBlurred(ev: FocusEvent) {
114+
this.closeFontList();
115+
this.props.onToggle();
116+
}
113117
}
114118

115119
FontSizeEditor.props = {

src/components/font_size_editor/font_size_editor.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
t-on-wheel.prevent.stop=""
1616
t-on-click.stop=""
1717
t-on-focus.stop="onInputFocused"
18+
t-on-blur="onInputBlurred"
1819
t-att-value="currentFontSize"
1920
t-on-change="setSizeFromInput"
20-
t-ref="inputFontSize"
2121
/>
2222
<span>
2323
<t t-call="o-spreadsheet-Icon.TRIANGLE_DOWN"/>

src/components/grid_add_rows_footer/grid_add_rows_footer.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
<button
88
t-on-click="onConfirm"
99
t-att-disabled="state.errorFlag"
10-
class="o-button o-button-grey">
10+
class="o-button o-button-grey"
11+
tabindex="-1">
1112
Add
1213
</button>
1314
<input
@@ -19,6 +20,7 @@
1920
t-on-keydown.stop="onKeydown"
2021
t-on-mousedown.stop=""
2122
t-on-input.stop="onInput"
23+
tabindex="-1"
2224
/>
2325
<span>more rows at the bottom</span>
2426
<ValidationMessages t-if="state.errorFlag" messages="errorMessages" msgType="'error'"/>

tests/grid/__snapshots__/grid_component.test.ts.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@ exports[`Grid component simple rendering snapshot 1`] = `
2727
>
2828
<button
2929
class="o-button o-button-grey"
30+
tabindex="-1"
3031
>
3132
Add
3233
</button>
3334
<input
3435
class="o-grid-add-rows-input o-input mt-0 me-2"
36+
tabindex="-1"
3537
type="text"
3638
value="100"
3739
/>

tests/spreadsheet/__snapshots__/spreadsheet_component.test.ts.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,11 +642,13 @@ exports[`Simple Spreadsheet Component simple rendering snapshot 1`] = `
642642
>
643643
<button
644644
class="o-button o-button-grey"
645+
tabindex="-1"
645646
>
646647
Add
647648
</button>
648649
<input
649650
class="o-grid-add-rows-input o-input mt-0 me-2"
651+
tabindex="-1"
650652
type="text"
651653
value="100"
652654
/>

tests/top_bar_component.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,19 @@ describe("TopBar component", () => {
339339
expect(getStyle(model, "A1").fontSize).toBe(8);
340340
});
341341

342+
test("Tab from font size editor closes the dropdown", async () => {
343+
const { fixture } = await mountSpreadsheet();
344+
const input = fixture.querySelector("input.o-font-size") as HTMLInputElement;
345+
input.focus();
346+
await nextTick();
347+
expect(fixture.querySelector(".o-dropdown-content.o-text-options")).toBeTruthy();
348+
input.blur();
349+
await nextTick();
350+
expect(fixture.querySelector(".o-dropdown-content.o-text-options")).toBeFalsy();
351+
const composerEl = fixture.querySelector<HTMLElement>(".o-grid-composer .o-composer")!;
352+
expect(document.activeElement).toBe(composerEl);
353+
});
354+
342355
test("prevents default behavior of mouse wheel event on font size input", async () => {
343356
await mountParent();
344357
const fontSizeInput = fixture.querySelector("input.o-font-size") as HTMLInputElement;

0 commit comments

Comments
 (0)