✨ (base): Oculta separadores en menús sin opciones

`Dropdown::items()` devuelve `dropdown::Items`, cuyo `render()` sólo
pinta un encabezado si su grupo tiene algún elemento visible, y un
separador sólo entre elementos visibles. Lo aprovecha cualquier tema
que pinte el menú con `items().render()`.
This commit is contained in:
Manuel Cillero 2026-11-08 10:11:42 +01:00
parent e2e2ccb31e
commit c940403869
9 changed files with 292 additions and 10 deletions

View file

@ -15,7 +15,7 @@ mod props;
pub use props::{AutoClose, Direction, MenuAlign, MenuPosition};
pub use pagetop::base::component::Dropdown;
pub use pagetop::base::component::dropdown::{Item, ItemKind};
pub use pagetop::base::component::dropdown::{Item, ItemKind, Items};
const EXTRA_BUTTON_GROUPED: &str = "bootsier.dropdown.button_grouped";
const EXTRA_AUTO_CLOSE: &str = "bootsier.dropdown.auto_close";

View file

@ -66,6 +66,9 @@ fn menu() -> Nav {
.with_item(bs::nav::Item::dropdown(
Dropdown::new()
.with_title(Lc::n("dropdown-partial"))
.with_item(dropdown::Item::header(Lc::n("header-empty")))
.with_item(dropdown::Item::link(Lc::n("x"), TestRoute::Forbidden))
.with_item(dropdown::Item::divider())
.with_item(dropdown::Item::link(
Lc::n("in-allowed"),
TestRoute::Allowed,
@ -97,9 +100,18 @@ fn assert_only_allowed_links(html: &str) {
for shown in ["nav-allowed", "dropdown-partial", "in-allowed"] {
assert!(html.contains(shown), "`{shown}` is missing in {html}");
}
for hidden in ["nav-forbidden", "dropdown-empty", "in-forbidden"] {
for hidden in [
"nav-forbidden",
"dropdown-empty",
"in-forbidden",
"header-empty",
] {
assert!(!html.contains(hidden), "`{hidden}` is shown in {html}");
}
assert!(
!html.contains("dropdown-divider"),
"a divider is shown in {html}"
);
}
#[pagetop::test]