Skip to content

Commit 17642c2

Browse files
committed
Fixed aria labels on ValueSelect
1 parent 0aacf74 commit 17642c2

7 files changed

Lines changed: 27 additions & 12 deletions

File tree

src/EventLogExpert/Shared/Components/Filters/FilterRow.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
<div>
4444
@if (Value.Data.Category is FilterCategory.Description)
4545
{
46-
<TextInput aria-labelledby="@($"{Id}_Value")" CssClass="input filter-description" @bind-Value="@Value.Data.Value" />
46+
<TextInput CssClass="input filter-description" @bind-Value="@Value.Data.Value" />
4747
}
4848
else if (Value.Data.Evaluator == FilterEvaluator.MultiSelect)
4949
{

src/EventLogExpert/Shared/Components/Filters/SubFilterRow.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<label aria-label="Value" id="@($"{Id}_Value")">Value: </label>
2525
@if (Value.Data.Category is FilterCategory.Description)
2626
{
27-
<TextInput aria-labelledby="@($"{Id}_Value")" CssClass="input filter-description" @bind-Value="@Value.Data.Value" />
27+
<TextInput CssClass="input filter-description" @bind-Value="@Value.Data.Value" />
2828
}
2929
else if (Value.Data.Evaluator == FilterEvaluator.MultiSelect)
3030
{

src/EventLogExpert/Shared/Components/ValueSelect.razor

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
@inherits BaseComponent<T>
44

55
<div class="dropdown-input" @onkeydown="HandleKeyDown" @onkeydown:preventDefault="_preventDefault" @ref="_selectComponent">
6-
<input aria-expanded="false" aria-label="@AriaLabel" aria-labelledby="@AriaLabelledBy" class="@CssClass" @oninput="OnInputChange"
7-
readonly="@(!IsInput || IsMultiSelect)" role="listbox" tabindex="0" type="text" value="@DisplayString" />
6+
<input aria-activedescendant="@HighlightedItem?.ItemId" aria-controls="@_itemId" aria-expanded="@IsOpen" aria-label="@AriaLabel" aria-labelledby="@AriaLabelledBy"
7+
class="@CssClass" @oninput="OnInputChange" readonly="@(!IsInput || IsMultiSelect)" role="combobox" tabindex="0" type="text" value="@DisplayString" />
88

9-
<div class="dropdown-list" tabindex="-1">
9+
<div class="dropdown-list" id="@_itemId" role="listbox" tabindex="-1">
1010
<CascadingValue Value="this">
1111
@ChildContent
1212
</CascadingValue>

src/EventLogExpert/Shared/Components/ValueSelect.razor.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ namespace EventLogExpert.Shared.Components;
1010

1111
public sealed partial class ValueSelect<T> : BaseComponent<T>
1212
{
13+
private readonly string _itemId = $"select_{Guid.NewGuid().ToString()[..8]}";
1314
private readonly List<ValueSelectItem<T>> _items = [];
1415
private readonly HashSet<T> _selectedValues = [];
1516

1617
private ValueSelectItem<T>? _highlightedItem;
18+
private bool _isOpen;
1719
private bool _preventDefault;
1820
private ElementReference _selectComponent;
1921

@@ -38,7 +40,9 @@ public ValueSelectItem<T>? HighlightedItem
3840
public bool IsInput { get; set; }
3941

4042
[Parameter]
41-
public bool IsMultiSelect { get; set; } = false;
43+
public bool IsMultiSelect { get; set; }
44+
45+
public string IsOpen => _isOpen.ToString().ToLower();
4246

4347
private string? DisplayString
4448
{
@@ -86,9 +90,17 @@ public bool AddItem(ValueSelectItem<T> item)
8690

8791
public void ClearSelected() => _selectedValues.Clear();
8892

89-
public async Task CloseDropDown() => await JSRuntime.InvokeVoidAsync("closeDropdown", _selectComponent);
93+
public async Task CloseDropDown()
94+
{
95+
_isOpen = false;
96+
await JSRuntime.InvokeVoidAsync("closeDropdown", _selectComponent);
97+
}
9098

91-
public async Task OpenDropDown() => await JSRuntime.InvokeVoidAsync("openDropdown", _selectComponent);
99+
public async Task OpenDropDown()
100+
{
101+
_isOpen = true;
102+
await JSRuntime.InvokeVoidAsync("openDropdown", _selectComponent);
103+
}
92104

93105
public void RemoveItem(ValueSelectItem<T> item) => _items.Remove(item);
94106

src/EventLogExpert/Shared/Components/ValueSelectItem.razor

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
@typeparam T
22

3-
<div aria-selected="@_isSelected" class="@CssClass" highlighted="@(_parent.HighlightedItem?.Equals(this) ?? false)"
4-
@onmousedown="SelectItem" @onmouseenter="HighlightItem" role="option" selected="@_isSelected">
3+
<div aria-selected="@_isSelected.ToString().ToLower()" class="@CssClass" highlighted="@(_parent.HighlightedItem?.Equals(this) ?? false)"
4+
id="@ItemId" @onmousedown="SelectItem" @onmouseenter="HighlightItem" role="option">
5+
56
@if (ChildContent is not null)
67
{
78
@ChildContent

src/EventLogExpert/Shared/Components/ValueSelectItem.razor.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ public sealed partial class ValueSelectItem<T> : IDisposable
2323
[Parameter]
2424
public bool IsDisabled { get; set; }
2525

26+
public string ItemId { get; } = $"_{Guid.NewGuid().ToString()[..8]}";
27+
2628
[Parameter]
2729
public T Value { get; set; } = default!;
2830

src/EventLogExpert/wwwroot/css/app.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ i.bi.bi-star-fill { color: var(--clr-yellow); }
311311
&:hover,
312312
&[highlighted] { background-color: var(--background-darkgray); }
313313

314-
&[selected] {
314+
&[aria-selected="true"] {
315315
color: var(--background-darkgray);
316316
background-color: var(--clr-lightblue);
317317
}
@@ -391,7 +391,7 @@ i.bi.bi-star-fill { color: var(--clr-yellow); }
391391

392392
&:hover { filter: brightness(0.9); }
393393

394-
&[selected] { filter: brightness(0.9); }
394+
&[aria-selected="true"] { filter: brightness(0.9); }
395395
}
396396

397397
@media (forced-colors: active) {

0 commit comments

Comments
 (0)