Adds doc comment for disabled button

Makes disabled button behavior consistent in web
This commit is contained in:
Jonas Matser 2020-12-01 11:52:52 +01:00 committed by Héctor Ramón
parent 0e70b11e00
commit dbc1181011
3 changed files with 31 additions and 8 deletions

View file

@ -20,6 +20,14 @@ use dodrio::bumpalo;
/// let button = Button::new(&mut state, Text::new("Press me!"))
/// .on_press(Message::ButtonPressed);
/// ```
///
/// Buttons can be disabled by not having an on_press.
///
/// ```
/// let mut state = button::State::new();
/// let disabled_button = Button::new(&mut state, Text::new("I'm disabled!"));
/// ```
#[allow(missing_debug_implementations)]
pub struct Button<'a, Message> {
content: Element<'a, Message>,
@ -90,6 +98,7 @@ impl<'a, Message> Button<'a, Message> {
}
/// Sets the message that will be produced when the [`Button`] is pressed.
/// If on_press isn't set, button will be disabled.
pub fn on_press(mut self, msg: Message) -> Self {
self.on_press = Some(msg);
self
@ -153,6 +162,8 @@ where
node = node.on("click", move |_root, _vdom, _event| {
event_bus.publish(on_press.clone());
});
} else {
node = node.attr("disabled", "");
}
node.finish()