Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature : defaultIsOpen is added #1154

Merged
merged 2 commits into from
Jan 21, 2024
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
1 change: 1 addition & 0 deletions docs/docs/options.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
4 changes: 4 additions & 0 deletions src/components/Tooltip/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const Tooltip = ({
content,
contentWrapperRef,
isOpen,
defaultIsOpen = false,
setIsOpen,
activeAnchor,
setActiveAnchor,
Expand Down Expand Up @@ -764,6 +765,9 @@ const Tooltip = ({
}, [anchorId, anchorsBySelect, activeAnchor])

useEffect(() => {
if (defaultIsOpen) {
handleShow(true)
}
return () => {
if (tooltipShowDelayTimerRef.current) {
clearTimeout(tooltipShowDelayTimerRef.current)
Expand Down
1 change: 1 addition & 0 deletions src/components/Tooltip/TooltipTypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ export interface ITooltip {
style?: CSSProperties
position?: IPosition
isOpen?: boolean
defaultIsOpen?: boolean
setIsOpen?: (value: boolean) => void
afterShow?: () => void
afterHide?: () => void
Expand Down
2 changes: 2 additions & 0 deletions src/components/TooltipController/TooltipController.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const TooltipController = React.forwardRef<TooltipRefProps, ITooltipController>(
style,
position,
isOpen,
defaultIsOpen = false,
disableStyleInjection = false,
border,
opacity,
Expand Down Expand Up @@ -354,6 +355,7 @@ const TooltipController = React.forwardRef<TooltipRefProps, ITooltipController>(
style,
position,
isOpen,
defaultIsOpen,
border,
opacity,
arrowColor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading