feat(module: icon): icon role attribute change now assignable, does not change default behavior (#3370)

when a screen reader parses an icon, it sees the role attribute has a value of 'img'. in the case where we don't want the screen reader to read the icon, the role can be assigned a blank value and the role attribute will not be added. instead, the aria-hidden attribute will be added with a value of 'true'

no breaking changes
This commit is contained in:
Peter Ha 2023-07-25 08:30:30 -07:00 committed by GitHub
parent 679a83410a
commit c559bd321e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 1 deletions

View File

@ -1,7 +1,7 @@
@namespace AntDesign
@inherits AntDomComponentBase
<span role="img" alt="@Alt" class="@ClassMapper.Class" style="@Style" id="@Id" tabindex="@TabIndex" @ref="Ref" @attributes="_attributes" @onclick:stopPropagation="StopPropagation">
<span class="@ClassMapper.Class" style="@Style" id="@Id" tabindex="@TabIndex" @ref="Ref" @attributes="_attributes" @onclick:stopPropagation="StopPropagation">
@if (Component == null)
{
@((MarkupString) _svgImg)

View File

@ -11,6 +11,12 @@ namespace AntDesign
[Parameter]
public string Alt { get; set; }
[Parameter]
public string Role { get; set; } = "img";
[Parameter]
public string AriaLabel { get; set; }
[Parameter]
public bool Spin { get; set; }
@ -91,6 +97,22 @@ namespace AntDesign
_attributes.Add("onclick", (Delegate)HandleOnClick);
}
_attributes.Add("aria-label", AriaLabel);
if (String.IsNullOrEmpty(Role))
{
_attributes.Add("aria-hidden", "true");
}
else
{
_attributes.Add("role", Role);
}
if (Role == "img")
{
_attributes.Add("alt", Alt);
}
await base.OnInitializedAsync();
}