File tree Expand file tree Collapse file tree 3 files changed +26
-1
lines changed Expand file tree Collapse file tree 3 files changed +26
-1
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ ' @primer/react ' : minor
3+ ---
4+
5+ IconButton: Hide tooltip when popup is open via new ` closeTooltip ` prop in ` Tooltip ` .
Original file line number Diff line number Diff line change @@ -28,7 +28,14 @@ const IconButton = forwardRef(
2828 const { tooltipId} = React . useContext ( TooltipContext ) // Tooltip v2
2929 const { tooltipId : tooltipIdV1 } = React . useContext ( TooltipContextV1 ) // Tooltip v1
3030
31+ const { 'aria-expanded' : isExpanded , 'aria-haspopup' : hasPopup } = props
32+
3133 const hasExternalTooltip = tooltipId || tooltipIdV1
34+
35+ // If the button has an active "popup" (like a menu), we don't want to show the tooltip.
36+ // This is mostly for `ActionMenu`, but could be applicable elsewhere.
37+ const hasActivePopup = ( isExpanded === true || isExpanded === 'true' ) && hasPopup === 'true'
38+
3239 const withoutTooltip =
3340 unsafeDisableTooltip || disabled || ariaLabel === undefined || ariaLabel === '' || hasExternalTooltip
3441
@@ -55,6 +62,7 @@ const IconButton = forwardRef(
5562 type = { description ? undefined : 'label' }
5663 direction = { tooltipDirection }
5764 keybindingHint = { keybindingHint ?? keyshortcuts }
65+ _privateDisableTooltip = { hasActivePopup }
5866 >
5967 < ButtonBase
6068 icon = { Icon }
Original file line number Diff line number Diff line change @@ -25,6 +25,16 @@ export type TooltipProps = React.PropsWithChildren<{
2525 * long (1200ms)
2626 */
2727 delay ?: 'short' | 'medium' | 'long'
28+ /**
29+ * Private API for use internally only. Prevents the tooltip from opening if `true`.
30+ *
31+ * Accessibility note: This prop should be used with caution. Only use when needing to
32+ * programmatically close the tooltip in response to a specific user action, such as
33+ * opening a menu, or content where the tooltip could overlap with interactive content.
34+ *
35+ * @default false
36+ */
37+ _privateDisableTooltip ?: boolean
2838} > &
2939 React . HTMLAttributes < HTMLElement >
3040
@@ -107,6 +117,7 @@ export const Tooltip: ForwardRefExoticComponent<
107117 className,
108118 keybindingHint,
109119 delay = 'short' ,
120+ _privateDisableTooltip = false ,
110121 ...rest
111122 } : TooltipProps ,
112123 forwardedRef ,
@@ -130,7 +141,8 @@ export const Tooltip: ForwardRefExoticComponent<
130141 tooltipElRef . current &&
131142 triggerRef . current &&
132143 tooltipElRef . current . hasAttribute ( 'popover' ) &&
133- ! tooltipElRef . current . matches ( ':popover-open' )
144+ ! tooltipElRef . current . matches ( ':popover-open' ) &&
145+ ! _privateDisableTooltip
134146 ) {
135147 const tooltip = tooltipElRef . current
136148 const trigger = triggerRef . current
You can’t perform that action at this time.
0 commit comments