Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add method to customize Dialog overlay ARIA role #6473

Merged
merged 7 commits into from
Jul 30, 2024
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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if this should be an enum on the flow side with both possible values (dialog / alertdialog) to ensure the typical type safety on java side.. those values don't change often and people could theoretically always use the element API if a new value comes out of the blue and you could not update in time.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Maybe we could add an override for this method to Dialog and also Popover.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That you have to decide :) While in alpha.. I would just ditch the old methods completely before you have to maintain them for decades

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are about to release beta so I'm afraid for now we'd have to leave these methods as they are.
Created #6645 so that we don't forget about this idea, and maybe consider it for the next minor.

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