Skip to content

Commit a6a8496

Browse files
Lonzakniloc132zbynek
authored
Improving accessability - added aria presentation role for layout tables (#10108)
According to accessibility rules layout tables exist merely to position content visually and should not be used in HTML5. Screen readers may interpret them as data tables (i.e., announcing column and row numbers) etc). To change that in GWT would be a bigger task. So as a minor improvement those tables should be marked as layout tables. This can be done by assigning the role="presentation" to ensure it is not identified as a table to screen reader users. --------- Co-authored-by: Colin Alworth <[email protected]> Co-authored-by: Zbynek Konecny <[email protected]>
1 parent 2425f0e commit a6a8496

15 files changed

+73
-2
lines changed

user/src/com/google/gwt/user/client/ui/CellPanel.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package com.google.gwt.user.client.ui;
1717

18+
import com.google.gwt.aria.client.Roles;
1819
import com.google.gwt.dom.client.Element;
1920
import com.google.gwt.user.client.DOM;
2021
import com.google.gwt.user.client.ui.HasHorizontalAlignment.HorizontalAlignmentConstant;
@@ -72,6 +73,8 @@ public abstract class CellPanel extends ComplexPanel {
7273

7374
public CellPanel() {
7475
table = DOM.createTable();
76+
// aria role to indicate it is a plain layout table
77+
Roles.getPresentationRole().set(table);
7578
body = DOM.createTBody();
7679
DOM.appendChild(table, body);
7780
setElement(table);

user/src/com/google/gwt/user/client/ui/DecoratedStackPanel.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package com.google.gwt.user.client.ui;
1717

18+
import com.google.gwt.aria.client.Roles;
1819
import com.google.gwt.dom.client.Element;
1920
import com.google.gwt.user.client.DOM;
2021

@@ -81,6 +82,8 @@ public DecoratedStackPanel() {
8182
Element createHeaderElem() {
8283
// Create the table
8384
Element table = DOM.createTable();
85+
// aria role to indicate it is a plain layout table
86+
Roles.getPresentationRole().set(table);
8487
Element tbody = DOM.createTBody();
8588
DOM.appendChild(table, tbody);
8689
table.getStyle().setProperty("width", "100%");

user/src/com/google/gwt/user/client/ui/DecoratorPanel.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package com.google.gwt.user.client.ui;
1717

18+
import com.google.gwt.aria.client.Roles;
1819
import com.google.gwt.dom.client.Element;
1920
import com.google.gwt.i18n.client.LocaleInfo;
2021
import com.google.gwt.user.client.DOM;
@@ -164,6 +165,9 @@ public DecoratorPanel() {
164165

165166
// Add a tbody
166167
Element table = getElement();
168+
// aria role to indicate it is a plain layout table
169+
Roles.getPresentationRole().set(table);
170+
167171
tbody = DOM.createTBody();
168172
DOM.appendChild(table, tbody);
169173
table.setPropertyInt("cellSpacing", 0);

user/src/com/google/gwt/user/client/ui/DisclosurePanel.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package com.google.gwt.user.client.ui;
1717

1818
import com.google.gwt.animation.client.Animation;
19+
import com.google.gwt.aria.client.Roles;
1920
import com.google.gwt.core.client.GWT;
2021
import com.google.gwt.dom.client.Element;
2122
import com.google.gwt.event.logical.shared.CloseEvent;
@@ -230,6 +231,9 @@ private DefaultHeader(Imager imager, String text) {
230231

231232
// I do not need any Widgets here, just a DOM structure.
232233
Element root = DOM.createTable();
234+
// aria role to indicate it is a plain layout table
235+
Roles.getPresentationRole().set(root);
236+
233237
Element tbody = DOM.createTBody();
234238
Element tr = DOM.createTR();
235239
final Element imageTD = DOM.createTD();

user/src/com/google/gwt/user/client/ui/MenuBar.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,6 +1180,9 @@ private void init(boolean vertical, AbstractImagePrototype subMenuIcon) {
11801180
this.subMenuIcon = subMenuIcon;
11811181

11821182
Element table = DOM.createTable();
1183+
// aria role to indicate it is a plain layout table
1184+
Roles.getPresentationRole().set(table);
1185+
11831186
body = DOM.createTBody();
11841187
DOM.appendChild(table, body);
11851188

user/src/com/google/gwt/user/client/ui/StackPanel.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package com.google.gwt.user.client.ui;
1717

18+
import com.google.gwt.aria.client.Roles;
1819
import com.google.gwt.dom.client.Element;
1920
import com.google.gwt.safehtml.shared.SafeHtml;
2021
import com.google.gwt.safehtml.shared.annotations.IsSafeHtml;
@@ -63,6 +64,8 @@ public class StackPanel extends ComplexPanel implements InsertPanel.ForIsWidget
6364
*/
6465
public StackPanel() {
6566
Element table = DOM.createTable();
67+
// aria role to indicate it is a plain layout table
68+
Roles.getPresentationRole().set(table);
6669
setElement(table);
6770

6871
body = DOM.createTBody();

user/src/com/google/gwt/user/client/ui/TreeItem.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ void initializeClonableElements() {
8888
if (GWT.isClient()) {
8989
// Create the base table element that will be cloned.
9090
BASE_INTERNAL_ELEM = DOM.createTable();
91+
// aria role to indicate it is a plain layout table
92+
Roles.getPresentationRole().set(BASE_INTERNAL_ELEM);
9193
Element contentElem = DOM.createDiv();
9294
Element tbody = DOM.createTBody(), tr = DOM.createTR();
9395
Element tdImg = DOM.createTD(), tdContent = DOM.createTD();

user/test/com/google/gwt/user/client/ui/DecoratorPanelTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@ public void testDefaultStyles() {
9191
// Check the container element
9292
assertTrue(panel.getCellElement(1, 1) == panel.getContainerElement());
9393
}
94+
95+
public void testPresentationRole() {
96+
DecoratorPanel panel = createPanel();
97+
assertNotNull(panel.getElement());
98+
assertEquals("presentation", panel.getElement().getAttribute("role"));
99+
}
94100

95101
@Override
96102
protected DecoratorPanel createPanel() {

user/test/com/google/gwt/user/client/ui/DisclosurePanelTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,12 @@ public void testRemoveNullAsIsWidget() {
232232
panel.remove(widget);
233233
// ta da...
234234
}
235+
236+
public void testPresentationRole() {
237+
DisclosurePanel panel = createEmptyDisclourePanel();
238+
assertNotNull(panel.getElement());
239+
assertEquals("presentation", panel.getElement().getAttribute("role"));
240+
}
235241

236242
private DisclosurePanel createEmptyDisclourePanel() {
237243
return new DisclosurePanel();

user/test/com/google/gwt/user/client/ui/DockPanelTest.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
/**
2323
* Tests the DockPanel widget.
2424
*/
25-
@SuppressWarnings("deprecation")
2625
public class DockPanelTest extends GWTTestCase {
2726

2827
static class Adder implements HasWidgetsTester.WidgetAdder {
@@ -125,6 +124,12 @@ public void testAddAsIsWidget() {
125124
assertPhysicalPaternity(panel,widget);
126125
}
127126

127+
public void testPresentationRole() {
128+
DockPanel panel = createDockPanel();
129+
assertNotNull(panel.getElement());
130+
assertEquals("presentation", panel.getElement().getAttribute("role"));
131+
}
132+
128133
public void testAttachDetachOrder() {
129134
HasWidgetsTester.testAll(new DockPanel(), new Adder(), true);
130135
}

0 commit comments

Comments
 (0)