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 Oct 28, 2024
1 parent 02a8c60 commit d664b2e
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 1 deletion.
3 changes: 2 additions & 1 deletion 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 @@ -80,7 +81,6 @@ export const Message = React.forwardRef<HTMLDivElement, MessageProps>(
</IconButton>
);
};

return open ? (
<MessageStyle
{...tagComponent("Message", props)}
Expand All @@ -93,6 +93,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: () => "",
info: () => "",
success: () => "",
warning: () => "",
neutral: () => "",
},
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: () => "",
info: () => "",
success: () => "",
warning: () => "",
neutral: () => "",
},
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: () => "",
info: () => "",
success: () => "",
warning: () => "",
neutral: () => "",
},
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: () => "",
info: () => "",
success: () => "",
warning: () => "",
neutral: () => "",
},
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 d664b2e

Please sign in to comment.