Frontend School

Product Catalog Tagging Component

Machine Coding
medium

Product Catalog Tagging Component

Medium
React
JavaScript
Front-end
UI/UX
State Management

Overview

Amazon's product catalog relies heavily on accurate tagging for search, categorization, and recommendation systems. Product managers frequently need to add and manage various tags for thousands of products. This problem focuses on building a robust and intuitive tag input component that allows users to easily add and remove tags.

What you need to do / Task

Your goal is to implement a TagInput React component that facilitates adding and removing tags.

  1. Tag Input Field: Render an input field where users can type tag names.
  2. Add Tags:
    • A tag should be added when the user types text into the input field and presses Enter or , (comma).
    • After adding a tag, the input field should be cleared.
  3. Display Tags: Display the added tags as individual, distinct "chips" below the input field.
  4. Remove Tags: Each tag chip should have a "remove" button (e.g., an 'X' icon) that, when clicked, removes the corresponding tag from the list.
  5. Handle Duplicates: Prevent the addition of duplicate tags. If a user tries to add a tag that already exists, it should not be added, and the input field should still clear.
  6. Empty Input: Do not add empty strings or strings consisting only of whitespace as tags.

UI/UX expectations

  • The input field should be clearly visible and allow text entry.
  • Tags should be rendered as distinct, visually separated "chips" or "pills" (e.g., with a background color, border, and rounded corners).
  • Each tag chip must include a visible and clickable element (e.g., an 'X' or 'Remove' button) to delete the tag.
  • Basic responsiveness is expected, ensuring the component looks reasonable on common screen sizes. Focus on functionality first.

Acceptance criteria

  • User can type text into the tag input field.
  • Pressing Enter adds the current input value as a tag.
  • Pressing , (comma) adds the current input value as a tag.
  • After adding a tag, the input field is cleared.
  • Added tags are displayed as visually distinct chips below the input.
  • Clicking the 'X' button on a tag chip removes it from the list.
  • Attempting to add an existing tag does not add a duplicate.
  • Empty or whitespace-only inputs do not create tags.

Constraints

Constraints & assumptions

  • Technology: Use React for the UI implementation.
  • Tag Limits: Assume a maximum of 10 tags can be added. If the limit is reached, new tags should not be added.
  • Tag Content: Tags should be alphanumeric strings. Each tag's length should be between 1 and 20 characters (inclusive).
  • No Backend: This is a purely client-side problem; no API integrations or data persistence are required. All state should be managed within the component.
  • Styling: Basic CSS styling is sufficient to meet UI/UX expectations. Focus on functional correctness over elaborate design.

Out of scope

  • Advanced tag features like auto-completion, suggestions, or categories.
  • Drag-and-drop reordering of tags.
  • Accessibility features beyond basic keyboard input for the text field.
  • Deep integration with external state management libraries (e.g., Redux).

What interviewers evaluate

  • Correctness: Does the component correctly implement adding, displaying, and removing tags, including handling edge cases like duplicates and empty input?
  • React Principles: Is the component state managed effectively using React hooks? Is the component well-structured and reusable?
  • Code Quality: Is the code clean, readable, maintainable, and well-organized?
  • UI/UX Implementation: Does the component meet the basic UI/UX expectations, providing a clear and interactive user experience?

Loading editor...