Skip to content

Commit

Permalink
feat(ui): add disable prop to Tooltip (#539)
Browse files Browse the repository at this point in the history
  • Loading branch information
matochu authored Mar 6, 2024
1 parent f73ed61 commit cf4b678
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
12 changes: 12 additions & 0 deletions packages/ui/__stories__/Tooltip.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,18 @@ Invisible.args = {
id: 'tooltip-story-invisible',
}

export const Visible = Template.bind({})
Visible.args = {
visible: true,
id: 'tooltip-story-visible',
}

export const Disabled = Template.bind({})
Disabled.args = {
disabled: true,
id: 'tooltip-story-disabled',
}

export const WithTooltip: Story<TooltipProps> = () => (
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', height: 320 }}>
<Tooltip
Expand Down
4 changes: 3 additions & 1 deletion packages/ui/src/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export type TooltipProps = {
updateToken?: ReactText | boolean
tooltipContainer?: PortalContainer
wordBreak?: CSSProperties['wordBreak']
disabled?: boolean
}

/**
Expand Down Expand Up @@ -86,6 +87,7 @@ export const Tooltip: FC<TooltipProps> = ({
updateToken,
tooltipContainer = 'body',
hoverAbleTooltip = true,
disabled = false,
}) => {
const [isShown, setShown] = useState<boolean>(false)
const timeoutRef = useRef<NodeJS.Timeout | null>(null)
Expand Down Expand Up @@ -167,7 +169,7 @@ export const Tooltip: FC<TooltipProps> = ({
)

// Makes sure "visible" prop can override local "isShown" state
const isTooltipVisible = visibilityOverride ?? isShown
const isTooltipVisible = !disabled && (visibilityOverride || isShown)

// Update the tooltip's position (useful when resizing table columns)
useLayoutEffect(() => {
Expand Down

0 comments on commit cf4b678

Please sign in to comment.