Also adds aria-selected for grid rows.
<li>Error indicators are now <tt><span class="v-errorindicator"></span></tt> elements.</li>
<li><tt>Embedded</tt> is not a <tt>LegacyComponent</tt> anymore.</li>
<li><tt>Notification</tt> method <tt>show</tt> returns <tt>Notification</tt>, instead of <tt>void</tt>.</li>
+ <li>The client side <tt>SelectionModel</tt> interface has a new method <tt>isMultiSelectionAllowed</tt>.</li>
<h2>For incompatible or behavior-altering changes in 8.1, please see <a href="https://vaadin.com/download/release/8.1/8.1.0/release-notes.html#incompatible">8.1 release notes</a></h2>
return isSelectionAllowed;
}
+ @Override
+ public boolean isMultiSelectionAllowed() {
+ return true;
+ }
}
@Override
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.
public boolean isSelectionAllowed() {
return false;
}
+
+ @Override
+ public boolean isMultiSelectionAllowed() {
+ return false;
+ }
}
/**
*/
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.
*/
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.
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();
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
cellFocusHandler = new CellFocusHandler();
setStylePrimaryName(STYLE_NAME);
+ setAriaRole("grid");
escalator.getHeader().setEscalatorUpdater(createHeaderUpdater());
escalator.getBody().setEscalatorUpdater(createBodyUpdater());
}
}
+ /**
+ * 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
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();
}
--- /dev/null
+/*
+ * Copyright 2000-2016 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;
+import com.vaadin.ui.Grid.SelectionMode;
+
+/**
+ * @author Vaadin Ltd
+ *
+ */
+public class GridAriaMultiselectable extends AbstractTestUI {
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ Grid<String> grid = new Grid<>();
+ grid.addColumn(ValueProvider.identity());
+ grid.setItems("a", "b");
+ grid.setSelectionMode(SelectionMode.NONE);
+
+ addComponent(grid);
+
+ Button singleSelectBtn = new Button("SingleSelect", event -> {
+ grid.setSelectionMode(SelectionMode.SINGLE);
+ });
+ addComponent(singleSelectBtn);
+
+ Button multiSelectBtn = new Button("MultiSelect", event -> {
+ grid.setSelectionMode(SelectionMode.MULTI);
+ });
+ addComponent(multiSelectBtn);
+ }
+}
--- /dev/null
+/*
+ * Copyright 2000-2016 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.testbench.elements.ButtonElement;
+import com.vaadin.testbench.elements.GridElement;
+import com.vaadin.tests.tb3.SingleBrowserTest;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * @author Vaadin Ltd
+ */
+public class GridAriaMultiselectableTest extends SingleBrowserTest {
+
+ @Test
+ public void checkAriaMultiselectable() {
+ openTestURL();
+
+ GridElement grid = $(GridElement.class).first();
+
+ Assert.assertTrue("Grid should have the role 'grid'",
+ grid.getHTML().contains("role=\"grid\""));
+ Assert.assertFalse("Grid should not have aria-multiselectable",
+ grid.getHTML().contains("aria-multiselectable"));
+
+ $(ButtonElement.class).caption("SingleSelect").first().click();
+
+ Assert.assertTrue("Grid should have aria-multiselectable 'false'",
+ grid.getHTML().contains("aria-multiselectable=\"false\""));
+
+ $(ButtonElement.class).caption("MultiSelect").first().click();
+
+ Assert.assertTrue("Grid should have aria-multiselectable 'true'",
+ grid.getHTML().contains("aria-multiselectable=\"true\""));
+ }
+}