fix(mobile/tree): "toggle sidebar" tooltip shown after opening sidebar

This commit is contained in:
Elian Doran 2026-02-19 18:31:38 +02:00
parent 0110b3c4a2
commit 4ebc4ece34
No known key found for this signature in database
2 changed files with 14 additions and 5 deletions

View File

@ -1,5 +1,5 @@
import ActionButton from "../react/ActionButton";
import { t } from "../../services/i18n";
import ActionButton from "../react/ActionButton";
import { useNoteContext } from "../react/hooks";
export default function ToggleSidebarButton() {
@ -10,10 +10,15 @@ export default function ToggleSidebarButton() {
{ noteContext?.isMainContext() && <ActionButton
icon="bx bx-sidebar"
text={t("note_tree.toggle-sidebar")}
onClick={() => parentComponent?.triggerCommand("setActiveScreen", {
screen: "tree"
})}
onClick={(e) => {
// Remove focus to prevent tooltip showing on top of the sidebar.
(e.currentTarget as HTMLButtonElement).blur();
parentComponent?.triggerCommand("setActiveScreen", {
screen: "tree"
});
}}
/>}
</div>
)
);
}

View File

@ -3,6 +3,7 @@ import { useEffect, useRef, useState } from "preact/hooks";
import { CommandNames } from "../../components/app_context";
import keyboard_actions from "../../services/keyboard_actions";
import { isMobile } from "../../services/utils";
import { useStaticTooltip } from "./hooks";
export interface ActionButtonProps extends Pick<HTMLAttributes<HTMLButtonElement>, "onClick" | "onAuxClick" | "onContextMenu" | "style"> {
@ -17,6 +18,8 @@ export interface ActionButtonProps extends Pick<HTMLAttributes<HTMLButtonElement
disabled?: boolean;
}
const cachedIsMobile = isMobile();
export default function ActionButton({ text, icon, className, triggerCommand, titlePosition, noIconActionClass, frame, active, disabled, ...restProps }: ActionButtonProps) {
const buttonRef = useRef<HTMLButtonElement>(null);
const [ keyboardShortcut, setKeyboardShortcut ] = useState<string[]>();
@ -25,6 +28,7 @@ export default function ActionButton({ text, icon, className, triggerCommand, ti
title: keyboardShortcut?.length ? `${text} (${keyboardShortcut?.join(",")})` : text,
placement: titlePosition ?? "bottom",
fallbackPlacements: [ titlePosition ?? "bottom" ],
trigger: cachedIsMobile ? "focus" : "hover focus",
animation: false
});