summaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorKnoobie <Knoobie@gmx.de>2017-10-11 12:15:26 +0200
committerHenri Sara <henri.sara@gmail.com>2017-10-11 13:15:26 +0300
commit0843f53881a3514a72370e51ab33f59df423aa0e (patch)
treeb094e68eb28adf57a540c2624f9ad78f888fddf9 /client
parent69c6675572e05c6b9c193b402f8d980f6af40884 (diff)
downloadvaadin-framework-0843f53881a3514a72370e51ab33f59df423aa0e.tar.gz
vaadin-framework-0843f53881a3514a72370e51ab33f59df423aa0e.zip
Add aria-rowcount to grid (#10167)
This is based on discussion from vaadin/vaadin-grid#1023 .
Diffstat (limited to 'client')
-rw-r--r--client/src/main/java/com/vaadin/client/widgets/Escalator.java85
1 files changed, 77 insertions, 8 deletions
diff --git a/client/src/main/java/com/vaadin/client/widgets/Escalator.java b/client/src/main/java/com/vaadin/client/widgets/Escalator.java
index cd5464a1cc..6adc0cbef9 100644
--- a/client/src/main/java/com/vaadin/client/widgets/Escalator.java
+++ b/client/src/main/java/com/vaadin/client/widgets/Escalator.java
@@ -1124,6 +1124,73 @@ public class Escalator extends Widget
}
}
+ /**
+ * Helper class that helps to implement the WAI-ARIA functionality
+ * for the Grid and TreeGrid component.
+ * <p>
+ * The following WAI-ARIA attributes are added through this class:
+ *
+ * <ul>
+ * <li>aria-rowcount (since 8.2)</li>
+ * </ul>
+ *
+ * @since 8.2
+ */
+ public class AriaGridHelper {
+
+ /**
+ * This field contains the total number of rows from the grid
+ * including rows from thead, tbody and tfoot.
+ *
+ * @since 8.2
+ */
+ private int allRows;
+
+ /**
+ * Adds the given numberOfRows to allRows and calls
+ * {@link #updateAriaRowCount()}.
+ *
+ * @param numberOfRows number of rows that were added to the
+ * grid
+ *
+ * @since 8.2
+ */
+ public void addRows(int numberOfRows) {
+ allRows += numberOfRows;
+ updateAriaRowCount();
+ }
+
+ /**
+ * Removes the given numberOfRows from allRows and calls
+ * {@link #updateAriaRowCount()}.
+ *
+ * @param numberOfRows number of rows that were removed from
+ * the grid
+ *
+ * @since 8.2
+ */
+ public void removeRows(int numberOfRows) {
+ allRows -= numberOfRows;
+ updateAriaRowCount();
+ }
+
+ /**
+ * Sets the aria-rowcount attribute with the current value
+ * of {@link AriaGridHelper#allRows} if the grid is attached
+ * and {@link AriaGridHelper#allRows} > 0.
+ *
+ * @since 8.2
+ */
+ public void updateAriaRowCount() {
+ if (!isAttached() || 0 > allRows) {
+
+ return;
+ }
+
+ getTable().setAttribute("aria-rowcount", String.valueOf(allRows));
+ }
+ }
+
public abstract class AbstractRowContainer implements RowContainer {
private EscalatorUpdater updater = EscalatorUpdater.NULL;
@@ -1150,8 +1217,7 @@ public class Escalator extends Widget
private boolean initialColumnSizesCalculated = false;
- public AbstractRowContainer(
- final TableSectionElement rowContainerElement) {
+ public AbstractRowContainer(final TableSectionElement rowContainerElement) {
root = rowContainerElement;
}
@@ -1216,6 +1282,7 @@ public class Escalator extends Widget
assertArgumentsAreValidAndWithinRange(index, numberOfRows);
rows -= numberOfRows;
+ ariaGridHelper.removeRows(numberOfRows);
if (!isAttached()) {
return;
@@ -1340,6 +1407,7 @@ public class Escalator extends Widget
}
rows += numberOfRows;
+ ariaGridHelper.addRows(numberOfRows);
/*
* only add items in the DOM if the widget itself is attached to the
* DOM. We can't calculate sizes otherwise.
@@ -2168,8 +2236,7 @@ public class Escalator extends Widget
/** The height of the combined rows in the DOM. Never negative. */
private double heightOfSection = 0;
- public AbstractStaticRowContainer(
- final TableSectionElement headElement) {
+ public AbstractStaticRowContainer(final TableSectionElement headElement) {
super(headElement);
}
@@ -5594,9 +5661,10 @@ public class Escalator extends Widget
private final VerticalScrollbarBundle verticalScrollbar = new VerticalScrollbarBundle();
private final HorizontalScrollbarBundle horizontalScrollbar = new HorizontalScrollbarBundle();
+ private final AriaGridHelper ariaGridHelper = new AriaGridHelper();
+
private final HeaderRowContainer header = new HeaderRowContainer(headElem);
- private final BodyRowContainerImpl body = new BodyRowContainerImpl(
- bodyElem);
+ private final BodyRowContainerImpl body = new BodyRowContainerImpl(bodyElem);
private final FooterRowContainer footer = new FooterRowContainer(footElem);
/**
@@ -5608,6 +5676,7 @@ public class Escalator extends Widget
private final ColumnConfigurationImpl columnConfiguration = new ColumnConfigurationImpl();
private final DivElement tableWrapper;
+ private final Element table;
private final DivElement horizontalScrollbarDeco = DivElement
.as(DOM.createDiv());
@@ -5662,7 +5731,7 @@ public class Escalator extends Widget
root.appendChild(tableWrapper);
- final Element table = DOM.createTable();
+ table = DOM.createTable();
tableWrapper.appendChild(table);
table.appendChild(headElem);
@@ -6799,7 +6868,7 @@ public class Escalator extends Widget
* @since 8.2
*/
public Element getTable() {
- return getTableWrapper().getFirstChildElement();
+ return table;
}
private Element getSubPartElementTableStructure(SubPartArguments args) {