Skip to content

Commit e6a2648

Browse files
authored
Add aria-hidden attribute to spacers (#63126)
1 parent a45c4ad commit e6a2648

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/Components/Web/src/Virtualization/Virtualize.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,8 @@ protected override void BuildRenderTree(RenderTreeBuilder builder)
223223

224224
builder.OpenElement(0, SpacerElement);
225225
builder.AddAttribute(1, "style", GetSpacerStyle(_itemsBefore));
226-
builder.AddElementReferenceCapture(2, elementReference => _spacerBefore = elementReference);
226+
builder.AddAttribute(2, "aria-hidden", "true");
227+
builder.AddElementReferenceCapture(3, elementReference => _spacerBefore = elementReference);
227228
builder.CloseElement();
228229

229230
var lastItemIndex = Math.Min(_itemsBefore + _visibleItemCapacity, _itemCount);
@@ -283,8 +284,9 @@ protected override void BuildRenderTree(RenderTreeBuilder builder)
283284
var itemsAfter = Math.Max(0, _itemCount - _visibleItemCapacity - _itemsBefore);
284285

285286
builder.OpenElement(7, SpacerElement);
286-
builder.AddAttribute(8, "style", GetSpacerStyle(itemsAfter, _unusedItemCapacity));
287-
builder.AddElementReferenceCapture(9, elementReference => _spacerAfter = elementReference);
287+
builder.AddAttribute(8, "aria-hidden", "true");
288+
builder.AddAttribute(9, "style", GetSpacerStyle(itemsAfter, _unusedItemCapacity));
289+
builder.AddElementReferenceCapture(10, elementReference => _spacerAfter = elementReference);
288290

289291
builder.CloseElement();
290292
}

src/Components/test/E2ETest/Tests/VirtualizationTest.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,23 @@ public void AlwaysFillsVisibleCapacity_Sync()
4040
// Wait until items have been rendered.
4141
Browser.True(() => (initialItemCount = GetItemCount()) > 0);
4242
Browser.Equal(expectedInitialSpacerStyle, () => topSpacer.GetDomAttribute("style"));
43+
Assert.Contains("true", topSpacer.GetDomAttribute("aria-hidden"));
4344

4445
// Scroll halfway.
4546
Browser.ExecuteJavaScript("const container = document.getElementById('sync-container');container.scrollTop = container.scrollHeight * 0.5;");
4647

4748
// Validate that we get the same item count after scrolling halfway.
4849
Browser.Equal(initialItemCount, GetItemCount);
4950
Browser.NotEqual(expectedInitialSpacerStyle, () => topSpacer.GetDomAttribute("style"));
51+
Assert.Contains("true", topSpacer.GetDomAttribute("aria-hidden"));
5052

5153
// Scroll to the bottom.
5254
Browser.ExecuteJavaScript("const container = document.getElementById('sync-container');container.scrollTop = container.scrollHeight;");
5355

5456
// Validate that we get the same item count after scrolling to the bottom.
5557
Browser.Equal(initialItemCount, GetItemCount);
5658
Browser.NotEqual(expectedInitialSpacerStyle, () => topSpacer.GetDomAttribute("style"));
59+
Assert.Contains("true", topSpacer.GetDomAttribute("aria-hidden"));
5760

5861
int GetItemCount() => Browser.FindElements(By.Id("sync-item")).Count;
5962
}
@@ -200,6 +203,7 @@ public void CanUseViewportAsContainer()
200203

201204
// Validate that the top spacer has a height of zero.
202205
Browser.Equal(expectedInitialSpacerStyle, () => topSpacer.GetDomAttribute("style"));
206+
Assert.Contains("true", topSpacer.GetDomAttribute("aria-hidden"));
203207

204208
Browser.ExecuteJavaScript("window.scrollTo(0, document.body.scrollHeight);");
205209

@@ -209,6 +213,7 @@ public void CanUseViewportAsContainer()
209213

210214
// Validate that the top spacer has expanded.
211215
Browser.NotEqual(expectedInitialSpacerStyle, () => topSpacer.GetDomAttribute("style"));
216+
Assert.Contains("true", topSpacer.GetDomAttribute("aria-hidden"));
212217
}
213218

214219
[Fact]
@@ -221,6 +226,7 @@ public async Task ToleratesIncorrectItemSize()
221226
// Wait until items have been rendered.
222227
Browser.True(() => GetItemCount() > 0);
223228
Browser.Equal(expectedInitialSpacerStyle, () => topSpacer.GetDomAttribute("style"));
229+
Assert.Contains("true", topSpacer.GetDomAttribute("aria-hidden"));
224230

225231
// Scroll slowly, in increments of 50px at a time. At one point this would trigger a bug
226232
// due to the incorrect item size, whereby it would not realise it's necessary to show more
@@ -234,6 +240,7 @@ public async Task ToleratesIncorrectItemSize()
234240

235241
// Validate that the top spacer did change
236242
Browser.NotEqual(expectedInitialSpacerStyle, () => topSpacer.GetDomAttribute("style"));
243+
Assert.Contains("true", topSpacer.GetDomAttribute("aria-hidden"));
237244

238245
int GetItemCount() => Browser.FindElements(By.ClassName("incorrect-size-item")).Count;
239246
}
@@ -250,6 +257,8 @@ public void CanRenderHtmlTable()
250257
Assert.Equal("tr", topSpacer.TagName.ToLowerInvariant());
251258
Assert.Equal("tr", bottomSpacer.TagName.ToLowerInvariant());
252259
Assert.Contains(expectedInitialSpacerStyle, topSpacer.GetDomAttribute("style"));
260+
Assert.Contains("true", topSpacer.GetDomAttribute("aria-hidden"));
261+
Assert.Contains("true", bottomSpacer.GetDomAttribute("aria-hidden"));
253262

254263
// Check scrolling document element works
255264
Browser.DoesNotExist(By.Id("row-999"));

0 commit comments

Comments
 (0)