From 55e6787b0b6e3e7d70c71afa9fee3ebbd1d383a7 Mon Sep 17 00:00:00 2001 From: SGavrl <277843151+SGavrl@users.noreply.github.com> Date: Fri, 3 Jul 2026 12:41:48 +0000 Subject: [PATCH] Fix :enabled/:disabled/:checked pseudo-classes matching real DOM state These were bundled in with the truly dynamic, interaction-only pseudo-classes (:hover/:active/:focus) and always resolved to false. That's right for :hover et al (there's no live cursor against a static snapshot) but wrong for :enabled/:disabled/:checked: those reflect real, static DOM state (the disabled/checked attributes), not user interaction, and modern component systems (Codex, Material, Bootstrap) lean on :enabled constantly for their base button/input styling. With it always false, every such base rule was silently inert, which is why the Wikipedia TOC toggle button (a "#); + let enabled = tree.query_selector_all("button:enabled").unwrap(); + assert_eq!(enabled.len(), 1, ":enabled should match only the non-disabled button"); + let disabled = tree.query_selector_all("button:disabled").unwrap(); + assert_eq!(disabled.len(), 1, ":disabled should match only the disabled button"); + } + + #[test] + fn test_enabled_does_not_match_non_form_elements() { + // :enabled/:disabled only apply to form controls; a plain div should + // never match either, disabled attribute or not. + let tree = parse_html(r#"
x
"#); + assert_eq!(tree.query_selector_all("div:enabled").unwrap().len(), 0); + assert_eq!(tree.query_selector_all("div:disabled").unwrap().len(), 0); + } + + #[test] + fn test_checked_matches_checked_attribute() { + let tree = parse_html( + r#""#, + ); + assert_eq!(tree.query_selector_all("input:checked").unwrap().len(), 1); + } + #[test] fn test_query_selector_descendant() { let tree =