pub struct Modal { /* private fields */ }Expand description
A dialog over the page: a <dialog> element.
Open it with Press::open_modal on any
pressable component, or with the open property to show it right away.
Its close button and Escape work without any script; the component
script adds opening as a true modal (focus kept inside, the page inert)
and closing on a click outside.
let m = Modal![id = "confirm", title = "Delete the class?",
ModalBody![p!["This cannot be undone."]],
ModalFooter![Button![on_press = Press::close_modal(), "Cancel"]],
];
let html = render_static(m);
assert!(html.contains(r#"<dialog class="nr-modal nr-modal-md nr-modal-center" id="confirm""#), "{html}");
assert!(html.contains(r#"<form method="dialog""#), "closes without a script");Implementations§
Source§impl Modal
impl Modal
pub fn new() -> Self
Sourcepub fn class(self, v: impl Into<String>) -> Self
pub fn class(self, v: impl Into<String>) -> Self
Extra classes for the outer element. They win over the defaults.
Sourcepub fn with(self, part: impl Part) -> Self
pub fn with(self, part: impl Part) -> Self
Add an attribute (class(..), id(..), aria(..), …) or a child.
Sourcepub fn id(self, v: impl Into<String>) -> Self
pub fn id(self, v: impl Into<String>) -> Self
The id Press::open_modal refers to.
Sourcepub fn title(self, v: impl Into<String>) -> Self
pub fn title(self, v: impl Into<String>) -> Self
A heading at the top (also the dialog’s accessible name).
pub fn placement(self, v: ModalPlacement) -> Self
pub fn radius(self, v: Radius) -> Self
Sourcepub fn open(self, v: bool) -> Self
pub fn open(self, v: bool) -> Self
Shown when the page loads (as a modal once the script runs).
Sourcepub fn dismissable(self, v: bool) -> Self
pub fn dismissable(self, v: bool) -> Self
A click on the backdrop closes it (on by default). Escape always does.
Sourcepub fn scroll_inside(self, v: bool) -> Self
pub fn scroll_inside(self, v: bool) -> Self
Long content scrolls inside the body, the header and footer stay put.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Modal
impl !Sync for Modal
impl !UnwindSafe for Modal
impl Forget for Modal
impl Freeze for Modal
impl Move for Modal
impl Send for Modal
impl Unpin for Modal
impl UnsafeUnpin for Modal
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more