Skip to content

Conversation

@ze-flo
Copy link
Contributor

@ze-flo ze-flo commented Oct 16, 2025

Description

This PR adds a keepMounted prop to the TooltipDialog component, allowing the dialog content to remain in the DOM when closed instead of being unmounted. This is useful for preserving component state and improving re-opening performance.

Details

  • New keepMounted prop lets you control mounting behavior
  • When true, the dialog stays in the DOM but gets hidden with CSS and proper ARIA attributes
  • Focus management works correctly when reopening a kept-mounted dialog
  • Exit animations complete fully before the dialog is hidden
  • Fully tested with new specs covering visibility states and focus behavior
  • Available in Storybook for experimentation

Checklist

  • 👌 design updates will be Garden Designer approved (add the designer as a reviewer)
  • 🌐 demo is up-to-date (npm start)
  • ⬅️ renders as expected with reversed (RTL) direction
  • ⚫ renders as expected in dark mode
  • 🤘 renders as expected with Bedrock CSS (?bedrock)
  • 💂‍♂️ includes new unit tests. Maintain existing coverage (always >= 96%)
  • ♿ tested for WCAG 2.1 AA accessibility compliance
  • 📝 tested in Chrome, Firefox, Safari, and Edge

Copy link

@bmson bmson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, that's a clean way to do it

offset: _offset,
onClose,
hasArrow = true,
keepMounted = false,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
keepMounted = false,
keepMounted,

Please follow the Garden convention of defaulting boolean props undefined

Comment on lines 178 to 183
style={{
...backdropProps?.style,
...(isHidden
? { visibility: 'hidden', pointerEvents: 'none' }
: { visibility: undefined })
}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can these be applied to the StyledTooltipDialogBackdrop CSS rather than inlining the styles?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I'm a bit concerned about leaving the backdrop in place as it there might be some unanticipated stacking issues. If the content is meant to remain accessibly aria-hidden to screen readers, I'd recommend polished JS hideVisually(). Otherwise, it might be good to apply display: contents;.

focusOnMount: true,
hasArrow: true,
restoreFocus: true,
keepMounted: false,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
keepMounted: false,

Prefer Storybook's implicit prop definition whenever possible

argTypes={{
referenceElement: { control: false },
fallbackPlacements: { control: 'multi-select', options: PLACEMENT.filter(p => p !== 'auto') },
keepMounted: { control: 'boolean' },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
keepMounted: { control: 'boolean' },

ditto .. should not be needed

opacity: 0;
}
${props => props.$isHidden && hideVisually()}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
${props => props.$isHidden && hideVisually()}
${props => props['aria-hidden'] && hideVisually()}

Can we use the ARIA attribute rather than adding a custom prop? This follows the more prominent styling from Garden's more mature components (dropdowns, for example)

{...(getBackdropProps() as HTMLAttributes<HTMLDivElement>)}
{...backdropProps}
ref={transitionRef}
style={backdropProps?.style}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
style={backdropProps?.style}

This shouldn't be needed as it is already spread above.

@ze-flo ze-flo merged commit f6853f4 into main Oct 20, 2025
8 checks passed
@ze-flo ze-flo deleted the ze-flo/tooltip-dialog-keep-mounted branch October 20, 2025 18:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

3 participants