Buttons · ToggleButton disabled: shown, not pressable, no tab stop, says it is unavailable; its tooltip can give the reason
This commit is contained in:
1 parent
b56acd2b9d
commit
f6f8b20624
2 files changed
+63
-16
No files matched your search
+38
-3
@@ -1,9 +1,9 @@
|
||||
use gpui::{
|
||||
Context, FocusHandle, IntoElement, KeyBinding, KeyUpEvent, Keystroke, ParentElement, Render,
|
||||
Styled, TestAppContext, VisualTestContext, Window,
|
||||
Context, FocusHandle, IntoElement, KeyBinding, KeyUpEvent, Keystroke, Modifiers, ParentElement,
|
||||
Render, Styled, TestAppContext, VisualTestContext, Window, div, point, px,
|
||||
};
|
||||
|
||||
use super::Button;
|
||||
use super::{Button, ToggleButton, ToggleItem};
|
||||
use crate::{
|
||||
primitives::{FocusNext, FocusScope},
|
||||
theme::Theme,
|
||||
@@ -63,3 +63,38 @@ fn a_loading_button_ignores_presses_and_keeps_its_tab_stop(cx: &mut TestAppConte
|
||||
"focus stayed on it"
|
||||
);
|
||||
}
|
||||
|
||||
/// One toggle that counts its presses.
|
||||
struct Toggles {
|
||||
disabled: bool,
|
||||
presses: usize,
|
||||
}
|
||||
|
||||
impl Render for Toggles {
|
||||
fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
let view = cx.entity();
|
||||
div().size_full().child(
|
||||
ToggleButton::new("bold", ToggleItem::new("bold").label("B"), false)
|
||||
.disabled(self.disabled)
|
||||
.on_toggle(move |_, _, cx| view.update(cx, |toggles, _| toggles.presses += 1)),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn a_disabled_toggle_ignores_clicks(cx: &mut TestAppContext) {
|
||||
cx.update(Theme::init);
|
||||
let (view, cx) = cx.add_window_view(|_, _| Toggles {
|
||||
disabled: true,
|
||||
presses: 0,
|
||||
});
|
||||
cx.simulate_click(point(px(4.0), px(4.0)), Modifiers::none());
|
||||
assert_eq!(view.read_with(cx, |toggles, _| toggles.presses), 0);
|
||||
view.update(cx, |toggles, cx| {
|
||||
toggles.disabled = false;
|
||||
cx.notify();
|
||||
});
|
||||
cx.run_until_parked();
|
||||
cx.simulate_click(point(px(4.0), px(4.0)), Modifiers::none());
|
||||
assert_eq!(view.read_with(cx, |toggles, _| toggles.presses), 1);
|
||||
}
|
||||
Reference in new issue
Block a user