Text Field
Text Field is a text input component for collecting user input. Use it for forms, search, filtering, and inline editing with features like error validation and scrubbing behavior.View source →Text Field is a text input component for collecting user input. Use it for forms, search, filtering, and inline editing. The component supports advanced features like error validation, slot-based composition for icons and labels, and scrubbing behavior for interactive numeric value adjustment.
This is an enhanced version of the TextField component from Radix Themes. For the original API reference, see the Radix Themes TextField documentation.
Playground
Installation
shellUsage
tsxAnatomy
TextField is a compound component with the following parts:
tsxRoot Props
The Root component is the input element that accepts user text input.
Slot Props
Slots allow you to place content before or after the input. Use them for icons, labels, units, or interactive scrubbers.
Variants
Use the variant prop to set input style.
Classic
Elevated style with subtle shadow for maximum visual prominence and important inputs.
tsxSurface
Standard surface style for form inputs and general text entry.
tsxSoft
Subtle background for secondary inputs and content-heavy interfaces.
tsxOutline
Bordered style for defined boundaries and structured forms.
tsxGhost
Minimal style for inline editing and seamless integration with text content.
tsxSizes
Set size for input density: 1 (24px), 2 (32px), 3 (40px). Use 3 for mobile touch targets. Supports responsive objects like { initial: '1', sm: '2', md: '3' }.
Size 1
For compact interfaces and dense data entry.
tsxSize 2
For standard form contexts and general interfaces.
tsxSize 3
For important inputs and mobile-friendly touch targets.
tsxColors
Use the color prop with semantic colors to communicate input purpose or status. The color affects the focus state and can be used for visual categorization.
tsxMaterial
Use the material prop to set input appearance. Choose solid for opaque backgrounds, or translucent for depth and separation over images or dynamic backgrounds.
Theme
Inputs automatically inherit the theme's material setting.
tsxCustom
Override the theme's material for specific effects.
tsxStates
Error
Use error and errorMessage props to show validation errors. Error messages are automatically connected to the input via ARIA attributes.
tsxDisabled
Set disabled to prevent interaction when input is unavailable.
tsxRead Only
Use readOnly to make input non-editable while keeping it focusable and copyable.
tsxSlots
Icon Slots
Place icons before or after the input for visual context and actions.
tsxLabel Slots
Use slots for inline labels or units, especially in design tools and property panels.
tsxScrubbing Slots
Enable interactive value adjustment by dragging on slot content. Perfect for numeric inputs in design tools, property panels, and parameter controls.
tsxScrubbing
Scrubbing allows users to adjust numeric values by dragging horizontally on a slot. This is a powerful interaction pattern for design tools, property panels, and any interface requiring quick numeric adjustments.
Basic Scrubbing
Enable scrubbing on a slot with the scrub prop and handle value changes with onScrub.
tsxMin/Max Constraints
Set boundaries on scrubbing values with scrubMin and scrubMax. The component clamps the delta internally, so just add it directly to your state.
tsxCustom Sensitivity
Control how sensitive scrubbing is with scrubSensitivity. Higher values require more mouse movement per step.
tsxModifier Keys
Use modifier keys for different adjustment speeds:
- Shift: Multiply step by 10 (default, customizable with
scrubShiftMultiplier) - Alt/Option: Multiply step by 0.1 for fine adjustments (default, customizable with
scrubAltMultiplier)
tsxScrubbing Behavior
During scrubbing:
- Pointer Lock: The cursor is hidden and movement is infinite (won't hit screen edges)
- Virtual Cursor: A custom cursor appears and wraps around viewport edges
- Delta Updates:
onScrubreceives the change amount (delta), not the absolute value - State Tracking:
isChangingparameter istruewhile dragging,falsewhen released
tsxExamples
Search Input
Combine icons and placeholder for clear search interfaces.
tsxEmail Input
Use appropriate input type for better mobile keyboard and validation.
tsxPassword Input
Combine password type with toggle visibility action.
tsxNumeric Input with Units
Display units and enable scrubbing for quick adjustments.
tsxForm with Validation
Show validation errors with error messages.
tsxProperty Panel
Design tool-style property inputs with labels and scrubbing.
tsxResponsive
Use responsive objects with the size prop to adapt input sizing across different breakpoints. The component uses a mobile-first approach.
tsxBreakpoints
Accessibility
TextField provides comprehensive accessibility through ARIA attributes and semantic HTML.
Keyboard Navigation
- Tab - Move focus to/from input
- Enter - Submit form (if inside form)
- Escape - Clear focus (browser default)
- Arrow Keys - Navigate cursor within text
- Shift + Arrow Keys - Select text
ARIA Attributes
aria-invalid="true"- Automatically set when error or isInvalid is truearia-describedby- Links to error message for screen reader announcementsaria-labelledby- Links to external label elementrole="alert"- Error messages are announced immediatelyaria-live="polite"- Error message updates are announced
Screen Readers
- Error messages are automatically associated with the input
- Required fields can be marked with
requiredprop - Placeholder text provides hints without replacing labels
- Input types provide semantic meaning (email, tel, url, etc.)
Scrubbing Accessibility
- Scrubbing only activates on pointer down, preserving keyboard access
- Interactive elements (buttons, links) inside slots are not affected
- Pointer lock provides infinite movement without hitting screen edges
- Visual cursor feedback during scrubbing operation
Best Practices
- Always provide a label (use
aria-labelledbyif label is external) - Use
errorMessageinstead of justerrorfor clear feedback - Provide placeholder as hints, not as replacement for labels
- Use appropriate input types for better mobile keyboards
- Mark required fields with
requiredprop - Ensure sufficient color contrast for all states
Enhancements
Kookie UI extends Radix Themes TextField with practical improvements:
Scrubbing Behavior
Interactive numeric value adjustment through TextField.Slot with scrub prop. Drag labels horizontally to modify values with customizable step, sensitivity, and modifier keys. Perfect for property panels and design tools.
Enhanced Error States
Rich error handling with error and errorMessage props. Error messages automatically associate with input via aria-describedby for screen reader accessibility. Visual error indicators appear in both light and dark themes.
Slot Composition
Flexible slot system supports icons, labels, and interactive controls on either side of the input. Slots can be scrubbed, clicked, or used for decorative content. Automatic icon sizing based on TextField size.
Advanced Validation
Built-in support for required fields, pattern validation, and min/max constraints. Form integration with native HTML validation attributes and proper error messaging.
Changelog
Added
- Scrubbing behavior for TextField.Slot with pointer lock and virtual cursor
- Error validation system with
error,errorMessage, andisInvalidprops - Automatic ARIA attributes for error messages and validation states
- Material prop for solid/translucent theme contexts
- Slot composition system for prefix/suffix content
- Scrubbable numeric inputs with min/max constraints, sensitivity control, and modifier keys
- Multiple slot support for complex input layouts
- Responsive size support with breakpoint objects
- Pointer lock for infinite scrubbing without hitting screen edges
- Virtual cursor with viewport wrap-around during scrubbing
- Delta-based onScrub callback with isChanging state tracking
Changed
- Enhanced focus states with better contrast
- Improved error state styling with clearer visual feedback
- Better slot positioning and alignment for icons and labels
- Scrubbing uses movementX for smooth sub-pixel precision
Deprecated
panelBackgroundprop in favor ofmaterialprop
Fixed
- Slot pointer events correctly handle interactive elements
- Error messages properly linked via ARIA for screen readers
- Focus management when clicking slots vs input
- Cursor positioning when clicking left vs right slots
- Min/max clamping in scrubbing with proper value tracking
- Modifier key detection (Shift, Alt) during scrubbing
- Virtual cursor visibility and positioning during pointer lock