Overview
Postman users frequently organize their work (collections, APIs, requests) using tags for better discoverability and management. A robust and intuitive tag input component is crucial for this experience, allowing users to quickly categorize items and improve team collaboration. This problem focuses on building the core functionality of such a component.
What you need to do / Task
Your task is to build a TagInput React component that allows users to add and remove tags.
- Input Field: Render an input field where users can type tag names.
- Add Tags:
- When a user types a tag name and presses
Enter or Tab, the tag should be added to the list.
- The input field should clear after a tag is added.
- Display Tags: Display the added tags as distinct visual "chips" or "pills" within the same container as the input field.
- Remove Tags: Each displayed tag chip should have a clickable 'x' icon (or similar) that, when clicked, removes the tag from the list.
- Duplicate Handling: Prevent adding duplicate tags. Tags should be considered duplicates regardless of case (e.g., "react" and "React" are the same).
- Empty Tag Prevention: Do not add empty tags (i.e., tags consisting only of whitespace).
UI/UX expectations
- The input field should be clearly visible and allow text entry.
- Tags should be displayed horizontally, wrapping to the next line if space is limited, alongside the input field within a single bordered container.
- Each tag chip should have a distinct background and text color, making it easily distinguishable.
- The 'x' icon for removing tags should be clearly visible and clickable within each tag chip.
- After adding or removing a tag, the input field should retain focus, allowing for continuous tag entry.
- Consider basic accessibility for the input and tag removal buttons (e.g.,
aria-label).
Acceptance criteria
- User can type "frontend" and press
Enter to add "frontend" as a tag.
- User can type "javascript" and press
Tab to add "javascript" as a tag.
- Added tags appear as distinct chips within the tag input container.
- Clicking the 'x' icon on a "frontend" tag chip removes it from the list.
- Attempting to add "frontend" again (case-insensitive) when it already exists does not add a new chip.
- Pressing
Enter or Tab with an empty or whitespace-only input does not add a tag.
- The input field clears and retains focus after a tag is successfully added.