pub trait FocusTrapElement: InteractiveElement + Sized {
// Provided method
fn focus_trap(
self,
id: impl Into<ElementId>,
focus_handle: &FocusHandle,
) -> FocusTrapContainer<Self>
where Self: ParentElement + Styled + Element + 'static { ... }
}Expand description
An extension trait to add focus_trap functionality to interactive elements.
Provided Methods§
Sourcefn focus_trap(
self,
id: impl Into<ElementId>,
focus_handle: &FocusHandle,
) -> FocusTrapContainer<Self>
fn focus_trap( self, id: impl Into<ElementId>, focus_handle: &FocusHandle, ) -> FocusTrapContainer<Self>
Enable focus trap for this element.
When enabled, focus will automatically cycle within this container instead of escaping to parent elements. This is useful for modal dialogs, sheets, and other overlay components.
The focus trap works by:
- Registering this element as a focus trap container
- When Tab/Shift-Tab is pressed, Root intercepts the event
- If focus would leave the container, it cycles back to the beginning/end
§Example
ⓘ
v_flex()
.child(Button::new("btn1").label("Button 1"))
.child(Button::new("btn2").label("Button 2"))
.child(Button::new("btn3").label("Button 3"))
.focus_trap("trap1", &self.container_focus_handle)
// Pressing Tab will cycle: btn1 -> btn2 -> btn3 -> btn1
// Focus will not escape to elements outside this containerDyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".