Overview
Sharechat relies heavily on user-generated content, and effective content categorization through tagging is crucial for discoverability and recommendation. A robust and intuitive tagging experience significantly improves user engagement. This problem challenges you to build a flexible and user-friendly Combobox component that allows users to select multiple tags from a predefined list, search through them, and even create new tags on the fly.
What you need to do / Task
Your primary task is to build a Combobox React component that facilitates multi-selection of tags.
- Display Initial Tags: The component should initialize with a predefined list of available tags.
- Search and Filter: As the user types into the input field, the dropdown list should dynamically filter and display matching tags. The search should be case-insensitive.
- Multiple Selection: Users should be able to select multiple tags. Selected tags should be removed from the available options in the dropdown and displayed as "pills" below the input field.
- Add New Tags: If the user types a tag that doesn't exist in the current filtered list, an option to "Add new tag: [User Input]" should appear in the dropdown. Selecting this option should add the new tag to the list of selected tags and also make it available for future searches.
- Remove Selected Tags: Each selected tag (pill) should have a dismiss button (e.g., 'x') allowing the user to remove it. When a tag is removed, it should become available again in the dropdown list for selection.
- Keyboard Navigation: Implement basic keyboard navigation for the dropdown list:
ArrowUp/ArrowDown: Navigate between items in the dropdown.
Enter: Select the currently highlighted item or add a new tag if "Add new tag" is highlighted.
- Clear Input: After a tag is selected (either existing or new), the input field should be cleared.
UI/UX expectations
- Input Field: A standard text input where users type their search query.
- Dropdown List: A list of available tags that appears below the input when it's focused or has input.
- Highlighting: The currently navigated item in the dropdown should be visually highlighted.
- Selected Tags: Display selected tags as distinguishable "pill" components below the input field, each with a clear 'x' button for removal.
- "Add new tag" option: This option should be clearly distinguishable in the dropdown when applicable.
- Clear State: The input field should reset after a tag is selected.
Acceptance criteria
- The Combobox component renders with an input field and initially no selected tags.
- Typing in the input field filters the dropdown list of available tags in a case-insensitive manner.
- Selecting an existing tag from the dropdown adds it to the selected tags and clears the input.
- If the typed text doesn't match existing tags, an "Add new tag: [text]" option appears in the dropdown.
- Selecting the "Add new tag" option adds the new tag to selected tags and the overall available tags, then clears the input.
- Selected tags are displayed as dismissible "pills" below the input.
- Clicking the 'x' on a selected tag pill removes it from selected tags and makes it available for selection again.
- Pressing
ArrowUp and ArrowDown keys navigates through the dropdown options.
- Pressing
Enter selects the highlighted option or adds a new tag.
- Maximum of 5 tags can be selected.