diff options
author | Olli Tietäväinen <ollit@vaadin.com> | 2018-01-09 15:36:55 +0200 |
---|---|---|
committer | Teemu Suo-Anttila <tsuoanttila@users.noreply.github.com> | 2018-01-15 11:43:19 +0200 |
commit | 911b2ed5e93bc53d17929a4b6ed9efa8db21631a (patch) | |
tree | 9bafba63080a1fad5486132c436fcdc5bcce8c9a | |
parent | 9e54760b68b7682566a41827b3e2ef235da895ab (diff) | |
download | vaadin-framework-911b2ed5e93bc53d17929a4b6ed9efa8db21631a.tar.gz vaadin-framework-911b2ed5e93bc53d17929a4b6ed9efa8db21631a.zip |
Add aria-modal attribute and role='dialog' for modal Window (#10447)
Fixes #10424
-rw-r--r-- | client/src/main/java/com/vaadin/client/ui/VWindow.java | 8 | ||||
-rw-r--r-- | uitest/src/test/java/com/vaadin/tests/components/window/ModalWindowFocusTest.java | 16 |
2 files changed, 22 insertions, 2 deletions
diff --git a/client/src/main/java/com/vaadin/client/ui/VWindow.java b/client/src/main/java/com/vaadin/client/ui/VWindow.java index 02d3ce63cd..a07a08ef99 100644 --- a/client/src/main/java/com/vaadin/client/ui/VWindow.java +++ b/client/src/main/java/com/vaadin/client/ui/VWindow.java @@ -444,7 +444,7 @@ public class VWindow extends VOverlay implements ShortcutActionHandlerOwner, && nativeEvent.getKeyCode() == KeyCodes.KEY_TAB && nativeEvent.getShiftKey()) { nativeEvent.preventDefault(); - FocusUtil.focusOnLastFocusableElement(this.getElement()); + FocusUtil.focusOnLastFocusableElement(getElement()); } if (nativeEvent.getEventTarget().cast() == topTabStop && nativeEvent.getKeyCode() == KeyCodes.KEY_BACKSPACE) { @@ -461,7 +461,7 @@ public class VWindow extends VOverlay implements ShortcutActionHandlerOwner, && nativeEvent.getKeyCode() == KeyCodes.KEY_TAB && !nativeEvent.getShiftKey()) { nativeEvent.preventDefault(); - FocusUtil.focusOnFirstFocusableElement(this.getElement()); + FocusUtil.focusOnFirstFocusableElement(getElement()); } if (nativeEvent.getEventTarget().cast() == bottomTabStop && nativeEvent.getKeyCode() == KeyCodes.KEY_BACKSPACE) { @@ -706,12 +706,16 @@ public class VWindow extends VOverlay implements ShortcutActionHandlerOwner, public void setVaadinModality(boolean modality) { vaadinModality = modality; if (vaadinModality) { + getElement().setAttribute("aria-modal", "true"); + Roles.getDialogRole().set(getElement()); if (isAttached()) { showModalityCurtain(); } addTabBlockHandlers(); deferOrdering(); } else { + getElement().removeAttribute("aria-modal"); + Roles.getDialogRole().remove(getElement()); if (modalityCurtain != null) { if (isAttached()) { hideModalityCurtain(); diff --git a/uitest/src/test/java/com/vaadin/tests/components/window/ModalWindowFocusTest.java b/uitest/src/test/java/com/vaadin/tests/components/window/ModalWindowFocusTest.java index b01a9ded14..8cbb9d6ae9 100644 --- a/uitest/src/test/java/com/vaadin/tests/components/window/ModalWindowFocusTest.java +++ b/uitest/src/test/java/com/vaadin/tests/components/window/ModalWindowFocusTest.java @@ -15,6 +15,7 @@ */ package com.vaadin.tests.components.window; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import java.io.IOException; @@ -91,6 +92,21 @@ public class ModalWindowFocusTest extends MultiBrowserTest { } + @Test + public void verifyAriaModalAndRoleAttributes() { + waitForElementPresent(By.id("firstButton")); + WebElement button = findElement(By.id("firstButton")); + button.click(); + + waitForElementPresent(By.className("v-window")); + WebElement windowElement = findElement(By.className("v-window")); + String ariaModal = windowElement.getAttribute("aria-modal"); + assertEquals("true", ariaModal); + String role = windowElement.getAttribute("role"); + assertEquals("dialog", role); + + } + private void pressEscAndWait() { new Actions(driver).sendKeys(Keys.ESCAPE).build().perform(); sleep(100); |