From de474e9af69db8322523d89618f9cbc2dc91fa42 Mon Sep 17 00:00:00 2001 From: Samit Basu Date: Fri, 20 Nov 2026 11:52:59 -0800 Subject: [PATCH] Combobox: the focus ring is a `has` rule, the rules' first real use (#443) The combobox's box, shadcn's input group, wore its ring through its own `focus_within` variant. It is now `has(Match::focus_visible(), ..)`: the box's border color and ring while a child, the field, has focus, as shadcn's `has-[[data-slot=input-group-control]:focus-visible]` does. The rule reads last frame's focus, so the ring follows the focus a frame later. Behavior changes: none in the goldens; the ring appears a frame after the field takes focus instead of in the frame it does. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01AJYxo4YJZUXcPJ1bHdAHKy --- crates/eggshell-ui-extras/src/command/list.rs | 8 ++--- tests/it/command_palette.rs | 33 +++++++++++++++++++ 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/crates/eggshell-ui-extras/src/command/list.rs b/crates/eggshell-ui-extras/src/command/list.rs index 716b0792..b25ca93e 100644 --- a/crates/eggshell-ui-extras/src/command/list.rs +++ b/crates/eggshell-ui-extras/src/command/list.rs @@ -8,8 +8,8 @@ use std::sync::Arc; use eggshell_ui::owned::{Enablement, Mark}; use eggshell_ui::vlist::ListNav; use eggshell_ui::{ - Builder, Command, CommandState, Commands, Icon, Key, Scope, Shell, Style, Tw, child_id, icons, - tw, + Builder, Command, CommandState, Commands, Icon, Key, Match, Scope, Shell, Style, Tw, child_id, + icons, tw, }; use egui::{Context, Id, Role}; @@ -337,8 +337,8 @@ pub(crate) fn group_classes(style: &Style) -> Tw { .bg(states.rest.fill) .text(states.rest.text) .role(style.role(&select.text).clone()) - .focus_within(|p| { - p.border_color(states.focused.border) + .has(Match::focus_visible(), |b| { + b.border_color(states.focused.border) .ring(style.focus.width, style.focus.color) }); match select.trigger.paint.shadow { diff --git a/tests/it/command_palette.rs b/tests/it/command_palette.rs index aff97c63..80fca038 100644 --- a/tests/it/command_palette.rs +++ b/tests/it/command_palette.rs @@ -226,6 +226,39 @@ fn the_combobox_is_a_field_that_opens_on_a_click_filters_as_typed_and_picks() { ); } +/// The rects painted with a stroke in the focus ring's color. +fn ring_rects(harness: &Harness<'_, Rig>) -> Vec { + let ring = eggshell_ui::Style::of(&harness.ctx).focus.color; + harness + .output() + .shapes + .iter() + .filter_map(|clipped| match &clipped.shape { + egui::epaint::Shape::Rect(shape) if shape.stroke.color == ring => Some(shape.rect), + _ => None, + }) + .collect() +} + +#[test] +fn the_combobox_box_wears_the_focus_ring_while_its_field_has_focus() { + let mut harness = harness(); + assert!( + ring_rects(&harness).is_empty(), + "precondition: no focus, no ring" + ); + combobox(&harness).focus(); + harness.run_steps(6); + assert!( + support::focused_path(&harness).is_some(), + "precondition: the field has the focus" + ); + assert!( + !ring_rects(&harness).is_empty(), + "the group's ring is drawn once the field has focus" + ); +} + #[test] fn the_chevron_opens_the_list_and_gives_the_field_the_focus() { let mut harness = harness();