Skip to content
This repository has been archived by the owner on Jan 20, 2022. It is now read-only.

Update tooltips to support controlled visibility #379

Merged
merged 1 commit into from
Sep 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/AbstractTooltip/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ export interface AbstractTooltipProps {
matchTriggerWidth?: boolean;
}

type Props = TippyProps & AbstractTooltipProps;
type Props = TippyProps &
AbstractTooltipProps &
({ visible?: undefined } | { visible: boolean; trigger?: undefined });

export const AbstractTooltip: React.FC<Props> = ({
animation = "shift-away",
Expand All @@ -51,6 +53,7 @@ export const AbstractTooltip: React.FC<Props> = ({
hideOnClick,
matchTriggerWidth = false,
popperOptions = {},
visible,
...props
}) => {
const {
Expand All @@ -67,7 +70,7 @@ export const AbstractTooltip: React.FC<Props> = ({
arrow={false}
hideOnClick={forceVisibleForTestingOnly ? false : hideOnClick}
trigger={forceVisibleForTestingOnly ? "manual" : trigger}
visible={forceVisibleForTestingOnly ? true : undefined}
visible={forceVisibleForTestingOnly ? true : visible}
theme="space-kit"
popperOptions={{
...popperOptions,
Expand Down
7 changes: 5 additions & 2 deletions src/Tooltip/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type Props = Pick<
| "disabled"
| "interactive"
| "placement"
| "visible"
> &
AbstractTooltipProps;

Expand All @@ -21,13 +22,15 @@ type Props = Pick<
* delay when hovering on an element. We also wait for the user's cursor to rest
* on the element; meaning we won't show a Tooltip while the cursor is moving
*/
export const Tooltip: React.FC<Props> = ({ children, ...props }) => {
export const Tooltip: React.FC<Props> = ({ children, visible, ...props }) => {
return (
<TooltipContextProvider descendsFromTooltip>
<AbstractTooltip
delay={150}
trigger="mouseenter"
plugins={[mouseRest]}
{...(typeof visible === "boolean"
? { visible }
: { trigger: "mouseenter" })}
{...props}
>
{children}
Expand Down