maia_wasm/ui/
active.rs

1//! Active elements.
2//!
3//! This module defines the [`IsElementActive`] trait for [`Document`], which is
4//! used to check if a given UI element is the active element.
5
6use web_sys::Document;
7
8/// Trait to check if an element is active.
9///
10/// This trait is used to implement `is_element_active` as a method on
11/// [`Document`] instead of a function of two arguments.
12pub trait IsElementActive {
13    /// Returns `true` if the element is active.
14    ///
15    /// The `id` argument indicates the ID of the element.
16    fn is_element_active(&self, id: &str) -> bool;
17}
18
19impl IsElementActive for Document {
20    fn is_element_active(&self, id: &str) -> bool {
21        self.active_element()
22            .map(|elem| elem.id() == id)
23            .unwrap_or(false)
24    }
25}