diff --git a/src/components/classes/blueprint-panel.tsx b/src/components/classes/blueprint-panel.tsx index 4511985..ac4cbcc 100644 --- a/src/components/classes/blueprint-panel.tsx +++ b/src/components/classes/blueprint-panel.tsx @@ -11,6 +11,7 @@ import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { SidePanel } from "@/components/ui/side-panel"; import { courseKindLabel } from "@/lib/course-kind"; +import { matchesSearch } from "@/lib/search-text"; import { useT } from "@/stores/preferences-context"; export function BlueprintPanel(props: { @@ -47,9 +48,9 @@ export function BlueprintPanel(props: { }); const visibleCourses = createMemo(() => { - const q = filter().trim().toLocaleLowerCase("tr-TR"); + const q = filter().trim(); if (!q) return props.courses; - return props.courses.filter((c) => c.title.toLocaleLowerCase("tr-TR").includes(q)); + return props.courses.filter((c) => matchesSearch(q, c.title)); }); const isSelected = (id: string) => selected().includes(id); diff --git a/src/components/layout/command-palette.tsx b/src/components/layout/command-palette.tsx index 33dd848..f5dca52 100644 --- a/src/components/layout/command-palette.tsx +++ b/src/components/layout/command-palette.tsx @@ -26,6 +26,7 @@ import { useAuth } from "@/stores/auth-context"; import { useModules } from "@/stores/modules-context"; import { usePreferences, useT } from "@/stores/preferences-context"; import { cn } from "@/lib/cn"; +import { matchesSearch } from "@/lib/search-text"; export type CommandPaletteProps = { open: boolean; @@ -289,7 +290,7 @@ export function CommandPalette(props: CommandPaletteProps) { }); const filteredItems = createMemo(() => { - const q = query().trim().toLocaleLowerCase(prefs.locale()); + const q = query().trim(); if (!q) return items(); const peopleLabel = t("command.group.people"); const found: CommandItem[] = (people.latest?.items ?? []).map((person) => ({ @@ -302,9 +303,7 @@ export function CommandPalette(props: CommandPaletteProps) { onSelect: () => void navigate({ to: "/admin/users/$id", params: { id: person.id } }), })); return [...found, ...items().filter((item) => - `${item.title} ${item.description ?? ""} ${item.keywords ?? ""} ${item.categoryLabel}` - .toLocaleLowerCase(prefs.locale()) - .includes(q), + matchesSearch(q, item.title, item.description, item.keywords, item.categoryLabel), )]; }); diff --git a/src/components/ui/data-table-search.tsx b/src/components/ui/data-table-search.tsx index 8a09489..13dd30e 100644 --- a/src/components/ui/data-table-search.tsx +++ b/src/components/ui/data-table-search.tsx @@ -18,8 +18,8 @@ export type DataTableSearchProps = { class?: string; }; -/** Rounded search field: leading icon, conditional clear (X) button, and an - * optional on-focus hint naming the fields it searches. */ +/** Rounded search field: leading icon, conditional clear (X) button, Escape to + * empty it, and an optional on-focus hint naming the fields it searches. */ export function DataTableSearch(props: DataTableSearchProps) { const t = useT(); const [focused, setFocused] = createSignal(false); @@ -34,6 +34,14 @@ export function DataTableSearch(props: DataTableSearchProps) { props.onChange(event.currentTarget.value)} + // Escape empties the box instead of only blurring it: a filter the + // keyboard cannot undo leaves the list silently narrowed. + onKeyDown={(event: KeyboardEvent) => { + if (event.key !== "Escape" || !props.value) return; + event.preventDefault(); + event.stopPropagation(); + props.onChange(""); + }} placeholder={props.placeholder ?? t("common.search")} aria-describedby={props.hint ? hintId : undefined} class={cn("h-8 rounded-lg bg-muted/40 text-[13px] md:text-[13px]", props.value ? "pl-9 pr-8" : "pl-9")} diff --git a/src/components/ui/searchable-select.test.tsx b/src/components/ui/searchable-select.test.tsx new file mode 100644 index 0000000..b5a5114 --- /dev/null +++ b/src/components/ui/searchable-select.test.tsx @@ -0,0 +1,45 @@ +import { cleanup, fireEvent, render, screen, waitFor } from "@solidjs/testing-library"; +import { afterEach, expect, it, vi } from "vitest"; +import { SearchableSelect } from "@/components/ui/searchable-select"; +import { PreferencesProvider } from "@/stores/preferences-context"; + +const OPTIONS = [ + { value: "m", label: "9-A · Matematik" }, + { value: "t", label: "10-B · Türkçe" }, +]; + +afterEach(cleanup); + +function renderSelect(onChange = vi.fn()) { + render(() => ( + + + + )); + return { input: screen.getByRole("combobox"), onChange }; +} + +it("finds an option across a dash and word order", async () => { + const { input } = renderSelect(); + + fireEvent.input(input, { target: { value: "9a matematik" } }); + + await waitFor(() => expect(screen.getByRole("option", { name: "9-A · Matematik" })).toBeTruthy()); + expect(screen.queryByRole("option", { name: "10-B · Türkçe" })).toBeNull(); +}); + +it("finds an option typed without its Turkish diacritics", async () => { + const { input } = renderSelect(); + + fireEvent.input(input, { target: { value: "turkce" } }); + + await waitFor(() => expect(screen.getByRole("option", { name: "10-B · Türkçe" })).toBeTruthy()); +}); + +it("says so when the search matches nothing", async () => { + const { input } = renderSelect(); + + fireEvent.input(input, { target: { value: "fizik" } }); + + await waitFor(() => expect(screen.getByText("No results.")).toBeTruthy()); +}); diff --git a/src/components/ui/searchable-select.tsx b/src/components/ui/searchable-select.tsx index d293fcc..184ad40 100644 --- a/src/components/ui/searchable-select.tsx +++ b/src/components/ui/searchable-select.tsx @@ -1,4 +1,4 @@ -import { createMemo } from "solid-js"; +import { Show, createMemo, createSignal } from "solid-js"; import { Combobox, ComboboxContent, @@ -9,13 +9,16 @@ import { ComboboxItemLabel, ComboboxTrigger, } from "@/components/ui/combobox"; +import { matchesSearch } from "@/lib/search-text"; +import { useT } from "@/stores/preferences-context"; export type SearchableOption = { value: string; label: string }; /** * Type-to-filter dropdown over a preloaded option list. Kobalte handles - * filtering, keyboard nav, ARIA and highlight. Drop-in for a native `