diff --git a/crates/ui-panels/src/rails/flyout.rs b/crates/ui-panels/src/rails/flyout.rs index 7ed09ecff..ef75176c3 100644 --- a/crates/ui-panels/src/rails/flyout.rs +++ b/crates/ui-panels/src/rails/flyout.rs @@ -339,14 +339,16 @@ impl Component for FlyoutButton<'_, T> { } } - fn access(&self, access: &mut Access, _: &Cx<'_, Self>) { + fn access(&self, access: &mut Access, cx: &Cx<'_, Self>) { let resolved = self.laid.as_ref().and_then(|laid| self.lead(laid)); - let name = resolved.map(|resolved| resolved.label.as_ref().to_owned()); - if let Some(resolved) = resolved { - access.name(Name::Text(resolved.label.as_ref().to_owned())); - if let Some(hint) = &resolved.hint { - access.description(hint.as_ref().to_owned()); - } + // A command that does not resolve leaves the button's own label as its name. + let own = (!cx.resolved.label.is_empty()).then(|| cx.resolved.label.to_owned()); + let name = resolved.map(|resolved| resolved.label.as_ref().to_owned()).or(own); + if let Some(name) = &name { + access.name(Name::Text(name.clone())); + } + if let Some(hint) = resolved.and_then(|resolved| resolved.hint.as_ref()) { + access.description(hint.as_ref().to_owned()); } // The face covers the whole button, so the button's own node is the face's node. access.node(FACE, Role::None); diff --git a/crates/ui-panels/tests/it/rails/mod.rs b/crates/ui-panels/tests/it/rails/mod.rs index ce705a14b..2b81f5486 100644 --- a/crates/ui-panels/tests/it/rails/mod.rs +++ b/crates/ui-panels/tests/it/rails/mod.rs @@ -135,6 +135,11 @@ fn a_click_command_cycles_and_a_hold_lists_the_tools_without_firing_it() { clicked.fixture.click(&target); clicked.fixture.idle(3); assert_eq!(fired(&clicked), 1, "a click fires the click command"); + // A pointer click need not leave focus on the button; the keys act on the focused one. + if clicked.fixture.focused_stop().is_none() { + clicked.fixture.key(Key::Tab, Modifiers::NONE); + } + assert!(clicked.fixture.focused_stop().is_some(), "the button has focus for the keys"); clicked.fixture.key(Key::Enter, Modifiers::NONE); assert_eq!(fired(&clicked), 1, "Enter fires it"); clicked.fixture.key(Key::Space, Modifiers::NONE); diff --git a/crates/ui-shell/src/shell/screen_mode_button.rs b/crates/ui-shell/src/shell/screen_mode_button.rs index d5bdbf0d9..cd9654c4d 100644 --- a/crates/ui-shell/src/shell/screen_mode_button.rs +++ b/crates/ui-shell/src/shell/screen_mode_button.rs @@ -1,8 +1,10 @@ //! `ScreenModeButton`: the status bar's screen mode button, a flyout of the three modes. use super::screen_mode::{ScreenMode, ScreenModeCommands}; +use super::words::ShellWords; use crate::contract::{NoValue, Outcome, Props as _, Show as _}; use crate::rails::{FlyoutButton, RailTool}; +use crate::runtime::env::Env; use egui::{Response, Ui}; #[cfg(feature = "testing")] @@ -43,7 +45,9 @@ impl ScreenModeButton { pub fn show(self, ui: &mut Ui) -> ScreenModeButtonOutput { let modes = [ScreenMode::Standard, ScreenMode::FullScreenWithMenuBar, ScreenMode::FullScreen]; let tools: Vec> = modes.iter().map(|mode| RailTool::new(*mode, ScreenModeCommands::of(*mode))).collect(); - let out = FlyoutButton::new(&tools, &self.mode).hold_selects(false).click(ScreenModeCommands::Cycle).show(ui); + // The shell's own word names the button when the Cycle command does not resolve. + let name = Env::of(ui).words::().screen_mode.clone(); + let out = FlyoutButton::new(&tools, &self.mode).label(name).hold_selects(false).click(ScreenModeCommands::Cycle).show(ui); ScreenModeButtonOutput { response: out.response } } }