From 83fd42aff29156a68f5588fb93ee2df98fdd9797 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Fri, 29 Aug 2025 11:54:16 +0300 Subject: [PATCH] feat(react): add bootstrap tooltip to menu items --- apps/client/src/widgets/react/FormList.tsx | 28 +++++++++++++++++++++- apps/client/src/widgets/react/hooks.tsx | 3 ++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/apps/client/src/widgets/react/FormList.tsx b/apps/client/src/widgets/react/FormList.tsx index 5e3bae3cf..7b44ad69d 100644 --- a/apps/client/src/widgets/react/FormList.tsx +++ b/apps/client/src/widgets/react/FormList.tsx @@ -1,9 +1,10 @@ -import { Dropdown as BootstrapDropdown } from "bootstrap"; +import { Dropdown as BootstrapDropdown, Tooltip } from "bootstrap"; import { ComponentChildren } from "preact"; import Icon from "./Icon"; import { useEffect, useMemo, useRef, type CSSProperties } from "preact/compat"; import "./FormList.css"; import { CommandNames } from "../../components/app_context"; +import { useStaticTooltip } from "./hooks"; interface FormListOpts { children: ComponentChildren; @@ -90,13 +91,23 @@ interface FormListItemOpts { outsideChildren?: ComponentChildren; } +const TOOLTIP_CONFIG: Partial = { + placement: "right", + fallbackPlacements: [ "right" ] +} + export function FormListItem({ className, children, icon, value, title, active, badges, disabled, checked, onClick, description, selected, rtl, triggerCommand, outsideChildren }: FormListItemOpts) { + const itemRef = useRef(null); + if (checked) { icon = "bx bx-check"; } + useStaticTooltip(itemRef, TOOLTIP_CONFIG); + return ( ; +} + +export function FormDropdownSubmenu({ icon, title, children }: { icon: string, title: ComponentChildren, children: ComponentChildren }) { + return ( +
  • + + + {title} + + +
      + {children} +
    +
  • + ) } \ No newline at end of file diff --git a/apps/client/src/widgets/react/hooks.tsx b/apps/client/src/widgets/react/hooks.tsx index bd0c2e287..58670155a 100644 --- a/apps/client/src/widgets/react/hooks.tsx +++ b/apps/client/src/widgets/react/hooks.tsx @@ -505,7 +505,8 @@ export function useTooltip(elRef: RefObject, config: Partial, config?: Partial) { useEffect(() => { - if (!elRef?.current) return; + const hasTooltip = config?.title || elRef.current?.getAttribute("title"); + if (!elRef?.current || !hasTooltip) return; const $el = $(elRef.current); $el.tooltip(config);