Skip to content

Conversation

@myrta2302
Copy link
Contributor

@myrta2302 myrta2302 commented Aug 29, 2025

📄 Description

This PR adds documentation for the following cross-component referencing scenarios under the (private) Accessibility section:

  1. for / label
  2. aria-labelledby
  3. aria-describedby
  4. role="list"

To support these examples, a new demo-components folder has been added under documentation/src, containing the following native web components:

  • demo-button
  • demo-label
  • demo-list-item-group
  • demo-list-item
  • demo-list
  • demo-span
  • demo-target

📝 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 Aug 29, 2025

⚠️ No Changeset found

Latest commit: ca323a5

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@swisspost-bot
Copy link
Contributor

swisspost-bot commented Aug 29, 2025

Related Previews

@myrta2302 myrta2302 changed the title feat(documentation): add accessibility 'for-label' story and demo target component feat(documentation): add accessibility reference relationship stories and demo components Sep 9, 2025
@myrta2302 myrta2302 marked this pull request as ready for review September 9, 2025 09:29
@myrta2302 myrta2302 requested review from a team as code owners September 9, 2025 09:29
@myrta2302 myrta2302 linked an issue Sep 12, 2025 that may be closed by this pull request
3 tasks
@sonarqubecloud
Copy link

Copy link
Contributor

@oliverschuerch oliverschuerch left a comment

Choose a reason for hiding this comment

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

The preview URL is not working.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Nov 5, 2025

@myrta2302
Copy link
Contributor Author

The preview URL is not working.

I merged the conflicts to main and it is working now.

Copy link
Contributor

@oliverschuerch oliverschuerch left a comment

Choose a reason for hiding this comment

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

Currently, the guidelines are always visible, no matther which mode the docs are rendered in (development | production).
Shouldn't we hide the guidelines in production mode, or is the content also relevant for our users?


The docs pages aria-describedby and aria-labelledby are almost the same (compared by page structur and content).
Please update the CRs requested for one also on the other.


During the review, I asked my self if the examples are just to specific? At least it's a lot of repeating information on all of the example pages.

I think it could be beneficial to add a page with general information about, how different HTML attributes or JS properties can cross the DOM borders or not. And then additionally only document exceptions.

e.g.

  • light -> light ✔️
  • light -> shadow ❌
  • shadow -> light ❌
  • shadow -> slotted ❌
  • shadow A -> shadow A ✔️
  • shadow B -> shadow B ❌
  • ...

if we'd do that and add examples, most of the content of the other pages could become obsolete.

Since you've already put a lot of effort into it, I'll leave it up to you if you want to do that, ask the team about it or completely ignore this idea.

}
}

const ariaPropertyName = isLabelled ? 'ariaLabelledByElements' : 'ariaDescribedByElements';
Copy link
Contributor

Choose a reason for hiding this comment

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

It's a so called "good practice" to define variables at the beginning of a function. Please move this to line 32.

Comment on lines +21 to +27
attributeChangedCallback(name: string, _oldValue: string, newValue: string) {
if (name === 'workaround') this.workaround = newValue;
if (name === 'arialabelledby-id') this.arialabelledbyId = newValue;
if (name === 'ariadescribedby-id') this.ariadescribedbyId = newValue;
if (name === 'button-version') this.buttonVersion = newValue as '1' | '2' | '3';
this.render();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Since only the observed attributes will execute this callback, you could easily make it generic.

attributeChangedCallback(name: string, _oldValue: string, newValue: string) {
  const member = name.replace(/-./g, m => m[1].toUpperCase());
  
  this[member] = newValue;
  this.render();
}

Copy link
Contributor

Choose a reason for hiding this comment

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

To be inline with the given file naming, I suggest to rename all the sample files:

  1. Write names in kebab-case
  2. Add context for the html samples and only use numbers/letters if there is no better word to describe the context
    (e.g. default-example-lightdom.sample.html and default-example-shadowdom.sample.html or not-working-example-1.sample.html and not-working-example-2.sample.html).

Comment on lines +45 to +50
<p>
Below is a working example of an `aria-describedby`/`id` relationship within the shadowDom of a
custom button component. You can <b>test it with NVDA</b> to confirm the correct description
announcement.
</p>
<Canvas of={CCR.ExampleHTML} sourceState="hide" />
Copy link
Contributor

Choose a reason for hiding this comment

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

The text says it's a working shadowdom example, but the story contains a lightdom example.

import WorkingExampleIV from './examples/workingExample-IV.sample.html?raw';

<Meta of={CCR} />

Copy link
Contributor

Choose a reason for hiding this comment

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

I would add something like the following as a general statement:

Note: The aria-describedby attribute is not designed to reference descriptions from external resources. As its value is one or more ids (space-separated if multiple), it must reference elements in the same DOM document.

Source: https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Reference/Attributes/aria-describedby#example

If you find a better description about this fact, that be even better.

<!--The aria-labelledby attribute is set automatically by the browser -->
<div ref="targetRef" role="button" tabindex="0" aria-labelledby>

<!-- slotted label element -->
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
<!-- slotted label element -->

Copy link
Contributor

Choose a reason for hiding this comment

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

Keep file naming consistant.


<custom-button>
⏷ #shadow-root (open)
<input ref="targetRef" id="inputId" aria-labelledby />
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
<input ref="targetRef" id="inputId" aria-labelledby />
<input ref="targetRef" id="inputId" aria-labelledby />

</b>
</p>

#### Workaround: `Element:ariaLabelledByElements`
Copy link
Contributor

Choose a reason for hiding this comment

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

This complete section reminds me almost 100% of the aria-labelledby page.
Do we need to keep both or would it be enough to say here, that you can use the ariaLabelledByElements workaround on the other page?

Copy link
Contributor

Choose a reason for hiding this comment

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

Check the links. some of them did not work.

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.

Investigate and Document Cross-Component DOM Referencing

4 participants