♻️ (pagetop): Deshabilita menús con with_disabled()

Cambia `link_disabled()`, `link_blank_disabled()` y `button_disabled()`
de `nav::Item` y `dropdown::Item` por `with_disabled(bool)`, como en
Button.
This commit is contained in:
Manuel Cillero 2026-11-23 02:01:06 +01:00
parent 5d6852382a
commit f1fd34f974
12 changed files with 123 additions and 93 deletions

View file

@ -193,3 +193,42 @@ async fn separators_are_also_cleaned_in_a_dropdown_inside_a_nav() {
assert!(!html.contains("dropdown-divider"), "{html}");
assert!(html.contains("item-shown"), "{html}");
}
// **< Disabled items >*****************************************************************************
async fn render_item(mut item: dropdown::Item) -> String {
item.render(&mut Context::default()).await.into_string()
}
#[pagetop::test]
async fn a_disabled_link_has_no_href() {
let html = render_item(dropdown::Item::link(Lc::n("Home"), "/").with_disabled(true)).await;
assert!(html.contains(r#"class="dropdown-item disabled""#), "{html}");
assert!(html.contains(r#"aria-disabled="true""#));
assert!(!html.contains("href="));
// Opening in a new window does not apply to a link that cannot be followed.
let html = render_item(
dropdown::Item::link_blank(Lc::n("Docs"), "https://docs.rs").with_disabled(true),
)
.await;
assert!(!html.contains("target="), "{html}");
let html = render_item(dropdown::Item::link(Lc::n("Home"), "/").with_disabled(false)).await;
assert!(html.contains(r#"href="/""#), "{html}");
assert!(!html.contains("disabled"));
}
#[pagetop::test]
async fn a_disabled_button_is_disabled() {
let html = render_item(dropdown::Item::button(Lc::n("Save")).with_disabled(true)).await;
assert!(html.contains(r#"aria-disabled="true""#), "{html}");
assert!(html.contains(r#" disabled"#));
}
#[pagetop::test]
async fn disabled_does_not_apply_to_labels() {
let label = render_item(dropdown::Item::label(Lc::n("Note"))).await;
let disabled = render_item(dropdown::Item::label(Lc::n("Note")).with_disabled(true)).await;
assert_eq!(label, disabled);
}

42
tests/component_nav.rs Normal file
View file

@ -0,0 +1,42 @@
use pagetop::prelude::*;
async fn render_item(mut item: nav::Item) -> String {
item.render(&mut Context::default()).await.into_string()
}
#[pagetop::test]
async fn a_disabled_link_has_no_href() {
let html = render_item(nav::Item::link(Lc::n("Shop"), "/shop").with_disabled(true)).await;
assert!(html.contains(r#"class="nav-link disabled""#), "{html}");
assert!(html.contains(r#"aria-disabled="true""#));
assert!(!html.contains("href="));
// Opening in a new window does not apply to a link that cannot be followed.
let html =
render_item(nav::Item::link_blank(Lc::n("Docs"), "https://docs.rs").with_disabled(true))
.await;
assert!(!html.contains("target="), "{html}");
assert!(!html.contains("rel="));
let html = render_item(nav::Item::link_blank(Lc::n("Docs"), "https://docs.rs")).await;
assert!(html.contains(r#"target="_blank""#), "{html}");
}
#[pagetop::test]
async fn disabled_can_be_turned_off() {
let html = render_item(
nav::Item::link(Lc::n("Shop"), "/shop")
.with_disabled(true)
.with_disabled(false),
)
.await;
assert!(html.contains(r#"href="/shop""#), "{html}");
assert!(!html.contains("disabled"));
}
#[pagetop::test]
async fn disabled_does_not_apply_to_labels() {
let label = render_item(nav::Item::label(Lc::n("Note"))).await;
let disabled = render_item(nav::Item::label(Lc::n("Note")).with_disabled(true)).await;
assert_eq!(label, disabled);
}