summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKnoobie <Knoobie@gmx.de>2017-10-30 09:00:21 +0100
committerPéter Török <31210544+torok-peter@users.noreply.github.com>2017-10-30 10:00:21 +0200
commite65efdfb50bc10bedf506d475f582276f6be0e2f (patch)
tree73c6ef9f6ad9658ea2ff564024f8426433c69b06
parentfb6e81221bd1b5ab0b81a3ee6c82e4286df57264 (diff)
downloadvaadin-framework-e65efdfb50bc10bedf506d475f582276f6be0e2f.tar.gz
vaadin-framework-e65efdfb50bc10bedf506d475f582276f6be0e2f.zip
add Grid.Column#get/setAssistiveCaption (#10219)
* add Grid#Column#get/setAssistiveCaption * fix test and update doc * move testGridAssistiveCaption to GridTest * delete test file * delete test file * Delete GridAssistiveCaptionTest.java * Create GridAssistiveCaptionTest * Create GridAssistiveCaption * Rename GridAssistiveCaption to GridAssistiveCaption.java * Rename GridAssistiveCaptionTest to GridAssistiveCaptionTest.java * Reformat using eclipse
-rw-r--r--client/src/main/java/com/vaadin/client/connectors/grid/ColumnConnector.java5
-rwxr-xr-xclient/src/main/java/com/vaadin/client/widgets/Grid.java50
-rw-r--r--server/src/main/java/com/vaadin/ui/Grid.java34
-rw-r--r--server/src/test/java/com/vaadin/tests/server/component/grid/GridTest.java7
-rw-r--r--shared/src/main/java/com/vaadin/shared/ui/grid/ColumnState.java3
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/grid/GridAssistiveCaption.java40
-rw-r--r--uitest/src/test/java/com/vaadin/tests/components/grid/GridAssistiveCaptionTest.java49
7 files changed, 186 insertions, 2 deletions
diff --git a/client/src/main/java/com/vaadin/client/connectors/grid/ColumnConnector.java b/client/src/main/java/com/vaadin/client/connectors/grid/ColumnConnector.java
index b9d14dc91c..e46a01c1ae 100644
--- a/client/src/main/java/com/vaadin/client/connectors/grid/ColumnConnector.java
+++ b/client/src/main/java/com/vaadin/client/connectors/grid/ColumnConnector.java
@@ -98,6 +98,11 @@ public class ColumnConnector extends AbstractExtensionConnector {
column.setHeaderCaption(getState().caption);
}
+ @OnStateChange("assistiveCaption")
+ void updateAssistiveCaption() {
+ column.setAssistiveCaption(getState().assistiveCaption);
+ }
+
@OnStateChange("sortable")
void updateSortable() {
column.setSortable(getState().sortable);
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 11604db9b8..34b58d569f 100755
--- a/client/src/main/java/com/vaadin/client/widgets/Grid.java
+++ b/client/src/main/java/com/vaadin/client/widgets/Grid.java
@@ -26,6 +26,7 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.TreeMap;
@@ -4722,6 +4723,8 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
private String headerCaption = "";
+ private String assistiveCaption = null;
+
private String hidingToggleCaption = null;
private double minimumWidthPx = GridConstants.DEFAULT_MIN_WIDTH;
@@ -4836,6 +4839,36 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
return headerCaption;
}
+ /**
+ * Sets the header aria-label for this column.
+ *
+ * @param caption
+ * The header aria-label for this column
+ * @return the column itself
+ *
+ * @since
+ */
+ public Column<C, T> setAssistiveCaption(String caption) {
+ if (!Objects.equals(this.assistiveCaption, caption)) {
+ this.assistiveCaption = caption;
+ if (grid != null) {
+ grid.getHeader().requestSectionRefresh();
+ }
+ }
+
+ return this;
+ }
+ /**
+ * Returns the current header aria-label for this column.
+ *
+ * @return the header aria-label string
+ *
+ * @since
+ */
+ public String getAssistiveCaption() {
+ return assistiveCaption;
+ }
+
private void updateHeader() {
HeaderRow row = grid.getHeader().getDefaultRow();
if (row != null) {
@@ -5730,6 +5763,7 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
// Decorate default row with sorting indicators
if (staticRow instanceof HeaderRow) {
+ addAriaLabelToHeaderRow(cell);
addSortingIndicatorsToHeaderRow((HeaderRow) staticRow,
cell);
}
@@ -5954,8 +5988,20 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
}
}
- private void addSortingIndicatorsToHeaderRow(HeaderRow headerRow,
- FlyweightCell cell) {
+ private void addAriaLabelToHeaderRow(FlyweightCell cell) {
+
+ Element cellElement = cell.getElement();
+
+ final Column<?, T> column = getVisibleColumn(cell.getColumn());
+
+ if (column.getAssistiveCaption() != null) {
+ cellElement.setAttribute("aria-label", column.getAssistiveCaption());
+ } else {
+ cellElement.removeAttribute("aria-label");
+ }
+ }
+
+ private void addSortingIndicatorsToHeaderRow(HeaderRow headerRow, FlyweightCell cell) {
Element cellElement = cell.getElement();
diff --git a/server/src/main/java/com/vaadin/ui/Grid.java b/server/src/main/java/com/vaadin/ui/Grid.java
index 7282afb44c..1e35578b19 100644
--- a/server/src/main/java/com/vaadin/ui/Grid.java
+++ b/server/src/main/java/com/vaadin/ui/Grid.java
@@ -1203,6 +1203,36 @@ public class Grid<T> extends AbstractListing<T> implements HasComponents,
}
/**
+ * Sets the header aria-label for this column.
+ *
+ * @param caption
+ * the header aria-label, null removes
+ * the aria-label from this column
+ *
+ * @return this column
+ *
+ * @since
+ */
+ public Column<T, V> setAssistiveCaption(String caption) {
+ if (Objects.equals(caption, getAssistiveCaption())) {
+ return this;
+ }
+ getState().assistiveCaption = caption;
+ return this;
+ }
+
+ /**
+ * Gets the header caption for this column.
+ *
+ * @return header caption
+ *
+ * @since
+ */
+ public String getAssistiveCaption() {
+ return getState(false).assistiveCaption;
+ }
+
+ /**
* Sets the header caption for this column.
*
* @param caption
@@ -2131,6 +2161,10 @@ public class Grid<T> extends AbstractListing<T> implements HasComponents,
setHidingToggleCaption(DesignAttributeHandler.readAttribute(
"hiding-toggle-caption", attributes, String.class));
}
+ if (design.hasAttr("assistive-caption")) {
+ setAssistiveCaption(DesignAttributeHandler.readAttribute(
+ "assistive-caption", attributes, String.class));
+ }
// Read size info where necessary.
if (design.hasAttr("width")) {
diff --git a/server/src/test/java/com/vaadin/tests/server/component/grid/GridTest.java b/server/src/test/java/com/vaadin/tests/server/component/grid/GridTest.java
index d27c7c5260..8e31e9acc6 100644
--- a/server/src/test/java/com/vaadin/tests/server/component/grid/GridTest.java
+++ b/server/src/test/java/com/vaadin/tests/server/component/grid/GridTest.java
@@ -80,6 +80,13 @@ public class GridTest {
}
@Test
+ public void testGridAssistiveCaption() {
+ assertEquals(null, fooColumn.getAssistiveCaption());
+ fooColumn.setAssistiveCaption("Press Enter to sort.");
+ assertEquals("Press Enter to sort.", fooColumn.getAssistiveCaption());
+ }
+
+ @Test
public void testCreateGridWithDataCommunicator() {
DataCommunicator<String> specificDataCommunicator = new DataCommunicator<>();
diff --git a/shared/src/main/java/com/vaadin/shared/ui/grid/ColumnState.java b/shared/src/main/java/com/vaadin/shared/ui/grid/ColumnState.java
index ae781951c6..82f6b77639 100644
--- a/shared/src/main/java/com/vaadin/shared/ui/grid/ColumnState.java
+++ b/shared/src/main/java/com/vaadin/shared/ui/grid/ColumnState.java
@@ -30,6 +30,9 @@ public class ColumnState extends AbstractGridExtensionState {
public boolean sortable = false;
public boolean editable = false;
+ /** The assistive device caption for the column. */
+ public String assistiveCaption;
+
/** The caption for the column hiding toggle. */
public String hidingToggleCaption;
diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridAssistiveCaption.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridAssistiveCaption.java
new file mode 100644
index 0000000000..83351d82f2
--- /dev/null
+++ b/uitest/src/main/java/com/vaadin/tests/components/grid/GridAssistiveCaption.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2000-2017 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.components.grid;
+
+import com.vaadin.data.ValueProvider;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Grid;
+
+public class GridAssistiveCaption extends AbstractTestUI {
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ Grid<String> grid = new Grid<>();
+ grid.addColumn(ValueProvider.identity());
+ grid.setItems("a", "b");
+ addComponent(grid);
+
+ addComponent(new Button("addAssistiveCaption", event -> {
+ grid.getColumns().get(0).setAssistiveCaption("Press Enter to sort.");
+ }));
+ addComponent(new Button("removeAssistiveCaption", event -> {
+ grid.getColumns().get(0).setAssistiveCaption(null);
+ }));
+ }
+}
diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridAssistiveCaptionTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridAssistiveCaptionTest.java
new file mode 100644
index 0000000000..e15858900a
--- /dev/null
+++ b/uitest/src/test/java/com/vaadin/tests/components/grid/GridAssistiveCaptionTest.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2000-2017 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.components.grid;
+
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+import com.vaadin.testbench.elements.ButtonElement;
+import com.vaadin.testbench.elements.GridElement;
+import com.vaadin.tests.tb3.SingleBrowserTest;
+
+public class GridAssistiveCaptionTest extends SingleBrowserTest {
+
+ @Test
+ public void checkGridAriaLabel() {
+ openTestURL();
+
+ GridElement.GridCellElement headerCell = $(GridElement.class).first()
+ .getHeaderCell(0, 0);
+
+ // default grid has no aria-label
+ assertNull("Column should not contain aria-label",
+ headerCell.getAttribute("aria-label"));
+
+ $(ButtonElement.class).caption("addAssistiveCaption").first().click();
+ assertTrue("Column should contain aria-label", headerCell
+ .getAttribute("aria-label").equals("Press Enter to sort."));
+
+ $(ButtonElement.class).caption("removeAssistiveCaption").first()
+ .click();
+ assertNull("Column should not contain aria-label",
+ headerCell.getAttribute("aria-label"));
+ }
+}