Components
Input Tag
A dynamic tag input component for adding, editing, and managing tags with optional limits and layout configurations.
Previews with Code
Example 1: Simple Tag Input
Simple Tag Input
Example 2: Tag Input with Custom Limit
Tag Input with Custom Limit
0/3 tags added
Example 3: Advanced Tag Input with Stacked Layout
Advanced Tag Input (Stacked)
ReactNextJSTypeScript
Tags appear in a list below the input field
Installation
The TagInput
component allows users to dynamically add and manage tags with flexible layout options and styling.
Quickly add the component using:
File Structure
tag-input.tsx
Props
TagInput Props
Prop | Type | Default |
---|---|---|
id | string | - |
label | string | - |
maxTags | number | 5 |
placeholder | string | "Add a tag" |
inlineTags | boolean | true |
inputFieldPosition | "top" | "bottom" | "inline" | "inline" |
initialTags | Tag[] | [] |
Tag Interface
Features
- Dynamic Tag Management:
- Add, remove, and navigate between tags with keyboard support.
- Flexible Layouts:
- Choose between inline, stacked, or custom tag layouts.
- Customizable Limits:
- Set maximum tag counts with visual feedback.
- Pre-populated Tags:
- Initialize with existing tags for editing workflows.
- Advanced Styling:
- Comprehensive style customization for all component parts.
- Keyboard Navigation:
- Navigate and edit tags using keyboard shortcuts.
Accessibility
The TagInput
component includes:
- Proper labeling with associated form elements
- Keyboard navigation between tags
- Focus management
- Screen reader announcements for tag actions
- Clear visual indicators for interactive elements
Usage with Form Libraries
The TagInput component works well with popular form libraries:
With React Hook Form
Conclusion
The TagInput
component provides a flexible solution for tag management in forms and interfaces. With support for various layouts, keyboard navigation, and comprehensive styling options, it adapts to many different use cases and design requirements.