Skip to content
FrontDepth, Home

Sort dropdown

Code ReviewJunior
Target
find the 2 must-fix problems (3 in all)
Your best
Not played yet

Pull request

Custom sort dropdown · design/sort-dropdown

The native <select> could not be styled like the new design, so this pull request replaces it with a custom dropdown. It looks like the mockup and works with a mouse.

SortPicker stays controlled by the product page: the page passes value and onChange, and its Clear filters button sets the sort back to Relevance.

Your teammate wrote it with an AI assistant. Review it before it is merged: comment on every line that has to change, and give each comment a category.

Hints

    Your comments

      Scoring: a comment finds a problem when it is on the problem's lines (or one line around them) and names its category. The score is the share of problems found, minus half a problem for each comment that finds nothing new. Find every must-fix problem, with no more such comments than there are problems, to complete the challenge. Only your first review is scored.

      1import { useState } from "react";
      2
      3const OPTIONS = [
      4 { value: "relevance", label: "Relevance" },
      5 { value: "price-asc", label: "Price: low to high" },
      1 unchanged lines
      7 { value: "newest", label: "Newest" },
      8];
      9
      10// A custom dropdown that matches the design (the native select could not be styled).
      11export function SortPicker({ value, onChange }) {
      12 const [open, setOpen] = useState(false);
      13 const [selected, setSelected] = useState(value);
      14 const current = OPTIONS.find((option) => option.value === selected);
      15
      16 function choose(option) {
      17 setSelected(option.value);
      18 onChange(option.value);
      19 setOpen(false);
      20 }
      21
      22 return (
      23 <div className="sort">
      11 <label htmlFor="sort">Sort by</label>
      12 <select id="sort" value={value} onChange={(e) => onChange(e.target.value)}>
      13 {OPTIONS.map((option) => (
      14 <option key={option.value} value={option.value}>
      15 {option.label}
      16 </option>
      17 ))}
      18 </select>
      24 <span className="sort-label">Sort by</span>
      25 <div className="sort-trigger" onClick={() => setOpen(!open)}>
      26 {current.label}
      27 </div>
      28 {open && (
      29 <ul className="sort-options">
      30 {OPTIONS.map((option) => (
      31 <li
      32 key={option.value}
      33 className={option.value === selected ? "selected" : ""}
      34 onClick={() => choose(option)}
      35 >
      36 {option.label}
      37 </li>
      38 ))}
      39 </ul>
      40 )}
      41 </div>
      42 );
      43}