Skip to content

Commit c41c0d4

Browse files
authored
Merge pull request #239 from getsentry/fix/accessibility-alt-attributes
fix(accessibility): add alt text to PlatformIcon
2 parents 69d8138 + 245c6b5 commit c41c0d4

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

src/platformIcon.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,8 @@ type Props = React.HTMLAttributes<HTMLDivElement | HTMLImageElement> & {
301301
radius?: number | null;
302302
withLanguageIcon?: boolean;
303303
languageIconStyles?: React.CSSProperties;
304+
/** Accessible label for the icon. Defaults to the platform name. Pass an empty string to mark the icon as decorative. */
305+
alt?: string;
304306
};
305307

306308
const PlatformIcon = ({
@@ -311,6 +313,7 @@ const PlatformIcon = ({
311313
withLanguageIcon,
312314
languageIconStyles = {},
313315
style = {},
316+
alt = platform,
314317
...otherProps
315318
}: Props) => {
316319
const icon = getIcon(platform);
@@ -322,15 +325,22 @@ const PlatformIcon = ({
322325

323326
if (withLanguageIcon && languageIcon !== icon && languageIcon !== "default") {
324327
return (
325-
<div {...otherProps} style={{ position: "relative", ...style }}>
328+
<div
329+
{...otherProps}
330+
role={alt === "" ? undefined : "img"}
331+
aria-label={alt === "" ? undefined : alt}
332+
style={{ position: "relative", ...style }}
333+
>
326334
<img
327335
src={iconPath}
328336
width={size}
329337
height={size}
338+
alt=""
330339
style={{ borderRadius: `${radius}px` }}
331340
/>
332341
<img
333342
src={languageIconPath}
343+
alt=""
334344
style={{
335345
position: "absolute",
336346
bottom: "-1px",
@@ -350,6 +360,7 @@ const PlatformIcon = ({
350360
src={iconPath}
351361
width={size}
352362
height={size}
363+
alt={alt}
353364
{...otherProps}
354365
style={{ borderRadius: `${radius}px`, ...style }}
355366
/>

0 commit comments

Comments
 (0)