feat(dashboard) modal search autofocus (#9038)

**What**
- autofocus search input on route modal that have tables

---

CLOSES CC-132
This commit is contained in:
Frane Polić
2024-09-11 10:12:34 +02:00
committed by GitHub
parent d398009d3f
commit 28dc8d4d17
17 changed files with 28 additions and 19 deletions

View File

@@ -4,7 +4,7 @@ import { DataTableOrderBy } from "../data-table-order-by"
import { DataTableSearch } from "../data-table-search"
export interface DataTableQueryProps {
search?: boolean
search?: boolean | "autofocus"
orderBy?: (string | number)[]
filters?: Filter[]
prefix?: string
@@ -25,7 +25,12 @@ export const DataTableQuery = ({
)}
</div>
<div className="flex shrink-0 items-center gap-x-2">
{search && <DataTableSearch prefix={prefix} />}
{search && (
<DataTableSearch
prefix={prefix}
autofocus={search === "autofocus"}
/>
)}
{orderBy && <DataTableOrderBy keys={orderBy} prefix={prefix} />}
</div>
</div>

View File

@@ -8,11 +8,13 @@ import { useSelectedParams } from "../hooks"
type DataTableSearchProps = {
placeholder?: string
prefix?: string
autofocus?: boolean
}
export const DataTableSearch = ({
placeholder,
prefix,
autofocus,
}: DataTableSearchProps) => {
const { t } = useTranslation()
const placeholderText = placeholder || t("general.search")
@@ -50,6 +52,7 @@ export const DataTableSearch = ({
name="q"
type="search"
size="small"
autoFocus={autofocus}
defaultValue={query?.[0] || undefined}
onChange={debouncedOnChange}
placeholder={placeholderText}

View File

@@ -41,7 +41,7 @@ export const DataTable = <TData,>({
<TableSkeleton
layout={layout}
rowCount={pageSize}
search={search}
search={!!search}
filters={!!filters?.length}
orderBy={!!orderBy?.length}
pagination={!!pagination}