Skip to content

Commit 12de8fa

Browse files
ErikCHErik Hanchett
andauthored
fix(Angular + Vue): Add accessible label to Alert dismiss button Authenticator (#2339)
* Added aria label for Angular and Vue dismiss buttons * Added vue test * Added changeset * Fixed test * Fixed Angular bug * removed import Co-authored-by: Erik Hanchett <[email protected]>
1 parent 31de229 commit 12de8fa

File tree

5 files changed

+59
-6
lines changed

5 files changed

+59
-6
lines changed

.changeset/late-ducks-divide.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@aws-amplify/ui-angular': patch
3+
'@aws-amplify/ui-vue': patch
4+
---
5+
6+
Adds an accessible label for the Alert dismiss button, which is configurable via translation.

packages/angular/projects/ui-angular/src/lib/primitives/error/error.component.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
</div>
2121
<button
2222
amplify-button
23-
class="amplify-field-group__control"
23+
class="amplify-field-group__control amplify-alert__dismiss"
24+
[attr.aria-label]="dismissAriaLabel"
2425
variation="link"
2526
[fullWidth]="false"
2627
(click)="close()"

packages/angular/projects/ui-angular/src/lib/primitives/error/error.component.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { Component } from '@angular/core';
2+
import { translate } from '@aws-amplify/ui';
23

34
@Component({
45
selector: 'amplify-error',
56
templateUrl: './error.component.html',
67
})
78
export class ErrorComponent {
89
public isVisible = true;
10+
public dismissAriaLabel = translate('Dismiss alert');
911

1012
public close() {
1113
this.isVisible = false;
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import BaseAlert from '../base-alert.vue';
2+
import { components } from '../../../../global-spec';
3+
import { render } from '@testing-library/vue';
4+
5+
import { I18n } from 'aws-amplify';
6+
7+
describe('Base Alert', () => {
8+
it('Base Alert Exists', () => {
9+
const wrapper = render(BaseAlert, {
10+
global: {
11+
components,
12+
},
13+
});
14+
15+
expect(wrapper).toBeTruthy();
16+
});
17+
18+
it('shows correct default accessible label', () => {
19+
const { queryByRole } = render(BaseAlert, {
20+
global: {
21+
components,
22+
},
23+
});
24+
25+
const defaultButton = queryByRole('button');
26+
expect(defaultButton?.getAttribute('aria-label')).toBe('Dismiss alert');
27+
});
28+
it('shows correct default translated label', () => {
29+
const translatedAriaLabel = 'Translated dismiss alert';
30+
I18n.putVocabulariesForLanguage('en', {
31+
'Dismiss alert': translatedAriaLabel,
32+
});
33+
const { queryByRole } = render(BaseAlert, {
34+
global: {
35+
components,
36+
},
37+
});
38+
39+
const defaultButton = queryByRole('button');
40+
expect(defaultButton?.getAttribute('aria-label')).toBe(translatedAriaLabel);
41+
});
42+
});

packages/vue/src/components/primitives/base-alert.vue

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
<script setup>
22
import { ref } from 'vue';
3+
import { translate } from '@aws-amplify/ui';
4+
35
const show = ref(true);
46
7+
const dismissAriaLabel = translate('Dismiss alert');
8+
59
function close() {
610
show.value = false;
711
}
@@ -10,10 +14,7 @@ function close() {
1014
<template>
1115
<div
1216
v-if="show"
13-
class="
14-
amplify-flex amplify-alert amplify-alert--error
15-
amplify-authenticator__base
16-
"
17+
class="amplify-flex amplify-alert amplify-alert--error amplify-authenticator__base"
1718
data-variation="error"
1819
role="alert"
1920
>
@@ -31,7 +32,8 @@ function close() {
3132
<div><slot></slot></div>
3233
</div>
3334
<amplify-button
34-
class="amplify-field-group__control"
35+
class="amplify-field-group__control amplify-alert__dismiss"
36+
:aria-label="dismissAriaLabel"
3537
:fullwidth="false"
3638
:variation="'link'"
3739
type="button"

0 commit comments

Comments
 (0)