✨ (form): Añade texto de ayuda a Checkbox

Documenta el criterio de uso de las cookies en PageTop y por qué no
requieren la aceptación del usuario.
This commit is contained in:
Manuel Cillero 2026-11-11 18:36:04 +01:00
parent e4a88b2150
commit a276a5f797
6 changed files with 138 additions and 15 deletions

View file

@ -47,6 +47,8 @@ pub struct Checkbox {
name: AttrName,
/// Devuelve la etiqueta del control.
label: Lc,
/// Devuelve el texto de ayuda del control.
help_text: Lc,
/// Devuelve si el control debe estar marcado/activo por defecto.
checked: bool,
/// Devuelve si el control recibe el foco automáticamente al cargar la página.
@ -104,6 +106,7 @@ impl Component for Checkbox {
let checkbox_id = util::join!(&container_id, "-checkbox");
let label = form::parts::Label::check(self.label(), Some(&checkbox_id))
.with_required(*self.required());
let help = form::parts::Help::new(self.help_text(), Some(&checkbox_id));
let is_switch = *self.checkbox_kind() == form::CheckboxKind::Switch;
Ok(html! {
@ -118,8 +121,10 @@ impl Component for Checkbox {
checked[*self.checked()]
autofocus[*self.autofocus()]
required[*self.required()]
disabled[*self.disabled()];
disabled[*self.disabled()]
aria-describedby=[help.id()];
(label.render(cx))
(help.render(cx))
}
})
}
@ -175,6 +180,12 @@ impl Checkbox {
self
}
/// Establece el texto de ayuda del control (usa [`Lc::none()`] para quitarlo).
pub fn with_help_text(mut self, help_text: Lc) -> Self {
self.help_text = help_text;
self
}
/// Establece si el control debe aparecer marcado/activo por defecto.
pub fn with_checked(mut self, checked: bool) -> Self {
self.checked = checked;