aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKnoobie <Knoobie@gmx.de>2017-09-18 09:47:46 +0200
committerHenri Sara <henri.sara@gmail.com>2017-09-18 10:47:46 +0300
commit4c2963ac4e0f5b2a9a59bd7791f7ea563acae6eb (patch)
treeaf79df6c304301b17bb568e1ba988fe5415bd780
parent4e720f6b2b48d99b6abe615fa26f399c47122e17 (diff)
downloadvaadin-framework-4c2963ac4e0f5b2a9a59bd7791f7ea563acae6eb.tar.gz
vaadin-framework-4c2963ac4e0f5b2a9a59bd7791f7ea563acae6eb.zip
Add aria-sort to Grid (#10007)
This adds basic support for aria-sort for Grid (https://www.w3.org/TR/wai-aria-1.1/#aria-sort). - aria-sort is not added, if the column is not sortable - aria-sort="none" is added, if the column is sortable but currently not sorted - aria-sort="ascending" is added, if the column is sorted by asc - aria-sort="descending" is added, if the column is sorted by desc - aria-sort="other" is added, if more than 1 column is sorted, currently there is no aria-sort-order
-rwxr-xr-xclient/src/main/java/com/vaadin/client/widgets/Grid.java8
-rw-r--r--uitest/src/test/java/com/vaadin/tests/components/grid/GridSortIndicatorTest.java8
2 files changed, 14 insertions, 2 deletions
diff --git a/client/src/main/java/com/vaadin/client/widgets/Grid.java b/client/src/main/java/com/vaadin/client/widgets/Grid.java
index 92765eec89..578f260a1e 100755
--- a/client/src/main/java/com/vaadin/client/widgets/Grid.java
+++ b/client/src/main/java/com/vaadin/client/widgets/Grid.java
@@ -5998,6 +5998,7 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
if (sortable) {
cellElement.addClassName("sortable");
+ cellElement.setAttribute("aria-sort", "none");
}
if (!sortable || sortingOrder == null) {
@@ -6007,16 +6008,18 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
if (SortDirection.ASCENDING == sortingOrder.getDirection()) {
cellElement.addClassName("sort-asc");
+ cellElement.setAttribute("aria-sort", "ascending");
} else {
cellElement.addClassName("sort-desc");
+ cellElement.setAttribute("aria-sort", "descending");
}
int sortIndex = Grid.this.getSortOrder().indexOf(sortingOrder);
if (sortIndex > -1 && Grid.this.getSortOrder().size() > 1) {
// Show sort order indicator if column is
// sorted and other sorted columns also exists.
- cellElement.setAttribute("sort-order",
- String.valueOf(sortIndex + 1));
+ cellElement.setAttribute("sort-order", String.valueOf(sortIndex + 1));
+ cellElement.setAttribute("aria-sort", "other");
}
if (!sortedBefore) {
@@ -6058,6 +6061,7 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
private void cleanup(FlyweightCell cell) {
Element cellElement = cell.getElement();
cellElement.removeAttribute("sort-order");
+ cellElement.removeAttribute("aria-sort");
cellElement.removeClassName("sort-desc");
cellElement.removeClassName("sort-asc");
cellElement.removeClassName("sortable");
diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridSortIndicatorTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridSortIndicatorTest.java
index 429e5a671e..2f623e1c51 100644
--- a/uitest/src/test/java/com/vaadin/tests/components/grid/GridSortIndicatorTest.java
+++ b/uitest/src/test/java/com/vaadin/tests/components/grid/GridSortIndicatorTest.java
@@ -35,18 +35,26 @@ public class GridSortIndicatorTest extends SingleBrowserTest {
Assert.assertTrue("First column should be sorted ascending",
grid.getHeaderCell(0, 0).getAttribute("class")
.contains("sort-asc"));
+ Assert.assertEquals("First column should have aria-sort other", "other",
+ grid.getHeaderCell(0, 0).getAttribute("aria-sort"));
Assert.assertEquals("First column should be first in sort order", "1",
grid.getHeaderCell(0, 0).getAttribute("sort-order"));
Assert.assertTrue("Second column should be sorted ascending",
grid.getHeaderCell(0, 1).getAttribute("class")
.contains("sort-asc"));
+ Assert.assertEquals("Second column should have aria-sort other", "other",
+ grid.getHeaderCell(0, 1).getAttribute("aria-sort"));
Assert.assertEquals("Second column should be also sorted", "2",
grid.getHeaderCell(0, 1).getAttribute("sort-order"));
$(ButtonElement.class).caption("Sort first").first().click();
+ Assert.assertEquals("First column should have aria-sort ascending", "ascending",
+ grid.getHeaderCell(0, 0).getAttribute("aria-sort"));
Assert.assertTrue("First column should be sorted ascending",
grid.getHeaderCell(0, 0).getAttribute("class")
.contains("sort-asc"));
+ Assert.assertEquals("Second column should have aria-sort none", "none",
+ grid.getHeaderCell(0, 1).getAttribute("aria-sort"));
Assert.assertFalse("Second column should not be sorted",
grid.getHeaderCell(0, 1).getAttribute("class")
.contains("sort-asc"));