fix(dashboard): match the range picker to the log toolbar controls

Next to the new Select and Input the range picker was shorter, lighter
bordered and had no focus ring, so the toolbar looked uneven and a
keyboard user could not see which range had focus. It now shares their
height, border and focus ring, and its buttons are grouped under one
accessible name.

Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
This commit is contained in:
ZverGuy committed 2026-11-04 18:48:43 +07:00
1 parent b88ad09678
commit f5ebb43c4b
2 files changed
+25 -2

No files matched your search

@@ -0,0 +1,23 @@
import { describe, it, expect, vi } from "vitest"
import { render, screen, within } from "@testing-library/react"
import userEvent from "@testing-library/user-event"
import { RangePicker } from "./RangePicker.tsx"
describe("RangePicker", () => {
it("groups the ranges under one name and marks the chosen one pressed", () => {
render(<RangePicker options={["1h", "6h"]} value="6h" onChange={() => {}} />)
const group = screen.getByRole("group", { name: "Time range" })
expect(within(group).getByRole("button", { name: "6h" })).toHaveAttribute("aria-pressed", "true")
expect(within(group).getByRole("button", { name: "1h" })).toHaveAttribute("aria-pressed", "false")
})
it("reports the range clicked", async () => {
const onChange = vi.fn()
render(<RangePicker options={["1h", "6h"]} value="6h" onChange={onChange} />)
await userEvent.click(screen.getByRole("button", { name: "1h" }))
expect(onChange).toHaveBeenCalledWith("1h")
})
})
@@ -10,7 +10,7 @@ export function RangePicker<K extends string>({
onChange: (value: K) => void
}) {
return (
<div className="inline-flex rounded-md border border-slate-200 bg-white p-0.5">
<div role="group" aria-label="Time range" className="inline-flex h-7 items-center rounded-lg border border-slate-300 bg-white p-0.5 shadow-xs">
{options.map((key) => (
<button
key={key}
@@ -18,7 +18,7 @@ export function RangePicker<K extends string>({
aria-pressed={value === key}
onClick={() => onChange(key)}
className={cn(
"rounded px-2.5 py-1 text-xs",
"h-full rounded-md px-2.5 text-xs outline-none focus-visible:ring-2 focus-visible:ring-slate-400",
value === key ? "bg-slate-900 text-white" : "text-slate-600 hover:bg-slate-100",
)}
>