Overview
In ServiceNow, effective data categorization is paramount for efficient incident management, knowledge base organization, and robust reporting. A flexible and intuitive tag input component is a common requirement across various forms and interfaces, allowing users to quickly classify records. This problem challenges you to build a dynamic tag input component that allows users to add and remove tags seamlessly, enhancing data entry and improving user experience.
What you need to do / Task
Your primary goal is to implement a React component that functions as a tag input field. Specifically, you must:
- Render an input field: This field will be used for typing new tags.
- Display existing tags: Render current tags as visual 'pills' or 'badges' within the component, preceding the input field.
- Add new tags: Allow users to add a new tag by typing text into the input field and pressing
Enter or , (comma).
- Remove existing tags: Provide a mechanism for users to remove a tag, either by clicking an 'X' button associated with each tag or by pressing
Backspace when the input field is empty (to remove the most recently added tag).
- Handle duplicates: Prevent the addition of tags that already exist in the list (case-insensitive).
- Basic validation: Do not allow empty tags to be added, and enforce a maximum tag length.
UI/UX expectations
- The input field should be clearly visible and functional.
- Each tag should be rendered as a distinct visual element (e.g., a rounded rectangle with text and a small 'X' button for removal).
- The 'X' button on each tag should be easily clickable.
- After adding a tag, the input field should clear automatically.
- When removing a tag, the visual element should disappear instantly.
- The input field should remain focused after adding/removing a tag to facilitate continuous entry.
Acceptance criteria
- Users can type a tag and press
Enter to add it to the list.
- Users can type a tag and press
, (comma) to add it to the list.
- Clicking the 'X' button on a tag successfully removes it from the list.
- Pressing
Backspace when the input field is empty removes the last tag in the list.
- Attempting to add a duplicate tag (case-insensitive) does not add it to the list.
- Attempting to add an empty tag (e.g., just pressing
Enter or , without text) does not add it.
- Tags exceeding
MAX_TAG_LENGTH are not added.
- The input field value clears after a tag is successfully added.
- The input field remains focused after tag operations (add/remove).