Skip to content

Commit

Permalink
feat(message): add icon description for screen readers
Browse files Browse the repository at this point in the history
Fixes #7027
  • Loading branch information
MarcServat committed Nov 8, 2024
1 parent a4d25b4 commit 47c5a2c
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/components/message/message.component.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useRef } from "react";
import { MarginProps } from "styled-system";

import Typography from "../typography";
import MessageStyle from "./message.style";
import TypeIcon from "./__internal__/type-icon/type-icon.component";
import MessageContent from "./__internal__/message-content/message-content.component";
Expand Down Expand Up @@ -93,6 +94,7 @@ export const Message = React.forwardRef<HTMLDivElement, MessageProps>(
tabIndex={-1}
>
<TypeIcon variant={variant} transparent={transparent} />
<Typography screenReaderOnly>{l.message[variant]()}</Typography>
<MessageContent
showCloseIcon={showCloseIcon}
title={title}
Expand Down
5 changes: 5 additions & 0 deletions src/components/message/message.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ test("renders close button aria-label with custom value from translations", () =
locale={{
...enGB,
message: {
info: () => "Information",
success: () => "Success",
warning: () => "Warning",
neutral: () => "Neutral",
error: () => "Error",
closeButtonAriaLabel: () => "test close button",
},
}}
Expand Down
5 changes: 5 additions & 0 deletions src/hooks/__internal__/useLocale/useLocale.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ test("when I18nProvider exists, it should return a translation function that pro
locale={{
locale: () => "en-GB",
message: {
info: () => "Information",
success: () => "Success",
warning: () => "Warning",
neutral: () => "Neutral",
error: () => "Error",
closeButtonAriaLabel: () => "test",
},
}}
Expand Down
5 changes: 5 additions & 0 deletions src/locales/de-de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ const deDE: Partial<Locale> = {
},
message: {
closeButtonAriaLabel: () => "Schließen",
error: () => "Fehler",
info: () => "Informationen",
success: () => "Erfolg",
warning: () => "Warnung",
neutral: () => "Informationen",
},
numeralDate: {
validation: {
Expand Down
5 changes: 5 additions & 0 deletions src/locales/en-gb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ const enGB: Locale = {
},
message: {
closeButtonAriaLabel: () => "Close",
error: () => "Error",
info: () => "Information",
success: () => "Success",
warning: () => "Warning",
neutral: () => "Information",
},
numeralDate: {
validation: {
Expand Down
5 changes: 5 additions & 0 deletions src/locales/es-es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ const esES: Partial<Locale> = {
},
message: {
closeButtonAriaLabel: () => "Cerrar",
error: () => "Error",
info: () => "Información",
success: () => "Acción realizada",
warning: () => "Aviso",
neutral: () => "Información",
},
numeralDate: {
validation: {
Expand Down
5 changes: 5 additions & 0 deletions src/locales/fr-ca.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ const frCA: Partial<Locale> = {
},
message: {
closeButtonAriaLabel: () => "Fermer",
error: () => "Erreur",
info: () => "Information",
success: () => "Opération réussie",
warning: () => "Avertissement",
neutral: () => "Information",
},
numeralDate: {
validation: {
Expand Down
5 changes: 5 additions & 0 deletions src/locales/fr-fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ const frFR: Partial<Locale> = {
},
message: {
closeButtonAriaLabel: () => "Fermer",
error: () => "Erreur",
info: () => "Information",
success: () => "Action réussie",
warning: () => "Avertissement",
neutral: () => "Information",
},
numeralDate: {
validation: {
Expand Down
5 changes: 5 additions & 0 deletions src/locales/locale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ interface Locale {
};
message: {
closeButtonAriaLabel: () => string;
error: () => string;
info: () => string;
success: () => string;
warning: () => string;
neutral: () => string;
};
numeralDate: {
validation: {
Expand Down

0 comments on commit 47c5a2c

Please sign in to comment.