Skip to content

Conversation

@myrta2302
Copy link
Contributor

@myrta2302 myrta2302 commented Nov 11, 2025

📄 Description

This PR updates the post-popover-trigger to enable the option of wrapping the post-popover inside it and omitting the id reference.

🔮 Design review

  • Design review done
  • No design review needed

📝 Checklist

  • ✅ My code follows the style guidelines of this project
  • 🛠️ I have performed a self-review of my own code
  • 📄 I have made corresponding changes to the documentation
  • ⚠️ My changes generate no new warnings or errors
  • ✔️ New and existing unit tests pass locally with my changes

@changeset-bot
Copy link

changeset-bot bot commented Nov 11, 2025

🦋 Changeset detected

Latest commit: 771663d

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 Patch
@swisspost/design-system-components-angular-workspace Patch
@swisspost/design-system-components-react Patch
@swisspost/design-system-documentation Patch
@swisspost/design-system-nextjs-integration Patch
@swisspost/design-system-components-angular Patch
@swisspost/design-system-changelog-github Patch
@swisspost/design-system-eslint Patch
@swisspost/design-system-icons Patch
@swisspost/internet-header Patch
@swisspost/design-system-styles Patch
@swisspost/design-system-styles-primeng-workspace Patch
@swisspost/design-system-styles-primeng Patch
@swisspost/design-system-tokens 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 Nov 11, 2025

Related Previews

@myrta2302 myrta2302 marked this pull request as ready for review November 13, 2025 07:36
@myrta2302 myrta2302 requested review from a team as code owners November 13, 2025 07:36
@myrta2302 myrta2302 requested a review from leagrdv November 13, 2025 07:36
Copy link
Contributor

@leagrdv leagrdv left a comment

Choose a reason for hiding this comment

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

Could this also be done for the tooltip? Maybe in another ticket

Copy link
Contributor

Choose a reason for hiding this comment

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

Since there is no "for", the aria-controls is set to undefined
Capture d'écran 2025-11-14 111606

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct! I ve updated that to either use the Elements API ariaControlsElements property, or fallback to a random ID generation.

@Watch('for')
validateFor() {
checkRequiredAndType(this, 'for', 'string');
checkEmptyOrType(this, '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.

Using a post-popovertrigger without a for or a wrapped post-popover shows no error (just a warning when clicking on the trigger). There should be a check that there is either one or the other and show an error if that's not the case.
Could you also add some tests for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok!

Copy link
Contributor

Choose a reason for hiding this comment

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

Just a hint...

When the scope of a test is very limited (e.g. we're testing one specific component), it is often easier, to keep the names of the aliases short, because you have to repeat them a lot afterwards.

Try to be consisting with the alias naming.

beforeEach(() => {
  cy.get('post-popover[data-hydrated][id="popover-one"]').as('popoverOne');
  cy.get('@popoverOne').find('p').as('contentOne');
  cy.get('post-popover-trigger[data-hydrated][for="popover-one"]').as('triggerOne');
  cy.get('@triggerOne').find('button').as('buttonOne');
});

// Set aria attributes
this.trigger.setAttribute('aria-haspopup', 'true');
this.trigger.setAttribute('aria-controls', this.for);
const popover = this.popover;
Copy link
Contributor

Choose a reason for hiding this comment

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

As a general rule, declare a const as early as possible in its scope!
And no worry, it has no effect to the memory usage even if you don't use it afterwards, as const popover is a simple reference to the same object (memory address) as this.popover (as long as this.popover does not return a primitive like null or a string).

This is considered good practice.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good to know, thanx!

Comment on lines 99 to 100
popover.id ||= `popover-${crypto.randomUUID()}`;
(this.trigger as HTMLElement).setAttribute('aria-controls', popover.id);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is the type assertion necessary here, but not on line 93?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It happens because of the else if ('ariaControlsElements' in this.trigger) check, ts sees it as never. I updated with a helper function.

@sonarqubecloud
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update popover trigger to allow to wrap the popover (to omit the id-reference)

5 participants