Give a text field the keyboard on a click in its padding or border (#138)

gpui-component's Input frame tracks its own focus handle, apart from the
editor's: a click off the text line focused the frame and typing went
nowhere. One app-side wrapper focuses the field's state instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
nessarandClaude Opus 5.5 committed 2026-11-27 16:22:04 +01:00
1 parent c3003930f1
commit aa5db4036e
9 files changed
+87 -19

No files matched your search

+21
View File
@@ -0,0 +1,21 @@
//! A click anywhere in a text field's frame gives it the keyboard.
//!
//! gpui-component's `Input` tracks a focus handle of its own on the frame, apart from the
//! editor's: a click in the padding or the border focused the frame, and typing wrote nothing.
use gpui_kit::component::input::{Input, InputState};
use gpui_kit::*;
/// `input` in a wrapper that focuses `state` on a left click the editor did not take (the
/// padding, the border). The text line and the buttons run first and keep their own click: the
/// wrapper does nothing once the editor has the focus. Size the wrapper, not the `Input`.
pub fn input_frame(state: &Entity<InputState>, input: Input) -> Div {
let state = state.clone();
div()
.on_mouse_down(MouseButton::Left, move |_, window, cx| {
if !state.read(cx).focus_handle(cx).is_focused(window) {
state.update(cx, |state, cx| state.focus(window, cx));
}
})
.child(input)
}
+1
View File
@@ -7,6 +7,7 @@ mod card_images;
mod card_lift;
mod card_order;
mod champion_table;
mod input_frame;
mod local_time;
mod logon;
mod minimized;
+7 -4
View File
@@ -1,5 +1,6 @@
use super::UNKNOWN_ANVIL;
use crate::card_grid::MAX_WIDTH;
use crate::input_frame::input_frame;
use crate::page::{
Page,
home::{StatsNotice, count_badge, notice_line},
@@ -191,10 +192,12 @@ impl Page {
.gap_x_3()
.gap_y_2()
.child(
Input::new(&self.others_search_input)
.cleanable(true)
.w(px(260.))
.min_w(px(150.)),
input_frame(
&self.others_search_input,
Input::new(&self.others_search_input).cleanable(true),
)
.w(px(260.))
.min_w(px(150.)),
)
.child(self.sort_selector(cx)),
)
+6 -3
View File
@@ -3,6 +3,7 @@
//! Matches are fetched when it is added, when it is chosen in the selector and on « Actualiser ».
use super::{AccountItem, AccountList, Page, RELOAD_EVERY, SettingsRequested};
use crate::input_frame::input_frame;
use crate::text::friend_sync_line;
use crate::worker::{spawn_add_friend, spawn_friend_import};
use arena_tracker_core::{AddFriendError, AddedFriend, SyncProgress};
@@ -304,9 +305,11 @@ impl Page {
.gap_y_2()
.on_action(cx.listener(|page, _: &Escape, _, cx| page.close_friend_field(cx)))
.child(
div()
.w(px(260.))
.child(gpui_kit::component::input::Input::new(&self.friends.input)),
input_frame(
&self.friends.input,
gpui_kit::component::input::Input::new(&self.friends.input),
)
.w(px(260.)),
)
.child(
Button::new("friend-cancel")
+8 -4
View File
@@ -18,6 +18,7 @@ pub(in crate::page) use content::{BannerContent, Line};
use super::{Page, shown};
use crate::card_grid::MAX_WIDTH;
use crate::input_frame::input_frame;
use crate::theme::heading;
/// The filters on offer, whatever the Season.
@@ -246,10 +247,13 @@ impl Page {
.items_center()
.gap_3()
.child(
Input::new(&self.home_search_input)
.cleanable(true)
.w(px(260.))
.min_w(px(150.)),
input_frame(
&self.home_search_input,
Input::new(&self.home_search_input).cleanable(true),
)
.w(px(260.))
.min_w(px(150.))
.debug_selector(|| "home-search".into()),
)
.child(
TabBar::new("home-filter")
+6 -3
View File
@@ -15,6 +15,7 @@ use gpui_kit::*;
use super::list::{MatchRow, Outcome};
use super::shown::Champions;
use crate::input_frame::input_frame;
use crate::page::{Page, Tab};
use crate::text::ordinal;
use crate::worker::MatchEntry;
@@ -226,9 +227,11 @@ impl Page {
)
.child(self.placement_control(cx))
.child(
Input::new(&self.matches.filters.input)
.cleanable(true)
.w_full(),
input_frame(
&self.matches.filters.input,
Input::new(&self.matches.filters.input).cleanable(true),
)
.w_full(),
)
}
+7 -4
View File
@@ -13,6 +13,7 @@ use gpui_kit::prelude::FluentBuilder as _;
use gpui_kit::*;
use super::{Page, Tab as Screen, shown};
use crate::input_frame::input_frame;
use crate::text::{decimal, official_note};
use crate::theme::{heading, surface};
@@ -382,10 +383,12 @@ impl Page {
})),
)
.child(
Input::new(&self.search_input)
.cleanable(true)
.w(px(260.))
.min_w(px(150.)),
input_frame(
&self.search_input,
Input::new(&self.search_input).cleanable(true),
)
.w(px(260.))
.min_w(px(150.)),
)
.into_any_element(),
);
+26
View File
@@ -165,6 +165,32 @@ fn the_counter_keeps_its_total_while_a_search_and_a_filter_reduce_the_list(
assert_eq!(counter(cx), "1 / 4 champions validés");
}
#[gpui::test]
fn a_click_in_the_padding_of_the_search_field_gives_it_the_keyboard(cx: &mut TestAppContext) {
use gpui_kit::{Modifiers, point, px};
let (page, cx) = open_page_in_season(cx);
let cx = &mut { cx };
show(&page, cx, statistics(0, 3, champions(3)));
draw(cx);
let input = page.read_with(cx, |p, _| p.home_search_input.clone());
let field = cx.debug_bounds("home-search").unwrap();
let text = |cx: &mut VisualTestContext| input.read_with(cx, |i, _| i.value().to_string());
// Just inside the left border, above the text line: nothing but the frame is there.
cx.simulate_click(
point(field.left() + px(2.), field.top() + px(2.)),
Modifiers::none(),
);
cx.simulate_input("an");
assert_eq!(text(cx), "an");
// The text line still takes its own click, and the field keeps working.
cx.update(|window, cx| window.blur(cx));
cx.simulate_click(field.center(), Modifiers::none());
cx.simulate_input("x");
assert_eq!(text(cx), "anx");
}
#[gpui::test]
fn the_home_follows_the_season_of_the_statistics_but_not_their_format(cx: &mut TestAppContext) {
cx.executor().allow_parking();
+5 -1
View File
@@ -10,6 +10,7 @@ use gpui_kit::component::input::{Input, InputEvent, InputState};
use gpui_kit::component::{ActiveTheme as _, StyledExt as _};
use gpui_kit::*;
use crate::input_frame::input_frame;
use crate::logon::LogonLaunch;
use crate::release::{self, channel};
use crate::tray::{Tray, UNAVAILABLE};
@@ -435,7 +436,10 @@ impl Render for KeyForm {
.children((!self.first_launch).then(|| self.preferences(cx)))
.children((!self.first_launch).then(|| self.accounts_section(cx)))
.child(div().text_color(muted).child(explanation))
.child(Input::new(&self.input).mask_toggle())
.child(input_frame(
&self.input,
Input::new(&self.input).mask_toggle(),
))
.children(
self.error
.clone()