pub trait StackModal: Send {
// Required methods
fn render_content(&self, area: Rect, frame: &mut Frame<'_>);
fn handle_event(
&mut self,
event: &Event,
hit_id: HitId,
) -> Option<ModalResultData>;
fn size_constraints(&self) -> ModalSizeConstraints;
fn backdrop_config(&self) -> BackdropConfig;
// Provided methods
fn close_on_escape(&self) -> bool { ... }
fn close_on_backdrop(&self) -> bool { ... }
fn aria_modal(&self) -> bool { ... }
fn focusable_ids(&self) -> Option<Vec<ModalFocusId>> { ... }
}Expand description
Trait for modal content that can be managed in the stack.
This trait abstracts over different modal implementations (Dialog, custom modals) so they can all be managed by the same stack.
§Focus Management (bd-39vx.5)
Modals can optionally participate in focus management by providing:
focusable_ids(): List of focusable widget IDs within the modalaria_modal(): Whether this modal should be treated as an ARIA modal
When focus management is enabled, the caller should:
- Create a focus group from
focusable_ids()when the modal opens - Push a focus trap to constrain Tab navigation within the modal
- Auto-focus the first focusable widget
- Restore previous focus when the modal closes
Required Methods§
Sourcefn render_content(&self, area: Rect, frame: &mut Frame<'_>)
fn render_content(&self, area: Rect, frame: &mut Frame<'_>)
Render the modal content at the given area.
Sourcefn handle_event(
&mut self,
event: &Event,
hit_id: HitId,
) -> Option<ModalResultData>
fn handle_event( &mut self, event: &Event, hit_id: HitId, ) -> Option<ModalResultData>
Handle an event, returning true if the modal should close.
Sourcefn size_constraints(&self) -> ModalSizeConstraints
fn size_constraints(&self) -> ModalSizeConstraints
Get the modal’s size constraints.
Sourcefn backdrop_config(&self) -> BackdropConfig
fn backdrop_config(&self) -> BackdropConfig
Get the backdrop configuration.
Provided Methods§
Sourcefn close_on_escape(&self) -> bool
fn close_on_escape(&self) -> bool
Whether this modal can be closed by pressing Escape.
Sourcefn close_on_backdrop(&self) -> bool
fn close_on_backdrop(&self) -> bool
Whether this modal can be closed by clicking the backdrop.
Sourcefn aria_modal(&self) -> bool
fn aria_modal(&self) -> bool
Whether this modal is an ARIA modal (accessibility semantic).
ARIA modals:
- Trap focus within the modal (Tab cannot escape)
- Announce modal semantics to screen readers
- Block interaction with content behind the modal
Default: true for accessibility compliance.
§Invariants
- When
aria_modal()returns true, focus MUST be trapped within the modal. - Screen readers should announce modal state changes.
§Failure Modes
- If focus trap is not configured, Tab may escape (accessibility violation).
Sourcefn focusable_ids(&self) -> Option<Vec<ModalFocusId>>
fn focusable_ids(&self) -> Option<Vec<ModalFocusId>>
Get the IDs of focusable widgets within this modal.
These IDs are used to create a focus group when the modal opens. The first ID in the list receives auto-focus.
Returns None if focus management is not needed (e.g., non-interactive modals).
§Example
fn focusable_ids(&self) -> Option<Vec<ModalFocusId>> {
Some(vec![
self.input_field_id,
self.confirm_button_id,
self.cancel_button_id,
])
}