Browse Source

Add aria-modal attribute and role='dialog' for modal Window (#10447)

Fixes #10424
tags/8.4.0.alpha1
Olli Tietäväinen 6 years ago
parent
commit
4a58876ee5

+ 6
- 2
client/src/main/java/com/vaadin/client/ui/VWindow.java View File

&& nativeEvent.getKeyCode() == KeyCodes.KEY_TAB && nativeEvent.getKeyCode() == KeyCodes.KEY_TAB
&& nativeEvent.getShiftKey()) { && nativeEvent.getShiftKey()) {
nativeEvent.preventDefault(); nativeEvent.preventDefault();
FocusUtil.focusOnLastFocusableElement(this.getElement());
FocusUtil.focusOnLastFocusableElement(getElement());
} }
if (nativeEvent.getEventTarget().cast() == topTabStop if (nativeEvent.getEventTarget().cast() == topTabStop
&& nativeEvent.getKeyCode() == KeyCodes.KEY_BACKSPACE) { && nativeEvent.getKeyCode() == KeyCodes.KEY_BACKSPACE) {
&& nativeEvent.getKeyCode() == KeyCodes.KEY_TAB && nativeEvent.getKeyCode() == KeyCodes.KEY_TAB
&& !nativeEvent.getShiftKey()) { && !nativeEvent.getShiftKey()) {
nativeEvent.preventDefault(); nativeEvent.preventDefault();
FocusUtil.focusOnFirstFocusableElement(this.getElement());
FocusUtil.focusOnFirstFocusableElement(getElement());
} }
if (nativeEvent.getEventTarget().cast() == bottomTabStop if (nativeEvent.getEventTarget().cast() == bottomTabStop
&& nativeEvent.getKeyCode() == KeyCodes.KEY_BACKSPACE) { && nativeEvent.getKeyCode() == KeyCodes.KEY_BACKSPACE) {
public void setVaadinModality(boolean modality) { public void setVaadinModality(boolean modality) {
vaadinModality = modality; vaadinModality = modality;
if (vaadinModality) { if (vaadinModality) {
getElement().setAttribute("aria-modal", "true");
Roles.getDialogRole().set(getElement());
if (isAttached()) { if (isAttached()) {
showModalityCurtain(); showModalityCurtain();
} }
addTabBlockHandlers(); addTabBlockHandlers();
deferOrdering(); deferOrdering();
} else { } else {
getElement().removeAttribute("aria-modal");
Roles.getDialogRole().remove(getElement());
if (modalityCurtain != null) { if (modalityCurtain != null) {
if (isAttached()) { if (isAttached()) {
hideModalityCurtain(); hideModalityCurtain();

+ 16
- 0
uitest/src/test/java/com/vaadin/tests/components/window/ModalWindowFocusTest.java View File

*/ */
package com.vaadin.tests.components.window; package com.vaadin.tests.components.window;


import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;


import java.io.IOException; import java.io.IOException;


} }


@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() { private void pressEscAndWait() {
new Actions(driver).sendKeys(Keys.ESCAPE).build().perform(); new Actions(driver).sendKeys(Keys.ESCAPE).build().perform();
sleep(100); sleep(100);

Loading…
Cancel
Save