Question presented to candidate: "Designers want to pick a brand colour in our settings page. Build a colour picker: hue, saturation and lightness sliders, a hex text field they can type or paste into, a row of preset swatches, a live preview, and a button that copies the hex value."
Requirements:
- Three sliders for H (0 to 360), S and L (0 to 100), a hex field that accepts
#RGBor#RRGGBB(the#optional, any case), and eight preset swatches. - Every control updates the others; the preview shows the hex, the
rgb()value and readable text on top (black or white, chosen by contrast). - An unfinished or invalid hex does not change the colour and is flagged; leaving the field normalises it (for example
#fc0becomes#FFCC00). - "Copy" writes the hex to the clipboard and shows a short confirmation, or a fallback message when the Clipboard API is unavailable.
- The parent receives the hex on every change.
- Accessible: labelled sliders with spoken values, swatches as named toggle buttons, a status message.
What a strong answer should cover:
- Choosing one canonical colour state and deriving the rest, and why the hex text needs its own draft state.
- Correct HSL to RGB to hex conversions, and the precision trap of storing rounded HSL.
- The WCAG contrast ratio for picking black or white text.
navigator.clipboard.writeTextbeing asynchronous, needing a secure context, and failing; a timer that is cleaned up on unmount.- ARIA:
aria-valuetexton sliders,aria-pressedon swatches,aria-invalidon the field.
Clarifying questions expected:
- "Which colour models must the user see: HSL, RGB, both? Is alpha needed?"
- "Should the parent get every intermediate value while dragging, or only the final one?"
- "Is there a fixed brand palette for the swatches?"
Code / implementation expected: Yes. A working picker with sliders, hex field, swatches, preview and copy; conversion functions that are separate and testable.