From 3b2f38aa066a0431bd7b9d369d879823757e58c1 Mon Sep 17 00:00:00 2001 From: jpranays Date: Sat, 20 Jan 2024 15:17:45 +0530 Subject: [PATCH 1/2] Feature : defaultIsOpen is added --- src/components/Tooltip/Tooltip.tsx | 4 ++++ src/components/Tooltip/TooltipTypes.d.ts | 1 + src/components/TooltipController/TooltipController.tsx | 2 ++ src/components/TooltipController/TooltipControllerTypes.d.ts | 1 + 4 files changed, 8 insertions(+) diff --git a/src/components/Tooltip/Tooltip.tsx b/src/components/Tooltip/Tooltip.tsx index 280da9f8..fa5f917c 100644 --- a/src/components/Tooltip/Tooltip.tsx +++ b/src/components/Tooltip/Tooltip.tsx @@ -56,6 +56,7 @@ const Tooltip = ({ content, contentWrapperRef, isOpen, + defaultIsOpen = false, setIsOpen, activeAnchor, setActiveAnchor, @@ -764,6 +765,9 @@ const Tooltip = ({ }, [anchorId, anchorsBySelect, activeAnchor]) useEffect(() => { + if (defaultIsOpen) { + handleShow(true) + } return () => { if (tooltipShowDelayTimerRef.current) { clearTimeout(tooltipShowDelayTimerRef.current) diff --git a/src/components/Tooltip/TooltipTypes.d.ts b/src/components/Tooltip/TooltipTypes.d.ts index 0fb2879f..cf8802f1 100644 --- a/src/components/Tooltip/TooltipTypes.d.ts +++ b/src/components/Tooltip/TooltipTypes.d.ts @@ -146,6 +146,7 @@ export interface ITooltip { style?: CSSProperties position?: IPosition isOpen?: boolean + defaultIsOpen?: boolean setIsOpen?: (value: boolean) => void afterShow?: () => void afterHide?: () => void diff --git a/src/components/TooltipController/TooltipController.tsx b/src/components/TooltipController/TooltipController.tsx index 12448464..17463631 100644 --- a/src/components/TooltipController/TooltipController.tsx +++ b/src/components/TooltipController/TooltipController.tsx @@ -53,6 +53,7 @@ const TooltipController = React.forwardRef( style, position, isOpen, + defaultIsOpen = false, disableStyleInjection = false, border, opacity, @@ -354,6 +355,7 @@ const TooltipController = React.forwardRef( style, position, isOpen, + defaultIsOpen, border, opacity, arrowColor, diff --git a/src/components/TooltipController/TooltipControllerTypes.d.ts b/src/components/TooltipController/TooltipControllerTypes.d.ts index 8211aa80..a6a5e289 100644 --- a/src/components/TooltipController/TooltipControllerTypes.d.ts +++ b/src/components/TooltipController/TooltipControllerTypes.d.ts @@ -80,6 +80,7 @@ export interface ITooltipController { style?: CSSProperties position?: IPosition isOpen?: boolean + defaultIsOpen?: boolean disableStyleInjection?: boolean | 'core' /** * @description see https://developer.mozilla.org/en-US/docs/Web/CSS/border. From 74215185ed0040355b67dbee65ef23628fd37a89 Mon Sep 17 00:00:00 2001 From: jpranays Date: Sat, 20 Jan 2024 19:45:53 +0530 Subject: [PATCH 2/2] Updated docs/options --- docs/docs/options.mdx | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/docs/options.mdx b/docs/docs/options.mdx index 22b281d6..01083381 100644 --- a/docs/docs/options.mdx +++ b/docs/docs/options.mdx @@ -123,6 +123,7 @@ import { Tooltip } from 'react-tooltip'; | `style` | `CSSProperties` | no | | a CSS style object | Add inline styles directly to the tooltip | | `position` | `{ x: number; y: number }` | no | | any `number` value for both `x` and `y` | Override the tooltip position on the DOM | | `isOpen` | `boolean` | no | | `true` `false` | The tooltip can be controlled or uncontrolled, this attribute can be used to handle show and hide tooltip outside tooltip (can be used **without** `setIsOpen`) | +| `defaultIsOpen` | `boolean` | no | `false` | `true` `false` | It determines the initial visibility of the tooltip. If true, the tooltip is shown by default, if false or not provided then it's in hidden state by default. | | `setIsOpen` | `function` | no | | | The tooltip can be controlled or uncontrolled, this attribute can be used to handle show and hide tooltip outside tooltip | | `afterShow` | `function` | no | | | A function to be called after the tooltip is shown | | `afterHide` | `function` | no | | | A function to be called after the tooltip is hidden |