Skip to content

Commit

Permalink
feat(react-tooltip): do not show tooltip, if it's applied to menu tri…
Browse files Browse the repository at this point in the history
…gger and menu is opened (#33394)
  • Loading branch information
mainframev authored Dec 4, 2024
1 parent ae797cb commit 91a9222
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "feat: do not show tooltip, if it's menu trigger and Menu is opened",
"packageName": "@fluentui/react-tooltip",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,15 @@ export type TooltipChildProps = {
ref?: React.Ref<unknown>;
} & Pick<
React.HTMLAttributes<HTMLElement>,
'aria-describedby' | 'aria-label' | 'aria-labelledby' | 'onBlur' | 'onFocus' | 'onPointerEnter' | 'onPointerLeave'
| 'aria-describedby'
| 'aria-label'
| 'aria-labelledby'
| 'onBlur'
| 'onFocus'
| 'onPointerEnter'
| 'onPointerLeave'
| 'aria-haspopup'
| 'aria-expanded'
>;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ export const useTooltip_unstable = (props: TooltipProps): TooltipState => {
const child = getTriggerChild(children);

const triggerAriaProps: Pick<TooltipChildProps, 'aria-label' | 'aria-labelledby' | 'aria-describedby'> = {};
const isMenuTrigger = child?.props?.['aria-haspopup'] === 'menu' && child?.props?.['aria-expanded'];

if (relationship === 'label') {
// aria-label only works if the content is a string. Otherwise, need to use aria-labelledby.
Expand All @@ -254,8 +255,9 @@ export const useTooltip_unstable = (props: TooltipProps): TooltipState => {
state.shouldRenderTooltip = true;
}

// Don't render the Tooltip in SSR to avoid hydration errors
if (isServerSideRender) {
// Case 1: Don't render the Tooltip in SSR to avoid hydration errors
// Case 2: Don't render the Tooltip, if it triggers Menu and it's already opened
if (isServerSideRender || isMenuTrigger) {
state.shouldRenderTooltip = false;
}

Expand Down

0 comments on commit 91a9222

Please sign in to comment.