♿️ (form): Enlaza ayuda de los campos a su control

This commit is contained in:
Manuel Cillero 2026-10-09 00:59:43 +02:00
parent fc71a077ee
commit 8690f994c3
15 changed files with 341 additions and 44 deletions

View file

@ -55,6 +55,7 @@ pub(crate) fn setup(field: &mut Field) {
pub(crate) fn render(field: &Field, cx: &mut Context) -> Result<Markup, ComponentError> {
let container_id = field.id();
let input_id = container_id.as_deref().map(|id| util::join!(id, "-input"));
let help = form::FieldHelp::new(field.help_text(), input_id.as_deref(), cx);
let input_class = if *field.plaintext() {
"form-control-plaintext"
} else {
@ -99,6 +100,7 @@ pub(crate) fn render(field: &Field, cx: &mut Context) -> Result<Markup, Componen
input
type=(field.kind())
id=[input_id.as_deref()]
aria-describedby=[help.id()]
class=(input_class)
name=[field.name().as_deref()]
value=[field.value().as_deref()]
@ -116,9 +118,7 @@ pub(crate) fn render(field: &Field, cx: &mut Context) -> Result<Markup, Componen
required[*field.required()]
disabled[*field.disabled()];
@if floating { (label) }
@if let Some(description) = field.help_text().lookup(cx) {
div class="form-text" { (description) }
}
(help)
}
})
}

View file

@ -62,6 +62,7 @@ pub(crate) fn setup(field: &mut Field) {
pub(crate) fn render(field: &Field, cx: &mut Context) -> Result<Markup, ComponentError> {
let container_id = field.id();
let select_id = container_id.as_deref().map(|id| util::join!(id, "-select"));
let help = form::FieldHelp::new(field.help_text(), select_id.as_deref(), cx);
let floating = field.props().extra_or(EXTRA_FLOATING_LABEL, false);
let label = match field.label().lookup(cx) {
Some(text) => html! {
@ -84,6 +85,7 @@ pub(crate) fn render(field: &Field, cx: &mut Context) -> Result<Markup, Componen
@if !floating { (label) }
select
id=[select_id.as_deref()]
aria-describedby=[help.id()]
class="form-select"
name=[field.name().as_deref()]
multiple[*field.multiple()]
@ -124,9 +126,7 @@ pub(crate) fn render(field: &Field, cx: &mut Context) -> Result<Markup, Componen
}
}
@if floating { (label) }
@if let Some(description) = field.help_text().lookup(cx) {
div class="form-text" { (description) }
}
(help)
}
})
}

View file

@ -61,6 +61,7 @@ pub(crate) fn render(field: &Textarea, cx: &mut Context) -> Result<Markup, Compo
let textarea_id = container_id
.as_deref()
.map(|id| util::join!(id, "-textarea"));
let help = form::FieldHelp::new(field.help_text(), textarea_id.as_deref(), cx);
let floating = field.props().extra_or(EXTRA_FLOATING_LABEL, false);
// La etiqueta flotante requiere `placeholder` para animar la etiqueta; si no está definido se
// fuerza `placeholder=""`.
@ -90,6 +91,7 @@ pub(crate) fn render(field: &Textarea, cx: &mut Context) -> Result<Markup, Compo
@if !floating { (label) }
textarea
id=[textarea_id.as_deref()]
aria-describedby=[help.id()]
class="form-control"
name=[field.name().as_deref()]
rows=[field.rows()]
@ -105,9 +107,7 @@ pub(crate) fn render(field: &Textarea, cx: &mut Context) -> Result<Markup, Compo
@if let Some(value) = field.value().as_deref() { (value) }
}
@if floating { (label) }
@if let Some(description) = field.help_text().lookup(cx) {
div class="form-text" { (description) }
}
(help)
}
})
}