Frontend School

Interactive Combobox for Content Tagging

Machine Coding
medium

Interactive Combobox for Content Tagging

Medium
React
JavaScript
TypeScript
UI
Combobox
Autocomplete
Machine Coding

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.

  1. Display Initial Tags: The component should initialize with a predefined list of available tags.
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. 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.
  7. 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.

Constraints

Constraints & assumptions

  • You must use React for building the UI.
  • The initial list of tags will be provided as a static array of strings.
  • The maximum number of selected tags is 5. Once 5 tags are selected, the input field should either be disabled or prevent further selections.
  • No backend integration is required. All tag management (adding new, filtering) should happen client-side.
  • Focus on functionality and clean component architecture. Basic styling to make the component usable is sufficient; extensive visual polish is not expected.
  • The problem targets a ~45 minute completion time for an L4 candidate, so prioritize core functionality.

Out of scope

  • Advanced accessibility features beyond basic keyboard navigation.
  • Debouncing for the search input.
  • Persistence of selected or newly added tags across page loads.
  • Comprehensive error handling or input validation (e.g., empty tag names).
  • Drag-and-drop reordering of tags.

What interviewers evaluate

  • Component Architecture and State Management: How well the Combobox component is structured, its internal state managed, and how it handles data flow.
  • Filtering and Search Logic: The correctness and efficiency of the tag filtering mechanism.
  • UI/UX Implementation: Accuracy in displaying selected tags, handling new tag creation, and implementing keyboard interactions.
  • Code Quality: Readability, maintainability, and adherence to React best practices.

Loading editor...