Skip to content

Build your personal knowledge base with Trilium Notes

fix(mobile): keep the hide-keyboard button usable over dialogs

Elian Doran852f4f4b0275
diff --git a/apps/client/src/widgets/mobile_widgets/hide_keyboard_button.css b/apps/client/src/widgets/mobile_widgets/hide_keyboard_button.css
index 88dd1114f1..c062092ae2 100644
--- a/apps/client/src/widgets/mobile_widgets/hide_keyboard_button.css
+++ b/apps/client/src/widgets/mobile_widgets/hide_keyboard_button.css
@@ -7,7 +7,9 @@ body.mobile .hide-keyboard-button {
position: fixed;
bottom: 0;
inset-inline-end: 0;
- z-index: 1000;
+ /* Above every dialog (2000, plus 10 per stacked one in `dialog.ts`) and menu,
+ below tooltips (9999). */
+ z-index: 5000;
transform: translateY(var(--tn-keyboard-gap, 0px));
.icon-action {
diff --git a/apps/client/src/widgets/mobile_widgets/hide_keyboard_button.spec.tsx b/apps/client/src/widgets/mobile_widgets/hide_keyboard_button.spec.tsx
index 6a81cc98f7..794be82dd6 100644
--- a/apps/client/src/widgets/mobile_widgets/hide_keyboard_button.spec.tsx
+++ b/apps/client/src/widgets/mobile_widgets/hide_keyboard_button.spec.tsx
@@ -57,6 +57,10 @@ describe("HideKeyboardButton", () => {
const button = container.querySelector("button");
expect(button).not.toBeNull();
+ const press = new MouseEvent("mousedown", { bubbles: true, cancelable: true });
+ button?.dispatchEvent(press);
+ expect(press.defaultPrevented).toBe(true);
+
act(() => button?.click());
expect(document.activeElement).not.toBe(input);
expect(container.querySelector("button")).toBeNull();
diff --git a/apps/client/src/widgets/mobile_widgets/hide_keyboard_button.tsx b/apps/client/src/widgets/mobile_widgets/hide_keyboard_button.tsx
index a695fb73ce..3c242ed926 100644
--- a/apps/client/src/widgets/mobile_widgets/hide_keyboard_button.tsx
+++ b/apps/client/src/widgets/mobile_widgets/hide_keyboard_button.tsx
@@ -31,7 +31,9 @@ export default function HideKeyboardButton() {
}, [ enabled ]);
return (
- <div className="hide-keyboard-button">
+ // Keeps the press from moving the focus onto the button: an open dialog's focus trap would
+ // send it back into the dialog and bring the keyboard up again.
+ <div className="hide-keyboard-button" onMouseDown={(e) => e.preventDefault()}>
{enabled && editableFocused && (
<ActionButton
icon="bx bx-chevron-down"