🎨 (bootsier): Normaliza id's y revisa Checkbox

Renombra los sufijos de `id` de los controles internos para que cada
tipo tenga su propio identificador: `-checkbox`, `-check-{n}` y
`-radio-{n}`. Elimina además el atributo booleano `switch` inválido en
HTML (basta con `role="switch"` y `class="form-switch"`).
This commit is contained in:
Manuel Cillero 2026-04-24 20:27:31 +02:00
parent 5b7e13e52b
commit ffba175985
4 changed files with 40 additions and 12 deletions

View file

@ -55,6 +55,8 @@ pub struct Checkbox {
label: Attr<L10n>,
/// 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.
autofocus: bool,
/// Devuelve si el campo es obligatorio.
required: bool,
/// Devuelve si el control está deshabilitado.
@ -93,23 +95,24 @@ impl Component for Checkbox {
.name()
.get()
.unwrap_or_else(|| cx.required_id::<Self>(self.id(), 1));
let id = self.id().unwrap_or_else(|| util::join!("edit-", &name));
let container_id = self.id().unwrap_or_else(|| util::join!("edit-", &name));
let checkbox_id = util::join!(&container_id, "-checkbox");
let is_switch = *self.checkbox_kind() == form::CheckboxKind::Switch;
Ok(html! {
div class=[self.classes().get()] {
div id=(&container_id) class=[self.classes().get()] {
input
type="checkbox"
role=[is_switch.then_some("switch")]
id=(&id)
id=(&checkbox_id)
class="form-check-input"
name=(&name)
value="true"
checked[*self.checked()]
autofocus[*self.autofocus()]
required[*self.required()]
disabled[*self.disabled()]
switch[is_switch];
disabled[*self.disabled()];
@if let Some(label) = self.label().lookup(cx) {
label class="form-check-label" for=(&id) {
label class="form-check-label" for=(&checkbox_id) {
(label)
@if *self.required() {
span
@ -187,6 +190,13 @@ impl Checkbox {
self
}
/// Establece si el control recibe el foco automáticamente al cargar la página.
#[builder_fn]
pub fn with_autofocus(mut self, autofocus: bool) -> Self {
self.autofocus = autofocus;
self
}
/// Establece si el campo es obligatorio.
#[builder_fn]
pub fn with_required(mut self, required: bool) -> Self {