Skip to content

time_field: Focus the first segment when the field is pressed outside a segment - #3655

Merged
huacnlee merged 2 commits into
mainfrom
time-field-click-blank-focus
Oct 24, 2026
Merged

huacnlee merged 2 commits into
mainfrom
time-field-click-blank-focus

Conversation

@ylinwind

Copy link
Copy Markdown
Contributor

Description

Pressing a TimeField anywhere outside its digit segments did nothing. Only the segments listened for the mouse, so with a wide field (for example a form field set to w_full) most of its area was dead: a press beside 09 : 00 neither focused the field nor selected a segment. Segmented date/time inputs such as react-aria's TimeField (used by shadcn's date picker) focus the first segment when the field itself is pressed.

  • gpui-base: the field root now handles a left press by focusing the field and selecting its first segment. A press on a segment stops propagation after selecting that segment, so it still selects the segment it hit, not the first one. A disabled field does not handle the press, as before.
  • gpui-component: the base field now fills the styled frame (size_full), and the frame's horizontal padding moved onto the base field. The rendered result is the same, but a press anywhere inside the frame now reaches the field.

This touches gpui-base because only the base state can select a segment (select_segment is private), and the press behavior belongs to the base field.

Impact

  • Users of TimeField: the component itself, DatePicker's time row and the gpui-shell retained-form TimeField. All three render the same component, so they all get the new behavior. Pressing a segment works as it did before.
  • DatePicker closes its popup with on_mouse_up_out, which runs in the capture phase and is based on pointer position. The new stop_propagation on segment mouse-down happens in the bubble phase, so closing the popup is not affected. The DatePicker frame is flex_none with no explicit width, so size_full on the inner field does not change its size.
  • The one new behavior a caller can observe: a MouseDown listener on an ancestor no longer receives presses that land on a segment. No such listener exists in this repository.
  • No public API changes.

How to Test

cargo test -p gpui-component --features test-support --lib time
cargo test -p gpui-base --features test-support --lib time_field

pressing_outside_the_segments_focuses_the_first_segment presses the empty part of a 200px field (focused, hour selected), then the minute segment (minute selected), then the empty part again (hour selected). It fails without this change.

Also checked in a downstream app (Allsum's scheduled task form): pressing the empty part of a full-width time field selects the hour.

Checklist

  • I have read the CONTRIBUTING document and followed the guidelines.
  • Reviewed the changes in this PR and confirmed AI generated code (If any) is accurate.
  • Passed cargo run for story tests related to the changes.
  • Tested macOS, Windows and Linux platforms performance (if the change is platform-specific)

🤖 Generated with Claude Code

… a segment

A press on the field's empty space did nothing: only the digit segments
listened for the mouse. The base field now fills the styled frame and a
press anywhere in it focuses the field and selects the first segment, while
a press on a segment still selects that segment.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ylinwind
ylinwind force-pushed the time-field-click-blank-focus branch from 6636a90 to 043adc3 Compare October 23, 2026 11:12
@huacnlee
huacnlee enabled auto-merge (squash) October 24, 2026 04:15
@huacnlee
huacnlee merged commit c297ddf into main Oct 24, 2026
18 of 19 checks passed
@huacnlee
huacnlee deleted the time-field-click-blank-focus branch October 24, 2026 04:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants