Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(ui): open disabled reason tooltips on click (#89888)

Eleftheria Trivyzakie3540bb9fa12
diff --git a/frontend/src/lib/components/Account/ProjectCombobox.tsx b/frontend/src/lib/components/Account/ProjectCombobox.tsx
index 45960b75b175..bb3ffa9abec3 100644
--- a/frontend/src/lib/components/Account/ProjectCombobox.tsx
+++ b/frontend/src/lib/components/Account/ProjectCombobox.tsx
@@ -191,7 +191,9 @@ export function ProjectCombobox(): JSX.Element | null {
tooltip="Create a new project"
tooltipPlacement="right"
className="shrink-0"
- disabled={!!projectCreationForbiddenReason}
+ disabledReasons={
+ projectCreationForbiddenReason ? { [projectCreationForbiddenReason]: true } : undefined
+ }
>
<IconPlusSmall className="text-tertiary" />
New project
diff --git a/frontend/src/lib/lemon-ui/LemonButton/LemonButton.tsx b/frontend/src/lib/lemon-ui/LemonButton/LemonButton.tsx
index dd9d30a80c2c..f80dc212edbd 100644
--- a/frontend/src/lib/lemon-ui/LemonButton/LemonButton.tsx
+++ b/frontend/src/lib/lemon-ui/LemonButton/LemonButton.tsx
@@ -301,6 +301,8 @@ export const LemonButton: React.FunctionComponent<LemonButtonProps & React.RefAt
arrowOffset={tooltipArrowOffset}
docLink={tooltipDocLink}
visible={tooltipForceMount}
+ // A click on a blocked button must surface the reason, since hover is unavailable on touch
+ openOnClick={!!disabledReason}
interactive={disabledReasonInteractive}
closeDelayMs={disabledReasonInteractive ? INTERACTIVE_CLOSE_DELAY_MS : undefined}
>
diff --git a/frontend/src/lib/ui/Button/ButtonPrimitives.tsx b/frontend/src/lib/ui/Button/ButtonPrimitives.tsx
index 0967a648818b..d57284d26620 100644
--- a/frontend/src/lib/ui/Button/ButtonPrimitives.tsx
+++ b/frontend/src/lib/ui/Button/ButtonPrimitives.tsx
@@ -292,6 +292,11 @@ export const ButtonPrimitive = forwardRef<HTMLButtonElement, ButtonPrimitiveProp
const effectiveVariant = forceVariant ? variant : context?.variantContext || variant
let effectiveDisabled = disabledReasons ? Object.values(disabledReasons).some((value) => value) : disabled
const externalAriaDisabled = rest['aria-disabled']
+
+ // If there are disabled reasons which are true, render them, otherwise render the tooltip
+ const tooltipTitle = disabledReasons && effectiveDisabled ? renderDisabledReasons(disabledReasons) : tooltip
+ const hasTooltip = !!(tooltipTitle || tooltipDocLink)
+
let buttonComponent: JSX.Element = React.createElement(
'button',
{
@@ -309,7 +314,9 @@ export const ButtonPrimitive = forwardRef<HTMLButtonElement, ButtonPrimitiveProp
inert,
truncate,
className,
- })
+ }),
+ // A disabled button swallows pointer events, so let the tooltip wrapper span receive them
+ hasTooltip && effectiveDisabled && 'pointer-events-none'
),
ref,
disabled: effectiveDisabled,
@@ -323,13 +330,7 @@ export const ButtonPrimitive = forwardRef<HTMLButtonElement, ButtonPrimitiveProp
children
)
- // If there are disabled reasons which are true, render them, otherwise render the tooltip
- const tooltipTitle =
- disabledReasons && Object.values(disabledReasons).some(Boolean)
- ? renderDisabledReasons(disabledReasons)
- : tooltip
-
- if (tooltipTitle || tooltipDocLink) {
+ if (hasTooltip) {
const tooltipChild = effectiveDisabled ? (
<span className="inline-flex w-fit">{buttonComponent}</span>
) : (
@@ -344,6 +345,7 @@ export const ButtonPrimitive = forwardRef<HTMLButtonElement, ButtonPrimitiveProp
docLink={tooltipDocLink}
visible={tooltipVisible}
interactive={tooltipInteractive}
+ openOnClick={!!effectiveDisabled}
>
{tooltipChild}
</Tooltip>