Skip to content

Commit e8aeff0

Browse files
authored
feat!: add aria-hidden="true" to hr component by default (#22571)
* feat!: add aria-hidden="true" to hr component by default The <hr> element is announced as "Horizontal Splitter" by screen readers (e.g., VoiceOver on macOS), but in most cases it's used for visual purposes only. Adding aria-hidden="true" by default improves accessibility by preventing screen readers from announcing it. Users can still override this if needed by removing the attribute. Fixes #14881
1 parent 8c46c41 commit e8aeff0

File tree

2 files changed

+11
-0
lines changed
  • flow-html-components/src
    • main/java/com/vaadin/flow/component/html
    • test/java/com/vaadin/flow/component/html

2 files changed

+11
-0
lines changed

flow-html-components/src/main/java/com/vaadin/flow/component/html/Hr.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,6 @@ public class Hr extends HtmlComponent {
3232
*/
3333
public Hr() {
3434
super();
35+
getElement().setAttribute("aria-hidden", "true");
3536
}
3637
}

flow-html-components/src/test/java/com/vaadin/flow/component/html/HrTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
*/
1616
package com.vaadin.flow.component.html;
1717

18+
import org.junit.Assert;
19+
import org.junit.Test;
20+
1821
public class HrTest extends ComponentTest {
1922

2023
// Actual test methods in super class
@@ -23,4 +26,11 @@ public class HrTest extends ComponentTest {
2326
protected void addProperties() {
2427
// Component defines no new properties
2528
}
29+
30+
@Test
31+
public void ariaHiddenSetByDefault() {
32+
Hr hr = new Hr();
33+
Assert.assertEquals("true",
34+
hr.getElement().getAttribute("aria-hidden"));
35+
}
2636
}

0 commit comments

Comments
 (0)