Skip to main content

StackModal

Trait StackModal 

Source
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 modal
  • aria_modal(): Whether this modal should be treated as an ARIA modal

When focus management is enabled, the caller should:

  1. Create a focus group from focusable_ids() when the modal opens
  2. Push a focus trap to constrain Tab navigation within the modal
  3. Auto-focus the first focusable widget
  4. Restore previous focus when the modal closes

Required Methods§

Source

fn render_content(&self, area: Rect, frame: &mut Frame<'_>)

Render the modal content at the given area.

Source

fn handle_event( &mut self, event: &Event, hit_id: HitId, ) -> Option<ModalResultData>

Handle an event, returning true if the modal should close.

Source

fn size_constraints(&self) -> ModalSizeConstraints

Get the modal’s size constraints.

Source

fn backdrop_config(&self) -> BackdropConfig

Get the backdrop configuration.

Provided Methods§

Source

fn close_on_escape(&self) -> bool

Whether this modal can be closed by pressing Escape.

Source

fn close_on_backdrop(&self) -> bool

Whether this modal can be closed by clicking the backdrop.

Source

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).
Source

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,
    ])
}

Implementors§