Frontend School

Dynamic Tag Editor for Playlists

Machine Coding
easy

Dynamic Tag Editor for Playlists

Easy
Machine Coding
React
Frontend
Tag Input
State Management

Overview

At Spotify, robust tools for managing content metadata are crucial. Tags are used across various features, from organizing user-generated content to categorizing internal data for recommendations. A well-designed tag input component significantly improves the usability of these tools.

This problem challenges you to build a dynamic tag editor for playlist metadata, enabling users to easily add, view, and remove tags associated with a playlist.

What you need to do / Task

Your primary task is to create a reusable TagInput React component that fulfills the following requirements:

  1. Display Existing Tags: The component should accept an initial list of tags and render them visually.
  2. Add New Tags: Users must be able to add new tags by:
    • Typing text into an input field and pressing the Enter key.
    • Typing text into an input field and pressing the comma (,) key.
  3. Remove Tags: Each displayed tag must have a clickable 'x' button (or similar icon) that removes the tag when clicked.
  4. Input Clearing: After a tag is successfully added, the input field should automatically clear.
  5. Prevent Duplicates: The component must prevent adding tags that are already present in the list (case-insensitive comparison).
  6. Validate Tag Length: Tags should not exceed a maximum length (e.g., 20 characters).
  7. Handle Empty Input: Submitting an empty string should not create a new tag.
  8. Propagate Changes: The component should notify its parent whenever the list of tags changes.

UI/UX expectations

  • Visual Distinction: Tags should appear as distinct, visually separated elements (e.g., rounded rectangles or badges).
  • Clear Input: Provide a clear and accessible input field for adding new tags.
  • Removal Mechanism: Each tag should clearly display an interactive element (e.g., an 'x' icon) for removal.
  • Focus Management: The input field should ideally retain focus after adding or removing a tag to allow for continuous input, enhancing user flow.
  • Basic Accessibility: Ensure interactive elements (input, remove buttons) are keyboard navigable and have appropriate labels if needed.

Acceptance criteria

  • User can type text into the input field and press Enter to add a new tag.
  • User can type text into the input field and press comma (,) to add a new tag.
  • Newly added tags are immediately visible within the component.
  • Clicking the 'x' button on an existing tag successfully removes it from the display.
  • Attempting to add a duplicate tag (case-insensitive) does not result in its addition.
  • Attempting to add a tag with an empty string (or only whitespace) does not create a new tag.
  • Attempting to add a tag exceeding the maximum allowed length is prevented.
  • The input field clears automatically after a tag has been successfully added.
  • The parent component (App) receives updated tags via the onTagsChange prop.

Constraints

Constraints & assumptions

  • You should use React functional components with hooks.
  • No external UI component libraries (e.g., Material UI, Ant Design) are allowed. Basic HTML and CSS should be used for styling.
  • Maximum number of tags allowed: 10.
  • Maximum character length for a single tag: 20 characters.
  • Tags are simple string values; no complex objects or nested data structures.
  • Case-insensitive comparison for detecting duplicate tags (e.g., "rock" is a duplicate of "Rock").
  • The component should be robust enough to handle various user inputs gracefully.

Out of scope

  • Backend integration or data persistence.
  • Advanced features like tag auto-completion, drag-and-drop reordering, or tag categories.
  • Complex, pixel-perfect styling beyond what's necessary to meet UI/UX expectations.

What interviewers evaluate

  • Correct and robust implementation of core tag input functionalities (add, remove, validation).
  • Effective use of React state management and component lifecycle.
  • Clean, readable, and maintainable code structure.
  • Attention to basic UI/UX principles and accessibility considerations.

Loading editor...