Skip to content

Commit

Permalink
fix(sbb-notification): fix accessibility (#2325)
Browse files Browse the repository at this point in the history
Co-authored-by: Davide Mininni <davide.mininni@finconsgroup.com>
  • Loading branch information
dauriamarco and DavideMininni-Fincons committed Feb 8, 2024
1 parent b94d92d commit 00e9540
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
6 changes: 0 additions & 6 deletions src/components/notification/notification.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
@include sbb.host-component-properties;

:host {
--sbb-notification-visibility: hidden;
--sbb-notification-opacity: 0;
--sbb-notification-max-height: 0;
--sbb-notification-margin: 0;
Expand All @@ -31,7 +30,6 @@
var(--sbb-notification-timing-function),
border var(--sbb-notification-animation-duration) var(--sbb-animation-duration-2x)
var(--sbb-notification-timing-function),
visibility var(--sbb-notification-animation-duration) var(--sbb-notification-timing-function),
opacity var(--sbb-notification-animation-duration) var(--sbb-notification-timing-function);

// As the notification has always a light background, we have to fix the focus outline color
Expand All @@ -40,7 +38,6 @@
}

:host(:is([data-state='opened'], [data-state='opening'])) {
--sbb-notification-visibility: visible;
--sbb-notification-opacity: 1;
--sbb-notification-max-height: calc(
var(--sbb-notification-height) + (var(--sbb-notification-border-width) * 2)
Expand Down Expand Up @@ -93,7 +90,6 @@
width: calc(
100% - calc(var(--sbb-notification-base-radius) - var(--sbb-notification-border-width))
);
visibility: var(--sbb-notification-visibility);
opacity: var(--sbb-notification-opacity);
max-height: var(--sbb-notification-max-height);
transition: var(--sbb-notification-transition);
Expand Down Expand Up @@ -208,15 +204,13 @@

@keyframes open {
from {
visibility: hidden;
opacity: 0;
max-height: 0;
border-block: none;
margin: 0;
}

to {
visibility: visible;
opacity: 1;
max-height: var(--sbb-notification-max-height);
border-block: var(--sbb-notification-border);
Expand Down
6 changes: 5 additions & 1 deletion src/components/notification/notification.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,11 @@ const meta: Meta = {
style="padding: 2rem;display: flex;gap: var(--sbb-spacing-fixed-4x);flex-direction: column;"
>
${trigger(context.args)}
<div class="notification-container" style="display: flex; flex-direction: column;">
<div
class="notification-container"
style="display: flex; flex-direction: column;"
aria-live="polite"
>
${story()}
</div>
${pageContent()}
Expand Down
13 changes: 13 additions & 0 deletions src/components/notification/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,19 @@ If the `sbb-notification` host needs a margin, in order to properly animate it o
we suggest using the `--sbb-notification-margin` variable to set it.
For example, use `--sbb-notification-margin: 0 0 var(--sbb-spacing-fixed-4x) 0` to apply a bottom margin.

## Accessibility

In order to announce the notification's content to screen readers as it becomes visible,
consumers **must** use the `aria-live` attribute with the `polite` value on the component's container.
This ensures that users who rely on screen readers are promptly informed of any relevant updates or changes.

```html
<!-- Add here any incoming notification by adding a sbb-notification component. -->
<div id="notification-container" aria-live="polite">
<sbb-notification type="success">Task successfully completed.</sbb-notification>
</div>
```

<!-- Auto Generated Below -->

## Properties
Expand Down

0 comments on commit 00e9540

Please sign in to comment.