pub struct FocusManager {
pub strategy: FocusStrategy,
/* private fields */
}Expand description
Manages focus behavior for interactive components.
Different component types require different focus management strategies:
- Dialogs trap focus within their boundary
- Popovers restore focus to the trigger on close
- Menus focus the first item on open
FocusManager encapsulates these strategies and provides methods
for programmatic focus control.
Fields§
§strategy: FocusStrategyThe focus strategy to use.
Implementations§
Source§impl FocusManager
impl FocusManager
Sourcepub fn new(strategy: FocusStrategy) -> Self
pub fn new(strategy: FocusStrategy) -> Self
Create a new FocusManager with the given strategy.
Create a FocusManager for a menu (focus first item).
Sourcepub fn with_container(self, id: impl Into<String>) -> Self
pub fn with_container(self, id: impl Into<String>) -> Self
Set the container element ID.
Sourcepub fn container_id(&self) -> Option<&str>
pub fn container_id(&self) -> Option<&str>
Get the container ID.
Sourcepub fn save_restore_target(&mut self, element_id: impl Into<String>)
pub fn save_restore_target(&mut self, element_id: impl Into<String>)
Record the currently focused element for later restoration.
Sourcepub fn restore_target(&self) -> Option<&str>
pub fn restore_target(&self) -> Option<&str>
Get the element ID to restore focus to.
Sourcepub fn trap(&self, container_id: &str) -> FocusInstruction
pub fn trap(&self, container_id: &str) -> FocusInstruction
Begin trapping focus within the container.
Returns focus instructions that the framework adapter should execute.
Sourcepub fn release(&self) -> FocusInstruction
pub fn release(&self) -> FocusInstruction
Release the focus trap.
Sourcepub fn restore(&self) -> FocusInstruction
pub fn restore(&self) -> FocusInstruction
Restore focus to the previously focused element.
Sourcepub fn focus_first(&self, container_id: &str) -> FocusInstruction
pub fn focus_first(&self, container_id: &str) -> FocusInstruction
Focus the first focusable child of a container.
Sourcepub fn focus_last(&self, container_id: &str) -> FocusInstruction
pub fn focus_last(&self, container_id: &str) -> FocusInstruction
Focus the last focusable child of a container.
Sourcepub fn focus_next(&self) -> FocusInstruction
pub fn focus_next(&self) -> FocusInstruction
Focus the next focusable element.
Sourcepub fn focus_prev(&self) -> FocusInstruction
pub fn focus_prev(&self) -> FocusInstruction
Focus the previous focusable element.
Sourcepub fn is_trapping(&self) -> bool
pub fn is_trapping(&self) -> bool
Whether this manager uses focus trapping.
Sourcepub fn should_restore(&self) -> bool
pub fn should_restore(&self) -> bool
Whether this manager restores focus on close.
Trait Implementations§
Source§impl Clone for FocusManager
impl Clone for FocusManager
Source§fn clone(&self) -> FocusManager
fn clone(&self) -> FocusManager
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more