Skip to content

Build your personal knowledge base with Trilium Notes

fix(text): keep the toolbar still as a menu replaces the keyboard

Elian Doran71aafd5efba3
diff --git a/apps/client/src/widgets/type_widgets/text/mobile_editor_toolbar.css b/apps/client/src/widgets/type_widgets/text/mobile_editor_toolbar.css
index ef7586ca2c..41a6f0b445 100644
--- a/apps/client/src/widgets/type_widgets/text/mobile_editor_toolbar.css
+++ b/apps/client/src/widgets/type_widgets/text/mobile_editor_toolbar.css
@@ -97,7 +97,6 @@ body.mobile {
.classic-toolbar-island {
bottom: var(--keyboard-panel-lift);
- margin-bottom: 0;
border-end-start-radius: 0;
border-end-end-radius: 0;
@@ -114,8 +113,8 @@ body.mobile {
.dropdown-menu.mobile-bottom-menu.keyboard-panel.show {
--dropdown-bottom: calc(-1 * var(--tn-layout-shrink, 0px));
- height: var(--tn-keyboard-height);
- max-height: var(--tn-keyboard-height);
+ height: calc(var(--tn-keyboard-height) + var(--mobile-toolbar-gap));
+ max-height: calc(var(--tn-keyboard-height) + var(--mobile-toolbar-gap));
}
.dropdown-menu.mobile-bottom-menu.keyboard-panel.keyboard-panel-own-height.show {
diff --git a/apps/client/src/widgets/type_widgets/text/mobile_editor_toolbar.spec.tsx b/apps/client/src/widgets/type_widgets/text/mobile_editor_toolbar.spec.tsx
index 5a3437844d..850625c1dd 100644
--- a/apps/client/src/widgets/type_widgets/text/mobile_editor_toolbar.spec.tsx
+++ b/apps/client/src/widgets/type_widgets/text/mobile_editor_toolbar.spec.tsx
@@ -94,15 +94,18 @@ describe("useKeyboardPanel", () => {
it("sizes the place by the menu with no keyboard, giving it back as the menu closes", async () => {
const { editable, host } = buildPanelFixture();
document.body.style.setProperty("--tn-keyboard-height", "300px");
+ document.body.style.setProperty("--mobile-toolbar-gap", "6px");
const height = vi.spyOn(HTMLElement.prototype, "offsetHeight", "get").mockReturnValue(240);
function Menu() {
const { measureRef } = useKeyboardPanel(true);
return <div ref={measureRef} />;
}
+ // The menu rises by the toolbar's gap above the place, to meet the toolbar.
act(() => render(<Menu />, host));
expect(isKeyboardPanelOpen()).toBe(true);
- expect(document.body.style.getPropertyValue("--tn-keyboard-height")).toBe("240px");
+ expect(document.body.style.getPropertyValue("--tn-keyboard-height")).toBe("234px");
+ document.body.style.removeProperty("--mobile-toolbar-gap");
// An entry that runs focuses the text, and no keyboard comes up to take the place over.
await act(async () => {
diff --git a/apps/client/src/widgets/type_widgets/text/mobile_editor_toolbar.tsx b/apps/client/src/widgets/type_widgets/text/mobile_editor_toolbar.tsx
index 273b6aa502..f615b09a4d 100644
--- a/apps/client/src/widgets/type_widgets/text/mobile_editor_toolbar.tsx
+++ b/apps/client/src/widgets/type_widgets/text/mobile_editor_toolbar.tsx
@@ -165,7 +165,7 @@ function useActiveToolbarElement(editor: CKTextEditor | undefined, pluginName: "
* the place, which it takes over without a reveal.
*
* With no keyboard up, the menu takes a place of its own height (`isOwnHeight`): `measureRef` on
- * its element sets `--tn-keyboard-height` to that height while it is open.
+ * its element sets `--tn-keyboard-height` to that height, less the toolbar's gap, while it is open.
*/
export function useKeyboardPanel(enabled: boolean) {
const [ { isPanel, replacesPanel, isOwnHeight } ] = useState(() => {
@@ -187,8 +187,10 @@ export function useKeyboardPanel(enabled: boolean) {
useLayoutEffect(() => {
if (!element || !isOwnHeight) return;
+ // The menu rises by `--mobile-toolbar-gap` above the place, to meet the toolbar.
+ const gap = parseFloat(getComputedStyle(document.body).getPropertyValue("--mobile-toolbar-gap")) || 0;
const measure = () => {
- document.body.style.setProperty("--tn-keyboard-height", `${element.offsetHeight}px`);
+ document.body.style.setProperty("--tn-keyboard-height", `${element.offsetHeight - gap}px`);
};
measure();
const observer = new ResizeObserver(measure);