Input
Anatomy
Text input component supporting multiple HTML input types with full XSS protection via maud's escaping.
maud_ui::primitives::input
Props
Generated from public Rust fields. Defaults are evaluated from the implementation.
| Prop | Type | Default | Description |
|---|---|---|---|
name | String | "" | HTML name attribute for form submission |
input_type | InputType | Text | Input type (text, email, password, etc.) |
placeholder | String | "" | Placeholder text displayed when empty |
value | String | "" | Current value |
id | String | "" | HTML id attribute for label linkage |
disabled | bool | false | Whether the input is disabled |
required | bool | false | Whether the input is required |
invalid | bool | false | Whether the input is in an invalid state |
readonly | bool | false | Whether the input is readonly |
aria_describedby | Option<String> | None | Optional aria-describedby value linking to descriptive text (e.g. hint or error message) |
Examples
Profile
A typical sign-up form using text, email, and password inputs.
Input Types
Each HTML input type rendered with a contextual placeholder.
States
Default, populated, invalid, disabled, and read-only.
Usage and composition
Import
use maud_ui::primitives::input::{self, Props, InputType};
Example
use maud::html;
use maud_ui::primitives::input;
html! {
(input::render(input::Props {
name: "email".to_string(),
id: "email".to_string(),
input_type: input::InputType::Email,
placeholder: "you@example.com".to_string(),
required: true,
aria_describedby: Some("email-hint".to_string()),
..Default::default()
}))
}
InputType
pub enum InputType {
Text,
Email,
Password,
Url,
Tel,
Search,
Number,
File,
}
Security
All attribute values (name, placeholder, value, id, aria_describedby) are automatically escaped by maud's html! macro. User-controlled strings cannot break out of attributes.
Recent improvement: Migrated from format!-based rendering to maud's html! macro (fully escaped). XSS tests verify the fix.
File Input
The InputType::File variant renders with class mui-input--file for CSS customization.
Related
- Field — wraps Input with label/description/error.
- Input Group — input with prefix/suffix addons.
- Textarea — multi-line text input.
Shadcn Reference
Mirrors shadcn's Input component with all HTML5 input types and proper accessibility attributes.
Accessibility
- Label must link via
for=to inputid. aria-invalid="true"when in error state.aria-describedbylinks to hint/error text if provided.requiredattribute honored by browsers and screen readers.