Skip to content

Commit

Permalink
fix: use slot for heading, implement a11y workaround for role=status
Browse files Browse the repository at this point in the history
  • Loading branch information
felixw committed Oct 23, 2023
1 parent a848629 commit ee7bf06
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,11 @@
padding-left: var(--spacing-y);
}

[part='heading'] {
[part='heading'],
[part='heading'] ::slotted(*) {
font: var(--telekom-text-style-heading-6);
line-height: var(--telekom-typography-line-spacing-tight);
margin: 0;
}

[part='text'] {
Expand Down
17 changes: 16 additions & 1 deletion packages/components/src/components/notification/notification.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ export class Notification {
if (newValue === true) {
this.open();
this.lastCloseEventTrigger = 'ATTRIBUTE';


} else if (this.isOpen) {
this.close();
}
Expand All @@ -131,6 +133,15 @@ export class Notification {
setTimeout(this.timeout, this.delay);
}
});
// workaround: when role is status, the inner text needs to be changed in order to be announced by the screen reader correctly
if (this.innerRole === "status") {
const text = this.hostElement.querySelector('[slot="text"]').innerHTML;
const heading = this.hostElement.querySelector('[slot="heading"]').innerHTML;
setTimeout( () => {
this.hostElement.querySelector('[slot="text"]').innerHTML = text;
this.hostElement.querySelector('[slot="heading"]').innerHTML = heading;
}, 10)
}
};

close = () => {
Expand Down Expand Up @@ -177,14 +188,18 @@ export class Notification {
<IconTag size={ICON_SIZE} selected={this.type === 'toast'} />
</slot>
</div>
<div part="body">
<div part="body"
role={this.innerRole}
aria-live="polite"
>
<div
part="heading"
role="heading"
aria-level={this.headingLevel}
aria-label={`${this.ariaHeading} ${this.heading}`}
>
<span>{this.heading}</span>
<slot name="heading"></slot>
</div>
{this.hasTextSlot && (
<div part="text">
Expand Down

0 comments on commit ee7bf06

Please sign in to comment.