Back

Color Swatch

easy

Streak

0 days

Progress

0%

Submitted

0

Color Swatch

React25 mineasyFree

Prompt

Build this React exercise in 25 minutes.

Build a 12-preset color picker and custom hex input. Start at #3b82f6. Accept exactly #RGB or #RRGGBB, case-insensitively, normalize committed colors to lowercase six-digit hex, and preserve raw partial input. Do not trim or accept named colors. Invalid input keeps the last valid preview.

Acceptance checks

  • Clicking any preset synchronizes preview, input, text, pressed state, and selection marker.
  • Typing #F00 commits #ff0000 and selects its matching preset; raw input stays #F00.
  • Typing #, #12, #xyz, or an empty string keeps the last valid color and shows an associated error.
  • All 12 controls and the input work by keyboard; a text marker and aria-pressed identify the selected preset.

The checks are a manual interview checklist; saving a submission does not execute them.

Learn and continue

Prerequisite: Controlled inputs. Work through the React Machine Coding Foundations path to practice related skills in order.

Requirements

  • →Clicking any preset synchronizes preview, input, text, pressed state, and selection marker.
  • →Typing #F00 commits #ff0000 and selects its matching preset; raw input stays #F00.
  • →Typing #, #12, #xyz, or an empty string keeps the last valid color and shows an associated error.
  • →All 12 controls and the input work by keyboard; a text marker and aria-pressed identify the selected preset.

Starter packet

What the interviewer handed you

Build a 12-preset color picker and custom hex input. Start at #3b82f6. Accept exactly #RGB or #RRGGBB, case-insensitively, normalize committed colors to lowercase six-digit hex, and preserve raw partial input. Do not trim or accept named colors. Invalid input keeps the last valid preview.

Manual acceptance checks

  • Clicking any preset synchronizes preview, input, text, pressed state, and selection marker.
  • Typing #F00 commits #ff0000 and selects its matching preset; raw input stays #F00.
  • Typing #, #12, #xyz, or an empty string keeps the last valid color and shows an associated error.
  • All 12 controls and the input work by keyboard; a text marker and aria-pressed identify the selected preset.

Likely follow-ups

  • • How would you commit only on blur or Enter instead of each valid keystroke?
Example
Loading preview...
For the best coding experience, we recommend using a desktop device.
Preparing Sandbox...
Premium interview report

What interviewers score in this build

Use this before reading the code. It tells you what to say, what to test, and where machine-coding candidates usually lose points.

Interview signals

  • State and behavior: Clicking any preset synchronizes preview, input, text, pressed state, and selection marker.
  • Edge cases: All 12 controls and the input work by keyboard; a text marker and aria-pressed identify the selected preset.
  • Explanation: Explain the state model and demonstrate the acceptance checks.

Time checkpoints

  1. 1

    0:00: Read the contract and inspect the fixtures.

  2. 2

    8:00: Complete the state and interaction handlers.

  3. 3

    16:00: Check keyboard use and boundary behavior.

  4. 4

    25:00: Run every acceptance check and explain tradeoffs.

Edge-case checklist

Clicking any preset synchronizes preview, input, text, pressed state, and selection marker.
Typing #F00 commits #ff0000 and selects its matching preset; raw input stays #F00.
Typing #, #12, #xyz, or an empty string keeps the last valid color and shows an associated error.
All 12 controls and the input work by keyboard; a text marker and aria-pressed identify the selected preset.

Common mistakes

  • How would you commit only on blur or Enter instead of each valid keystroke?
SolutionRead-only · Live Preview

Technical Explanation

Draft and committed values

The input is a draft: update it on every keystroke. The preview is a committed color: update it only after validation. A single shared state would either erase partial input or send invalid colors to the preview.

Compare normalized colors

Expand each shorthand digit twice and lowercase the result. Thus #F00 and #ff0000 compare equal. Keep the draft unchanged so typing does not jump the cursor.

Describe the result

The selected hex remains visible outside the colored preview. Preset buttons expose a pressed state and a non-color marker. The labeled input associates its validation message using a unique ID.

Interview Criteria

State and behavior

Clicking any preset synchronizes preview, input, text, pressed state, and selection marker.

Edge cases

All 12 controls and the input work by keyboard; a text marker and aria-pressed identify the selected preset.

Explanation

Explain the state model and demonstrate the acceptance checks.

Time Checkpoints

0:00

0:00: Read the contract and inspect the fixtures.

8:00

8:00: Complete the state and interaction handlers.

16:00

16:00: Check keyboard use and boundary behavior.

25:00

25:00: Run every acceptance check and explain tradeoffs.

Streak

0 days

Last active: Sign in to track

Progress

0%

0/0 solved

Submitted

0

Solutions pushed to review history.

More Machine Coding

View all Machine Coding →
Machine CodingMedium

React Tic-Tac-Toe Engine

Machine CodingMedium

Performant Image Slider

Machine CodingMedium

API Search and Render Image

Machine CodingEasy

Accessible React Tabs

Machine CodingMedium

Recursive File Explorer

Machine CodingEasy

Stopwatch

Related hubs

  • All machine coding
  • Frontend machine coding guide
  • React machine coding questions
  • UI coding interview questions
  • React UI interview questions
  • Adobe interview
  • ClickUp interview
  • Stripe interview