Skip to content

Commit

Permalink
feat: add setAutofocus and isAutofocus API to Popover (#6498)
Browse files Browse the repository at this point in the history
  • Loading branch information
web-padawan authored Aug 2, 2024
1 parent db10dda commit 84ea286
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,28 @@ public Optional<String> getAriaLabelledBy() {
.ofNullable(getElement().getProperty("accessibleNameRef"));
}

/**
* Set {@code true} to make the popover content automatically receive focus
* after it is opened. Modal popovers use this behavior by default.
*
* @param autofocus
* the boolean value to set
*/
public void setAutofocus(boolean autofocus) {
getElement().setProperty("autofocus", autofocus);
}

/**
* Get if the popover content automatically receives focus after it is
* opened. Modal popovers use this behavior by default.
*
* @return {@code true} if the popover content receives focus when opened,
* {@code false} otherwise
*/
public boolean isAutofocus() {
return getElement().getProperty("autofocus", false);
}

/**
* Sets the ARIA role for the overlay element, used by screen readers.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,4 +264,15 @@ public void setBackdropVisible_isBackdropVisible() {
Assert.assertTrue(
popover.getElement().getProperty("withBackdrop", false));
}

@Test
public void setAutofocus_isAutofocus() {
Assert.assertFalse(popover.isAutofocus());
Assert.assertFalse(
popover.getElement().getProperty("autofocus", false));

popover.setAutofocus(true);
Assert.assertTrue(popover.isAutofocus());
Assert.assertTrue(popover.getElement().getProperty("autofocus", false));
}
}

0 comments on commit 84ea286

Please sign in to comment.