Skip to content

Commit 8eaf2d3

Browse files
committed
feat: Add ariaLabel property to icon
1 parent 3cdecff commit 8eaf2d3

File tree

4 files changed

+33
-2
lines changed

4 files changed

+33
-2
lines changed

src/__tests__/snapshot-tests/__snapshots__/documenter.test.ts.snap

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8890,12 +8890,19 @@ exports[`Documenter definition for icon matches the snapshot: icon 1`] = `
88908890
"name": "Icon",
88918891
"properties": [
88928892
{
8893+
"deprecatedTag": "Use the \`ariaLabel\` property instead.",
88938894
"description": "Specifies alternate text for a custom icon (using the \`url\` attribute). We recommend that you provide this for accessibility.
88948895
This property is ignored if you use a predefined icon or if you set your custom icon using the \`svg\` slot.",
88958896
"name": "alt",
88968897
"optional": true,
88978898
"type": "string",
88988899
},
8900+
{
8901+
"description": "Specifies alternate text for the icon. We recommend that you provide this for accessibility.",
8902+
"name": "ariaLabel",
8903+
"optional": true,
8904+
"type": "string",
8905+
},
88998906
{
89008907
"deprecatedTag": "Custom CSS is not supported. For testing and other use cases, use [data attributes](https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes).",
89018908
"description": "Adds the specified classes to the root element of the component.",
@@ -13942,6 +13949,16 @@ The function will be called when a user clicks on the trigger button.",
1394213949
"optional": true,
1394313950
"type": "(itemsType: string) => string",
1394413951
},
13952+
{
13953+
"name": "labelIconFile",
13954+
"optional": true,
13955+
"type": "string",
13956+
},
13957+
{
13958+
"name": "labelIconFolder",
13959+
"optional": true,
13960+
"type": "string",
13961+
},
1394513962
{
1394613963
"name": "labelModalDismiss",
1394713964
"optional": true,

src/icon/interfaces.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export interface IconProps extends BaseComponentProps {
99
* Specifies the icon to be displayed.
1010
*/
1111
name?: IconProps.Name;
12+
1213
/**
1314
* Specifies the size of the icon.
1415
*
@@ -32,12 +33,20 @@ export interface IconProps extends BaseComponentProps {
3233
* If you set both `url` and `svg`, `svg` will take precedence.
3334
*/
3435
url?: string;
36+
3537
/**
3638
* Specifies alternate text for a custom icon (using the `url` attribute). We recommend that you provide this for accessibility.
3739
* This property is ignored if you use a predefined icon or if you set your custom icon using the `svg` slot.
40+
*
41+
* @deprecated Use the `ariaLabel` property instead.
3842
*/
3943
alt?: string;
4044

45+
/**
46+
* Specifies alternate text for the icon. We recommend that you provide this for accessibility.
47+
*/
48+
ariaLabel?: string;
49+
4150
/**
4251
* Specifies the SVG of a custom icon.
4352
*

src/icon/internal.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ const InternalIcon = ({
4444
variant = 'normal',
4545
url,
4646
alt,
47+
ariaLabel,
4748
svg,
4849
badge,
4950
__internalRootRef = null,
@@ -100,7 +101,7 @@ const InternalIcon = ({
100101
if (url) {
101102
return (
102103
<span {...baseProps} ref={mergedRef} style={inlineStyles}>
103-
<img src={url} alt={alt} />
104+
<img src={url} alt={ariaLabel ?? alt} />
104105
</span>
105106
);
106107
}
@@ -130,8 +131,10 @@ const InternalIcon = ({
130131
}
131132
}
132133

134+
const labelAttributes = ariaLabel ? { role: 'img', 'aria-label': ariaLabel } : {};
135+
133136
return (
134-
<span {...baseProps} ref={mergedRef} style={inlineStyles}>
137+
<span {...baseProps} {...labelAttributes} ref={mergedRef} style={inlineStyles}>
135138
{validIcon ? iconMap(name) : undefined}
136139
</span>
137140
);

src/s3-resource-selector/interfaces.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,8 @@ export namespace S3ResourceSelectorProps {
267267
labelBreadcrumbs?: string;
268268
labelExpandBreadcrumbs?: string;
269269
labelClearFilter?: string;
270+
labelIconFolder?: string;
271+
labelIconFile?: string;
270272
}
271273

272274
export interface ChangeDetail {

0 commit comments

Comments
 (0)