Skip to content

Commit

Permalink
Tooltipv2: Check if tooltip has popover attribute before opening or…
Browse files Browse the repository at this point in the history
… closing the popover (#4463)

* check if tooltip has popover attribute for open and close functions

* Create dirty-pots-rule.md
  • Loading branch information
broccolinisoup committed Apr 8, 2024
1 parent 3b72120 commit 4b00129
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/dirty-pots-rule.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/react": patch
---

TooltipV2: Check if tooltip element has `popover` attribute before calling `showPopover` and `hidePopover`
14 changes: 12 additions & 2 deletions packages/react/src/TooltipV2/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,12 @@ export const Tooltip = React.forwardRef(
const [calculatedDirection, setCalculatedDirection] = useState<TooltipDirection>(direction)

const openTooltip = () => {
if (tooltipElRef.current && triggerRef.current && !tooltipElRef.current.matches(':popover-open')) {
if (
tooltipElRef.current &&
triggerRef.current &&
tooltipElRef.current.hasAttribute('popover') &&
!tooltipElRef.current.matches(':popover-open')
) {
const tooltip = tooltipElRef.current
const trigger = triggerRef.current
tooltip.showPopover()
Expand All @@ -216,7 +221,12 @@ export const Tooltip = React.forwardRef(
}
}
const closeTooltip = () => {
if (tooltipElRef.current && triggerRef.current && tooltipElRef.current.matches(':popover-open')) {
if (
tooltipElRef.current &&
triggerRef.current &&
tooltipElRef.current.hasAttribute('popover') &&
tooltipElRef.current.matches(':popover-open')
) {
tooltipElRef.current.hidePopover()
}
}
Expand Down

0 comments on commit 4b00129

Please sign in to comment.