Interactive Elements
Foundation components that respond to user input - buttons, inputs, switches, and other interactive controls.
Interactive Elements
Overview
Interactive elements are foundation components that respond to user input such as taps, swipes, or keyboard actions. They form the basis of all user interactions in our applications and must be built with careful attention to accessibility, performance, and user experience.
Key Principles for Interactive Components
All interactive elements should:
- Provide clear visual feedback for all states (default, hover, pressed, disabled)
- Meet minimum touch target sizes (44×44 points)
- Include comprehensive keyboard support
- Communicate state changes to assistive technologies
- Handle loading and error states gracefully
Button Components
The Button is perhaps the most fundamental interactive component in any UI system. It serves as the primary way users trigger actions in our applications.
📋 Complete Implementation Available
See our Button Component for a production-ready example with TypeScript types, accessibility features, testing patterns, and usage examples. Perfect for copy-pasting into your project!
Component Interface
Implementation Guidelines
Implementation Considerations
Buttons appear simple but require careful implementation to handle all scenarios effectively:
- Accessibility: Ensure proper roles, states, and labels
- Loading states: Prevent multiple submissions while actions are pending
- Touch feedback: Provide appropriate visual feedback on press
- Variants: Support different visual styles for different contexts
- Composition: Allow composition with icons and other elements
Design Token Integration
Buttons should use design tokens for all visual properties:
Loading State Implementation
Loading states should always:
- Disable the button to prevent multiple submissions
- Show a visual indicator (typically a spinner)
- Maintain the button's size to prevent layout shifts
- Provide appropriate accessibility updates
Button Best Practices
(Do ✅) Follow these Button component best practices
- Use semantic colors based on button purpose (e.g., danger for destructive actions)
- Include appropriate touch targets (minimum 44×44 points)
- Maintain sufficient contrast ratios between text and background
- Use consistent spacing between buttons when grouped
- Always include a visible focus state for keyboard navigation
- Provide clear, action-oriented button text
(Don't ❌) Make these common Button component mistakes
- Using ambiguous or generic text like "Click Here" or "Submit"
- Placing too many buttons with equal visual weight in proximity
- Using buttons when links would be more appropriate (navigation vs. action)
- Creating custom one-off button styles instead of using variants
- Omitting loading states for asynchronous actions
- Making touch targets too small for comfortable interaction
Complete Button Implementation
For a complete implementation of the Button component with all variants, states, accessibility features, and testing patterns, see the Button Component.
The Button example demonstrates:
- ✅ All visual variants (primary, secondary, ghost, danger)
- ✅ Size variations (small, medium, large)
- ✅ Loading and disabled states
- ✅ Icon support (left and right)
- ✅ Full accessibility implementation
- ✅ Design token integration
- ✅ TypeScript interfaces
- ✅ Comprehensive testing patterns
Input Components
Input components handle text entry and form interactions. They must balance functionality with accessibility and user experience across different platforms and input methods.
Input Interface
For a complete implementation of the Input component with all variants, validation, accessibility features, and testing patterns, see the Input Component Example.
The Input example demonstrates:
- ✅ Multiple variants (outlined, filled)
- ✅ Size variations (small, medium, large)
- ✅ Validation with error messages
- ✅ Helper text support
- ✅ Icon support (left and right)
- ✅ Focus state management
- ✅ Full accessibility implementation
- ✅ Comprehensive testing patterns
Input Best Practices
(Do ✅) Input component best practices
- Provide clear labels for all inputs
- Show validation feedback inline and immediately
- Support autofill and password managers
- Include helper text for complex inputs
- Make error messages specific and actionable
- Support platform-specific input behaviors
(Don't ❌) Common input mistakes
- Validating only on form submission
- Using placeholder text as the only label
- Making error messages vague or technical
- Ignoring platform keyboard differences
- Forgetting to handle secure text entry
- Using tiny touch targets for input fields
Switch Components
Switches provide binary on/off controls for settings and preferences.
Switch Interface
Switch Implementation Considerations
- Visual feedback: Smooth animations for state changes
- Touch targets: Ensure adequate size for easy interaction
- Color contrast: Maintain visibility in both states
- Platform consistency: Match iOS and Android patterns
- Accessibility: Clear state announcements
Checkbox Components
Checkboxes allow users to select multiple options from a set.
Checkbox Interface
Checkbox Best Practices
- Support indeterminate state for parent-child relationships
- Include clear touch targets beyond the checkbox itself
- Provide visual feedback for all states
- Support keyboard navigation (Space to toggle)
- Group related checkboxes appropriately
Radio Button Components
Radio buttons allow single selection from a group of options.
RadioButton Interface
Slider Components
Sliders allow users to select values from a continuous range.
Slider Interface
General Best Practices for Interactive Elements
Accessibility Requirements
All interactive elements must:
-
Provide proper roles
-
Communicate states
-
Include descriptive labels
Performance Considerations
- Use
React.memofor components that receive stable props - Memoize style calculations with
useMemo - Debounce rapid interactions when appropriate
- Optimize animation performance with
useNativeDriver
Testing Interactive Elements
Summary
Interactive elements form the foundation of user interaction in your application. By following these patterns and best practices, you can create components that are:
- Accessible: Work for all users regardless of abilities
- Performant: Respond quickly to user input
- Consistent: Behave predictably across the application
- Maintainable: Easy to update and extend
Next Steps
- Explore Display Components for presenting information
- Learn about Design Token Integration for consistent styling
- Review Accessibility Patterns for inclusive design