Skip to content

Commit

Permalink
feat: add method to customize Dialog overlay ARIA role (#6473)
Browse files Browse the repository at this point in the history
  • Loading branch information
web-padawan authored Jul 30, 2024
1 parent 2834347 commit 53797bf
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ public Dialog() {
width = event.getWidth();
height = event.getHeight();
});

setOverlayRole("dialog");
}

/**
Expand Down Expand Up @@ -968,6 +970,28 @@ protected void onAttach(AttachEvent attachEvent) {
registerClientCloseHandler();
}

/**
* Sets the ARIA role for the overlay element, used by screen readers.
*
* @param role
* the role to set
*/
public void setOverlayRole(String role) {
Objects.requireNonNull(role, "Role cannot be null");

getElement().setProperty("overlayRole", role);
}

/**
* Gets the ARIA role for the overlay element, used by screen readers.
* Defaults to {@code dialog}.
*
* @return the role
*/
public String getOverlayRole() {
return getElement().getProperty("overlayRole");
}

/**
* Set the {@code aria-label} attribute for assistive technologies like
* screen readers. An {@code undefined} value for this property (the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,31 @@ public void isModal_trueByDefault() {
!dialog.getElement().getProperty("modeless", false));
}

@Test
public void getOverlayRole_defaultDialog() {
Dialog dialog = new Dialog();

Assert.assertEquals("dialog", dialog.getOverlayRole());
Assert.assertEquals("dialog",
dialog.getElement().getProperty("overlayRole"));
}

@Test
public void setOverlayRole_getOverlayRole() {
Dialog dialog = new Dialog();
dialog.setOverlayRole("alertdialog");

Assert.assertEquals("alertdialog", dialog.getOverlayRole());
Assert.assertEquals("alertdialog",
dialog.getElement().getProperty("overlayRole"));
}

@Test(expected = NullPointerException.class)
public void setOverlayRole_null_throws() {
Dialog dialog = new Dialog();
dialog.setOverlayRole(null);
}

@Test
public void setModal_dialogCanBeModeless() {
Dialog dialog = new Dialog();
Expand Down

0 comments on commit 53797bf

Please sign in to comment.