mirror of
https://github.com/slint-ui/slint.git
synced 2025-08-04 18:58:36 +00:00
TextInput: don't get the focus if disabled
Fixes #8626 ChangeLog: TextInput no longer get the focus if disabled
This commit is contained in:
parent
af573e6401
commit
db3bbcd0e4
3 changed files with 33 additions and 13 deletions
|
@ -911,6 +911,9 @@ impl Item for TextInput {
|
|||
) -> FocusEventResult {
|
||||
match event {
|
||||
FocusEvent::FocusIn(_reason) => {
|
||||
if !self.enabled() {
|
||||
return FocusEventResult::FocusIgnored;
|
||||
}
|
||||
self.has_focus.set(true);
|
||||
self.show_cursor(window_adapter);
|
||||
WindowInner::from_pub(window_adapter.window()).set_text_input_focused(true);
|
||||
|
@ -923,11 +926,8 @@ impl Item for TextInput {
|
|||
}
|
||||
|
||||
#[cfg(not(target_vendor = "apple"))]
|
||||
{
|
||||
// check self.enabled() to make sure it doesn't select disabled (greyed-out) inputs
|
||||
if *_reason == FocusReason::TabNavigation && self.enabled() {
|
||||
self.select_all(window_adapter, self_rc);
|
||||
}
|
||||
if *_reason == FocusReason::TabNavigation {
|
||||
self.select_all(window_adapter, self_rc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
// Copyright © SixtyFPS GmbH <info@slint.dev>
|
||||
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
|
||||
|
||||
TestCase := Rectangle {
|
||||
export component TestCase inherits Window {
|
||||
width: 400phx;
|
||||
height: 600phx;
|
||||
|
||||
input1 := TextInput {
|
||||
y: 0px;
|
||||
width: parent.width;
|
||||
height: 200phx;
|
||||
}
|
||||
|
@ -23,11 +24,12 @@ TestCase := Rectangle {
|
|||
read-only: true;
|
||||
}
|
||||
|
||||
property<bool> input1_focused: input1.has_focus;
|
||||
property<string> input1_text: input1.text;
|
||||
property<bool> input2_focused: input2.has_focus;
|
||||
property<string> input2_text: input2.text;
|
||||
property<bool> input3_focused: input3.has_focus;
|
||||
out property<bool> input1_focused: input1.has_focus;
|
||||
out property<string> input1_text: input1.text;
|
||||
out property<bool> input2_focused: input2.has_focus;
|
||||
out property<string> input2_text: input2.text;
|
||||
out property<bool> input3_focused: input3.has_focus;
|
||||
in-out property input2_enabled <=> input2.enabled;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -76,7 +78,6 @@ let mut ime_requests = slint_testing::access_testing_window(instance.window(), |
|
|||
assert!(matches!(ime_requests.next(), Some(InputMethodRequest::Disable)));
|
||||
assert!(ime_requests.next().is_none());
|
||||
assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Text);
|
||||
|
||||
```
|
||||
|
||||
```cpp
|
||||
|
@ -123,4 +124,23 @@ slintlib.private_api.send_keyboard_string_sequence(instance, "Only for field 2")
|
|||
assert.equal(instance.input1_text, "Only for field 1");
|
||||
assert.equal(instance.input2_text, "Only for field 2");
|
||||
```
|
||||
|
||||
|
||||
```rust
|
||||
// Test for issue #8626: disabled TextInputs should not be focusable
|
||||
let instance = TestCase::new().unwrap();
|
||||
assert!(instance.get_input2_enabled());
|
||||
instance.set_input2_enabled(false);
|
||||
assert!(!instance.get_input1_focused());
|
||||
assert!(!instance.get_input2_focused());
|
||||
assert!(!instance.get_input3_focused());
|
||||
slint_testing::send_keyboard_string_sequence(&instance, "\t");
|
||||
assert!(instance.get_input1_focused());
|
||||
assert!(!instance.get_input2_focused());
|
||||
assert!(!instance.get_input3_focused());
|
||||
slint_testing::send_keyboard_string_sequence(&instance, "\t");
|
||||
assert!(!instance.get_input1_focused());
|
||||
assert!(!instance.get_input2_focused());
|
||||
assert!(instance.get_input3_focused());
|
||||
```
|
||||
*/
|
||||
|
|
|
@ -68,7 +68,7 @@ assert_eq!(instance.get_value(), "hophop");
|
|||
assert_eq!(instance.get_condition(), false);
|
||||
slint_testing::send_keyboard_string_sequence(&instance, "a\n\tdd\t\t");
|
||||
assert_eq!(instance.get_condition(), true);
|
||||
slint_testing::send_keyboard_string_sequence(&instance, "\tblop\n\t");
|
||||
slint_testing::send_keyboard_string_sequence(&instance, "blop\n\t");
|
||||
assert_eq!(instance.get_value(), "blop");
|
||||
```
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue