Skip to content

Commit

Permalink
feat: add setModal override to allow setting backdrop visibility (#6559)
Browse files Browse the repository at this point in the history
Co-authored-by: Sascha Ißbrücker <[email protected]>
  • Loading branch information
web-padawan and sissbruecker authored Aug 20, 2024
1 parent 0f09065 commit 6fbed43
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ public Registration addOpenedChangeListener(
* popover is modal, interacting with elements behind it will be prevented
* until the popover is closed.
* <p>
* Setting the modal to {@code true} does not enable showing the backdrop
* (modality curtain) automatically. This should be done separately using
* {@link #setBackdropVisible(boolean)} or optionally passed as a second
* parameter using {@link #setModal(boolean, boolean)}.
* <p>
* NOTE: this setting does not involve server-side modality, as the modal
* popover is typically not used to prevent anything else from happening
* while it's open.
Expand All @@ -175,11 +180,35 @@ public Registration addOpenedChangeListener(
* @param modal
* {@code true} to enable popover to open as modal, {@code false}
* otherwise.
* @see #setBackdropVisible(boolean)
* @see #setModal(boolean, boolean)
*/
public void setModal(boolean modal) {
getElement().setProperty("modal", modal);
}

/**
* Sets whether component should open modal or modeless popover and whether
* the component should show a backdrop (modality curtain) when opened.
* <p>
* NOTE: this setting does not involve server-side modality, as the modal
* popover is typically not used to prevent anything else from happening
* while it's open.
* <p>
* By default, the popover is non-modal and has no modality curtain.
*
* @param modal
* {@code true} to enable popover to open as modal, {@code false}
* otherwise.
* @param backdropVisible
* {@code true} to show the backdrop, {@code false} otherwise.
* @see #setBackdropVisible(boolean)
*/
public void setModal(boolean modal, boolean backdropVisible) {
setModal(modal);
setBackdropVisible(backdropVisible);
}

/**
* Gets whether component is set as modal or modeless popover. By default,
* the popover is non-modal.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,17 @@ public void setBackdropVisible_isBackdropVisible() {
popover.getElement().getProperty("withBackdrop", false));
}

@Test
public void setModalAndBackdropVisible() {
popover.setModal(true, true);
Assert.assertTrue(popover.isModal());
Assert.assertTrue(popover.isBackdropVisible());

popover.setModal(false, false);
Assert.assertFalse(popover.isModal());
Assert.assertFalse(popover.isBackdropVisible());
}

@Test
public void setAutofocus_isAutofocus() {
Assert.assertFalse(popover.isAutofocus());
Expand Down

0 comments on commit 6fbed43

Please sign in to comment.