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

[WNMGDS-2893] Implement Tooltip web component #3249

Open
wants to merge 25 commits into
base: main
Choose a base branch
from

Conversation

jack-ryan-nava-pbc
Copy link
Collaborator

Summary

  • Initial implementation of the ds-tooltip web component
  • Stories are written, and seek to emulate the existing React-based component
  • Tests are written, and seek to emulate the existing React-based component
  • There are a few notable differences between the web component and the React component:
    • No onOpen or onClose custom events - I figured these could be manually attached rather than being inbuilt, especially since these are used somewhat infrequently and for analytics when they are used.
    • No aria-label - see Slack Thread for context.

How to test

  1. Pull down branch
  2. Confirm tests pass locally
  3. Confirm controls in stories all change the component in expected ways.
  4. Confirm that the usability of the component matches the expectations from the React component.

Checklist

  • Prefixed the PR title with the Jira ticket number as [WNMGDS-####] Title or [NO-TICKET] if this is unticketed work.
  • Selected appropriate Type (only one) label for this PR, if it is a breaking change, label should only be Type: Breaking
  • Selected appropriate Impacts, multiple can be selected.
  • Selected appropriate release milestone

@jack-ryan-nava-pbc jack-ryan-nava-pbc added Status: Work In Progress PR's that are not yet ready for review Impacts: Core Impacts the core DS primarily, changes may occur in other themes as well. Type: Added Indicates a new feature. labels Sep 27, 2024
@jack-ryan-nava-pbc jack-ryan-nava-pbc added this to the 12.0.0-beta.0 milestone Sep 27, 2024
@jack-ryan-nava-pbc jack-ryan-nava-pbc self-assigned this Sep 27, 2024
return Tooltip.defaultProps.offset as TooltipProps['offset'];
};

const isPlacementValue = (location: string): location is Placement => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The goal with this function is to enforce some guardrails on the user input for the placement value attribute. This could be overwrought, and I can probably just remove it and replace the type definition in the WrapperProps as string | TooltipProps['placement'].

title: string | TooltipProps['title'];
}

const parseOffset = (offset: string): TooltipProps['offset'] => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Trying to support an array as a string is maybe a bit wrongheaded. Curious if people think this is likely unnecessary. I have seen this prop used rarely in the wild in the React components as well. So maybe this just gets cut out.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, I'd argue that this one isn't necessary right now

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sounds good! To the chopping block it goes.

it('closes tooltip when trigger focus is lost', async () => {
jest.useFakeTimers();
const { container } = renderTooltip();
const tooltip = container.querySelector('.ds-c-tooltip');
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I doubt this class name is going to change anytime soon which is why I didn't go through the trouble of assigning a testID for this query.

renderTooltip(propsWithSlots);
const tooltipTrigger = screen.getByText(customTooltipText);
expect(tooltipTrigger).toHaveTextContent(customTooltipText);
expect(tooltipTrigger).toHaveTextContent(customHeadingText);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Since we set both the title and the contentheading slot values, we expect both sections of text to be contained within the tooltip.

@@ -1,2 +1,4 @@
export * from './Tooltip';
export * from './TooltipIcon';
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We export everything mostly to get access to the type definitions. I can tighten this export statement to just reveal the types if folks think that is a better idea?

}: WrapperProps) => (
<Tooltip
{...otherProps}
ariaLabel={otherProps.triggerAriaLabel}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

OK, so I think the way this is setup actually handles all the cases we might be worried about re duplicative aria labelling.

  1. You can have both aria-label and trigger-aria-label exist on the component. The trigger-aria-label attribute will still apply to the child trigger element, and the aria-label value will apply only to the parent.
  2. If you apply an aria-label and no trigger-aria-label attribute, the new aria-label attribute only exists on the parent web component container. It is not applied to the child trigger element.

As the code currently is, I think these are sufficiently distinct. Please let me know if you have any concerns @kim-cmsds @tamara-corbalt @pwolfert

@jack-ryan-nava-pbc jack-ryan-nava-pbc marked this pull request as ready for review October 1, 2024 16:27
@jack-ryan-nava-pbc jack-ryan-nava-pbc removed the Status: Work In Progress PR's that are not yet ready for review label Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Impacts: Core Impacts the core DS primarily, changes may occur in other themes as well. Type: Added Indicates a new feature.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants