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

feat(tooltip)!: add post-tooltip-trigger #3196

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

Conversation

gfellerph
Copy link
Member

In order to get rid of mutation observers on attributes, a new element to wrap the trigger was added for the tooltip. This enables easier lifecycle management and more precise event listeners with less overhead.

In order to get rid of mutation observers on attributes, a new element to wrap the trigger was added for the tooltip. This enables easier lifecycle management and more precise event listeners with less overhead.
@gfellerph gfellerph requested a review from a team as a code owner June 28, 2024 14:32
Copy link

changeset-bot bot commented Jun 28, 2024

🦋 Changeset detected

Latest commit: 268fda3

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 14 packages
Name Type
@swisspost/design-system-components Major
@swisspost/design-system-components-angular-workspace Patch
@swisspost/design-system-components-react Major
@swisspost/design-system-documentation Patch
@swisspost/design-system-components-angular Major
@swisspost/design-system-nextjs-integration Patch
@swisspost/design-system-styles Major
@swisspost/design-system-intranet-header Major
@swisspost/design-system-icons Major
@swisspost/design-system-migrations Major
@swisspost/design-system-demo Patch
@swisspost/internet-header Patch
@swisspost/design-system-intranet-header-workspace Patch
@swisspost/design-system-intranet-header-showcase Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@swisspost-bot
Copy link
Contributor

swisspost-bot commented Jun 28, 2024

In order to hide the post-tooltip with display: none initially, an open attribute is reflected to the custom element. This enables to set display: block when the attribute is present, handling issues with screen readers.
@gfellerph gfellerph linked an issue Jul 2, 2024 that may be closed by this pull request
this.trigger.setAttribute('aria-describedby', newDescribedBy);
}

this.host.addEventListener('pointerover', this.localInterestHandler);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not adding the event listeners on the trigger instead of the host?

Copy link
Member Author

Choose a reason for hiding this comment

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

Just in case the trigger gets replaced or re-rendered by react/angular in which case the event bindings would be lost. If the trigger is re-rendered, the lifecycle hooks will trigger again.

Copy link
Contributor

Choose a reason for hiding this comment

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

True, in this case the ARIA attributes will not be set properly. We might need a Mutation observer in the end...

@alizedebray alizedebray added the 🚂 PR train PR which follows another one. label Jul 2, 2024
Copy link

sonarcloud bot commented Jul 10, 2024

/**
* Link the trigger to a tooltip with this id
*/
@Prop() for: string;
Copy link
Contributor

Choose a reason for hiding this comment

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

Validation is missing, checkNonEmpty at least.


// Add tooltip to aria-describedby
const describedBy = this.trigger.getAttribute('aria-describedby');
if (!describedBy?.includes(this.for)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be good to move this logic to the "for" watcher in case it changes after the component load.

this.trigger.setAttribute('aria-describedby', newDescribedBy);
}

this.host.addEventListener('pointerover', this.localInterestHandler);
Copy link
Contributor

Choose a reason for hiding this comment

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

True, in this case the ARIA attributes will not be set properly. We might need a Mutation observer in the end...

@@ -181,7 +62,7 @@ export class PostTooltip {

/**
* Toggle tooltip display
* @param target An element with [data-tooltip-target="id"] where the tooltip should be shown
* @param target An element where the tooltip should be shown
* @param force Pass true to always show or false to always hide
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* @param force Pass true to always show or false to always hide
* @param [force] Pass true to always show or false to always hide

/**
* Indicates the open state of the tooltip
*/
@Prop({ reflect: true, mutable: true }) open = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

Props validation is missing, they should also be added to the changeset.

Copy link
Contributor

Choose a reason for hiding this comment

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

These changes can probably be reverted.

/**
* Animation style
*/
@Prop() readonly animation?: 'pop-in' = null;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
@Prop() readonly animation?: 'pop-in' = null;
@Prop() readonly animation?: 'pop-in';

OR

Suggested change
@Prop() readonly animation?: 'pop-in' = null;
@Prop() readonly animation: 'pop-in' | null = null;

@@ -62,11 +62,17 @@ const meta: MetaComponent = {
placement: {
name: 'Placement',
},
arrow: {
name: 'Arrow',
animation: {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did you override the animation arg?
It would be better to use the definition derived from the JSDoc of the component.

@oliverschuerch oliverschuerch removed their request for review July 12, 2024 11:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🚂 PR train PR which follows another one.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tooltips sometimes not showing
3 participants