Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Accessibility] Fix of the unannounced Required keyword with FluentSelect #2706

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Core/Components/List/FluentSelect.razor
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
@typeparam TOption
<CascadingValue Value="_internalListContext" Name="ListContext" TValue="InternalListContext<TOption>" IsFixed="true">
@InlineStyleValue
<FluentInputLabel ForId="@Id" Label="@Label" AriaLabel="@AriaLabel" Required="@Required" ChildContent="@LabelTemplate" />
<FluentInputLabel ForId="@Id" Label="@Label" AriaLabel="@GetAriaLabelWithRequired()" Required="@Required" ChildContent="@LabelTemplate" />
<fluent-select @ref=Element
id=@Id
class="@ClassValue"
Expand Down
12 changes: 12 additions & 0 deletions src/Core/Components/List/FluentSelect.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
[CascadingTypeParameter(nameof(TOption))]
public partial class FluentSelect<TOption> : ListComponentBase<TOption> where TOption : notnull
{
/// <summary>
/// Gets the `Required` aria label.
/// </summary>
public static string RequiredAriaLabel = "Required";

/// <summary />
protected virtual MarkupString InlineStyleValue => new InlineStyleBuilder()
.AddStyle($"#{Id}::part(listbox)", "max-height", Height, !string.IsNullOrWhiteSpace(Height))
Expand Down Expand Up @@ -39,4 +44,11 @@
/// </summary>
[Parameter]
public Appearance? Appearance { get; set; }

private string? GetAriaLabelWithRequired()
{
var label = AriaLabel ?? Label ?? Title ?? string.Empty;

Check warning on line 50 in src/Core/Components/List/FluentSelect.razor.cs

View workflow job for this annotation

GitHub Actions / Build and Deploy Demo site

'ListComponentBase<TOption>.Title' is obsolete: 'Use AriaLabel instead'

Check warning on line 50 in src/Core/Components/List/FluentSelect.razor.cs

View workflow job for this annotation

GitHub Actions / Build and Test Core Lib

'ListComponentBase<TOption>.Title' is obsolete: 'Use AriaLabel instead'

Check warning on line 50 in src/Core/Components/List/FluentSelect.razor.cs

View workflow job for this annotation

GitHub Actions / Build and Test Core Lib

'ListComponentBase<TOption>.Title' is obsolete: 'Use AriaLabel instead'

Check warning on line 50 in src/Core/Components/List/FluentSelect.razor.cs

View workflow job for this annotation

GitHub Actions / Build and Test Core Lib

'ListComponentBase<TOption>.Title' is obsolete: 'Use AriaLabel instead'

Check warning on line 50 in src/Core/Components/List/FluentSelect.razor.cs

View workflow job for this annotation

GitHub Actions / Build and Test Core Lib

'ListComponentBase<TOption>.Title' is obsolete: 'Use AriaLabel instead'

Check warning on line 50 in src/Core/Components/List/FluentSelect.razor.cs

View workflow job for this annotation

GitHub Actions / Build and Test Core Lib

'ListComponentBase<TOption>.Title' is obsolete: 'Use AriaLabel instead'

Check warning on line 50 in src/Core/Components/List/FluentSelect.razor.cs

View workflow job for this annotation

GitHub Actions / Build and Test Core Lib

'ListComponentBase<TOption>.Title' is obsolete: 'Use AriaLabel instead'

return label + (Required ? $", {RequiredAriaLabel}" : string.Empty);
}
}
Loading