aboutsummaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorKnoobie <Knoobie@gmx.de>2017-10-04 07:51:31 +0200
committerHenri Sara <henri.sara@gmail.com>2017-10-04 08:51:31 +0300
commit80336d30ed12d53f24c01de5c4b6274ccc094b3b (patch)
treedd3994504c85feade1810478faa372f5229ffefc /client
parentbf690d31eb986ef1803324ff2bd628104a7cb0fe (diff)
downloadvaadin-framework-80336d30ed12d53f24c01de5c4b6274ccc094b3b.tar.gz
vaadin-framework-80336d30ed12d53f24c01de5c4b6274ccc094b3b.zip
Add role="grid" and aria-multiselectable to grid (#10009)
Also adds aria-selected for grid rows.
Diffstat (limited to 'client')
-rw-r--r--client/src/main/java/com/vaadin/client/connectors/grid/MultiSelectionModelConnector.java4
-rw-r--r--client/src/main/java/com/vaadin/client/connectors/grid/SingleSelectionModelConnector.java5
-rw-r--r--client/src/main/java/com/vaadin/client/widget/grid/selection/SelectionModel.java15
-rw-r--r--client/src/main/java/com/vaadin/client/widget/treegrid/TreeGrid.java7
-rw-r--r--client/src/main/java/com/vaadin/client/widgets/Escalator.java10
-rwxr-xr-xclient/src/main/java/com/vaadin/client/widgets/Grid.java30
6 files changed, 68 insertions, 3 deletions
diff --git a/client/src/main/java/com/vaadin/client/connectors/grid/MultiSelectionModelConnector.java b/client/src/main/java/com/vaadin/client/connectors/grid/MultiSelectionModelConnector.java
index 92b858cb97..79a3cac92b 100644
--- a/client/src/main/java/com/vaadin/client/connectors/grid/MultiSelectionModelConnector.java
+++ b/client/src/main/java/com/vaadin/client/connectors/grid/MultiSelectionModelConnector.java
@@ -121,6 +121,10 @@ public class MultiSelectionModelConnector
return isSelectionAllowed;
}
+ @Override
+ public boolean isMultiSelectionAllowed() {
+ return true;
+ }
}
@Override
diff --git a/client/src/main/java/com/vaadin/client/connectors/grid/SingleSelectionModelConnector.java b/client/src/main/java/com/vaadin/client/connectors/grid/SingleSelectionModelConnector.java
index 560ccb2d85..2320edc8e0 100644
--- a/client/src/main/java/com/vaadin/client/connectors/grid/SingleSelectionModelConnector.java
+++ b/client/src/main/java/com/vaadin/client/connectors/grid/SingleSelectionModelConnector.java
@@ -82,6 +82,11 @@ public class SingleSelectionModelConnector
return isSelectionAllowed;
}
+ @Override
+ public boolean isMultiSelectionAllowed() {
+ return false;
+ }
+
/**
* Sets whether it's allowed to deselect the selected row through the
* UI. Deselection is allowed by default.
diff --git a/client/src/main/java/com/vaadin/client/widget/grid/selection/SelectionModel.java b/client/src/main/java/com/vaadin/client/widget/grid/selection/SelectionModel.java
index 17763b0a94..513ee4949a 100644
--- a/client/src/main/java/com/vaadin/client/widget/grid/selection/SelectionModel.java
+++ b/client/src/main/java/com/vaadin/client/widget/grid/selection/SelectionModel.java
@@ -58,6 +58,11 @@ public interface SelectionModel<T> {
public boolean isSelectionAllowed() {
return false;
}
+
+ @Override
+ public boolean isMultiSelectionAllowed() {
+ return false;
+ }
}
/**
@@ -116,6 +121,16 @@ public interface SelectionModel<T> {
boolean isSelectionAllowed();
/**
+ * Checks if the user is allowed to have more than on item selected.
+ * <p>
+ *
+ * @return <code>true</code> if the user is allowed to select multiple items,
+ * <code>false</code> otherwise
+ * @since 8.2
+ */
+ boolean isMultiSelectionAllowed();
+
+ /**
* Gets the selected state from a given grid row json object. This is a
* helper method for grid selection models.
*
diff --git a/client/src/main/java/com/vaadin/client/widget/treegrid/TreeGrid.java b/client/src/main/java/com/vaadin/client/widget/treegrid/TreeGrid.java
index 016c701deb..cf9d7ea833 100644
--- a/client/src/main/java/com/vaadin/client/widget/treegrid/TreeGrid.java
+++ b/client/src/main/java/com/vaadin/client/widget/treegrid/TreeGrid.java
@@ -45,6 +45,13 @@ public class TreeGrid extends Grid<JsonObject> {
private String depthStyleNamePrefix;
/**
+ * Creates a new instance.
+ */
+ public TreeGrid() {
+ setAriaRole("treegrid");
+ }
+
+ /**
* Body updater that adds additional style to each row containing depth
* information inside the hierarchy.
*/
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 a46450fe07..640304e828 100644
--- a/client/src/main/java/com/vaadin/client/widgets/Escalator.java
+++ b/client/src/main/java/com/vaadin/client/widgets/Escalator.java
@@ -6792,6 +6792,16 @@ public class Escalator extends Widget
return tableWrapper;
}
+ /**
+ * Returns the {@code <table />} element of the grid.
+ *
+ * @return the table element
+ * @since 8.2
+ */
+ public Element getTable() {
+ return getTableWrapper().getFirstChildElement();
+ }
+
private Element getSubPartElementTableStructure(SubPartArguments args) {
String type = args.getType();
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 e4ceac93f8..81f6756930 100755
--- a/client/src/main/java/com/vaadin/client/widgets/Grid.java
+++ b/client/src/main/java/com/vaadin/client/widgets/Grid.java
@@ -5597,10 +5597,15 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
rowReference.set(rowIndex, rowData, rowElement);
- if (hasData) {
- setStyleName(rowElement, rowSelectedStyleName,
- isSelected(rowData));
+ boolean isSelected = hasData && isSelected(rowData);
+ if (Grid.this.selectionModel.isSelectionAllowed()) {
+ rowElement.setAttribute("aria-selected", String.valueOf(isSelected));
+ } else {
+ rowElement.removeAttribute("aria-selected");
+ }
+ if (hasData) {
+ setStyleName(rowElement, rowSelectedStyleName, isSelected);
if (rowStyleGenerator != null) {
try {
String rowStylename = rowStyleGenerator
@@ -6148,6 +6153,7 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
cellFocusHandler = new CellFocusHandler();
setStylePrimaryName(STYLE_NAME);
+ setAriaRole("grid");
escalator.getHeader().setEscalatorUpdater(createHeaderUpdater());
escalator.getBody().setEscalatorUpdater(createBodyUpdater());
@@ -6309,6 +6315,17 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
}
/**
+ * Adds the given role as 'role="$param"' to the {@code <table />} element
+ * of the grid.
+ *
+ * @param role the role param
+ * @since 8.2
+ */
+ protected void setAriaRole(String role){
+ escalator.getTable().setAttribute("role", role);
+ }
+
+ /**
* Creates the escalator updater used to update the header rows in this
* grid. The updater is invoked when header rows or columns are added or
* removed, or the content of existing header cells is changed.
@@ -7971,6 +7988,13 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
setSelectColumnRenderer(null);
}
+ if (this.selectionModel.isMultiSelectionAllowed()) {
+ escalator.getTable().setAttribute("aria-multiselectable", "true");
+ } else if (this.selectionModel.isSelectionAllowed()) {
+ escalator.getTable().setAttribute("aria-multiselectable", "false");
+ } else {
+ escalator.getTable().removeAttribute("aria-multiselectable");
+ }
// Refresh rendered rows to update selection, if it has changed
requestRefreshBody();
}