summaryrefslogtreecommitdiffstats
path: root/web/src/widget
diff options
context:
space:
mode:
authorLibravatar Jonas Matser <jonas@jonasmatser.nl>2020-12-01 11:52:52 +0100
committerLibravatar Héctor Ramón <hector0193@gmail.com>2021-06-10 18:28:37 +0700
commitdbc1181011d579ac1da2546fba08e11094633f4b (patch)
tree1b5239b76f4040b02bf73cd2b4cf8d88507e1bef /web/src/widget
parent0e70b11e00e4d8517419a5f09490c9502827d35b (diff)
downloadiced-dbc1181011d579ac1da2546fba08e11094633f4b.tar.gz
iced-dbc1181011d579ac1da2546fba08e11094633f4b.tar.bz2
iced-dbc1181011d579ac1da2546fba08e11094633f4b.zip
Adds doc comment for disabled button
Makes disabled button behavior consistent in web
Diffstat (limited to 'web/src/widget')
-rw-r--r--web/src/widget/button.rs11
1 files changed, 11 insertions, 0 deletions
diff --git a/web/src/widget/button.rs b/web/src/widget/button.rs
index 8a36aab9..7c8612f6 100644
--- a/web/src/widget/button.rs
+++ b/web/src/widget/button.rs
@@ -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()