Skip to content

Commit

Permalink
Add dom-accessibility-api
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielleHuisman committed Oct 13, 2024
1 parent ce67702 commit 12e227d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 27 deletions.
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/dom/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ version.workspace = true

[dependencies]
aria-query = "0.0.3"
dom-accessibility-api = "0.0.2"
log.workspace = true
paste = "1.0.15"
pretty-format = { path = "../pretty-format", version = "0.0.1" }
Expand Down
1 change: 0 additions & 1 deletion packages/dom/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use crate::{
static CONFIG: LazyLock<Arc<Mutex<Config>>> = LazyLock::new(|| {
Arc::new(Mutex::new(Config {
test_id_attribute: "data-testid".into(),
computed_style_supports_pseudo_elements: false,
default_hidden: false,
default_ignore: "script, style".into(),
show_original_stack_trace: false,
Expand Down
23 changes: 12 additions & 11 deletions packages/dom/src/queries/role.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use std::collections::HashSet;

use aria_query::{AriaProperty, AriaRole, ROLES, ROLE_ELEMENTS};
use web_sys::{Element, HtmlElement};
use dom_accessibility_api::{
compute_accessible_description, compute_accessible_name, ComputeTextAlternativeOptions,
};
use web_sys::HtmlElement;

use crate::{
build_queries,
Expand All @@ -18,14 +21,6 @@ use crate::{
util::node_list_to_vec,
};

fn compute_accessibe_name(_element: &Element) -> String {
todo!("port dom-accessibility-api and import compute_accessibe_name")
}

fn compute_accessibe_description(_element: &Element) -> String {
todo!("port dom-accessibility-api and import compute_accessibe_description")
}

pub fn _query_all_by_role<M: Into<ByRoleMatcher>>(
container: &HtmlElement,
role: M,
Expand Down Expand Up @@ -261,7 +256,10 @@ pub fn _query_all_by_role<M: Into<ByRoleMatcher>>(
let normalizer = |text| text;

matches(
Some(compute_accessibe_name(element)),
Some(compute_accessible_name(
element,
ComputeTextAlternativeOptions::default(),
)),
Some(element),
name,
&normalizer,
Expand All @@ -276,7 +274,10 @@ pub fn _query_all_by_role<M: Into<ByRoleMatcher>>(
let normalizer = |text| text;

matches(
Some(compute_accessibe_description(element)),
Some(compute_accessible_description(
element,
ComputeTextAlternativeOptions::default(),
)),
Some(element),
description,
&normalizer,
Expand Down
15 changes: 0 additions & 15 deletions packages/dom/src/types/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ pub type GetElementErrorFn = dyn Fn(Option<String>, Element) -> QueryError + Sen
pub struct Config {
pub test_id_attribute: String,
// TODO
pub computed_style_supports_pseudo_elements: bool,
/// Default value for the `hidden` option in `by_role` queries.
pub default_hidden: bool,
/// Default value for the `ignore` option in `by_text` queries.
Expand All @@ -28,11 +27,6 @@ impl Config {
if let Some(test_id_attribute) = other.test_id_attribute {
self.test_id_attribute = test_id_attribute;
}
if let Some(computed_style_supports_pseudo_elements) =
other.computed_style_supports_pseudo_elements
{
self.computed_style_supports_pseudo_elements = computed_style_supports_pseudo_elements;
}
if let Some(default_hidden) = other.default_hidden {
self.default_hidden = default_hidden;
}
Expand All @@ -55,7 +49,6 @@ impl Config {
pub struct PartialConfig {
pub test_id_attribute: Option<String>,
// TODO
pub computed_style_supports_pseudo_elements: Option<bool>,
/// Default value for the `hidden` option in `by_role` queries.
pub default_hidden: Option<bool>,
/// Default value for the `ignore` option in `by_text` queries.
Expand All @@ -74,11 +67,6 @@ impl PartialConfig {
self
}

pub fn computed_style_supports_pseudo_elements(mut self, value: bool) -> Self {
self.computed_style_supports_pseudo_elements = Some(value);
self
}

pub fn default_hidden(mut self, value: bool) -> Self {
self.default_hidden = Some(value);
self
Expand Down Expand Up @@ -109,9 +97,6 @@ impl From<&Config> for PartialConfig {
fn from(value: &Config) -> Self {
Self {
test_id_attribute: Some(value.test_id_attribute.clone()),
computed_style_supports_pseudo_elements: Some(
value.computed_style_supports_pseudo_elements,
),
default_hidden: Some(value.default_hidden),
default_ignore: Some(value.default_ignore.clone()),
show_original_stack_trace: Some(value.show_original_stack_trace),
Expand Down

0 comments on commit 12e227d

Please sign in to comment.