SortSelect
"Sort by [field ▾] [⇅]" for lists that cannot sort from a header (card grids, mobile). Options are (key, default direction, label); the toggle flips the current direction without changing the field.
Deprecated
Since 0.2.0: use ListToolbar sort (options [key, label, dir], onChange(key, dir), onFlip).
Still works unchanged; removed once the Brand Console has moved (MIGRATION.md).
import { SortSelect } from '@ergasti/bricks';Examples
Sort by
Deprecated since 0.2.0: use the sort prop of ListToolbar, which does the same with [key, label, dir] options.
Code
import { useState } from 'react';
import { SortSelect, type SortValue } from '@ergasti/bricks';
function Sort() {
const [sort, setSort] = useState<SortValue | null>({ key: 'sales', dir: 'desc' });
return <SortSelect id="docs-sort" label="Sort by" value={sort} onChange={setSort} options={[{ key: 'sales', dir: 'desc', label: 'Sales' }, { key: 'name', dir: 'asc', label: 'Name' }]} />;
}Props
Prop
Type
Labels
Every word this component draws, in both languages. Override one per component and language with BricksProvider labels under the key sortSelect, or with the component's own prop where it has one. A {name} is a value the component fills in.
| Key | English | Arabic |
|---|---|---|
dir | Sort direction: descending | اتجاه الترتيب: تنازلي |
Design guidance
How the BRICKS design system uses SortSelect. Written in docs/content/components/SortSelect.md; the props above are read from the code, which wins where the two disagree.
A "Sort by [field] [⇅]" control for lists that cannot sort from a column header (card grids, phones); deprecated since 0.2.0 in favour of ListToolbar's sort.
SortSelect pairs a SelectBox of fields with a direction toggle button. Choosing a field applies that field's default direction; the toggle flips the direction without changing the field. An unknown value.key shows and toggles the first option, never a stale key. It still works unchanged and will be removed once the Brand Console has moved (see MIGRATION.md).
Anatomy
- Wrapper (
div.kit-sortsel). - Field select:
SelectBoxwithlabel("Sort by"). - Direction button (
button.kit-sortsel-dir): a 16px ⇅ SVG,aria-label"Sort direction: descending".
Variants
None.
States
| State | Trigger | Look |
|---|---|---|
| Value | value set | That field and direction |
| No value | value=null | First option with its default direction |
| No options | options=[] | Renders nothing |
| Focus-visible | Tab to the toggle | Shared focus ring |
Usage
<SortSelect id="fc-sort" label="Sort by" value={sort} onChange={setSort}
options={[{ key: 'sales', dir: 'desc', label: 'Sales' }, { key: 'name', dir: 'asc', label: 'Name' }]} />Migrate to ListToolbar:
<ListToolbar sort={{ label: 'Sort by', value: sort.key, dir: sort.dir,
options: [['sales', 'Sales', 'desc'], ['name', 'Name', 'asc']],
onChange: (key, dir) => setSort({ key, dir }), onFlip: () => setSort({ ...sort, dir: sort.dir === 'asc' ? 'desc' : 'asc' }) }} />Where it appears
- Deprecated; kit gallery only. v3 screens use
ListToolbar sort(Find creators, Payments orders).
Guidelines
Do
- Move to
ListToolbarsortin new code.
Don't
- Don't use it beside a sortable
DataTableheader.
RTL and Arabic
- Follows the page direction.
Tokens
Via SelectBox; shared focus ring.
Accessibility
- The field is a native
<select>with a real<label>("Sort by"). - The direction toggle is a native button named with the current direction ("Sort direction: descending" / "اتجاه الترتيب: تنازلي"); its glyph is hidden. It does not say what pressing it will do, so keep the label next to it.
- Focus: the shared ring on the toggle (
--focus-ring). The toggle is not in the kit's touch hit-area list, so it keeps its drawn size on touch screens; one more reason to move toListToolbar. - Changing the sort does not announce the new order; the list's own result summary should.
Found in the source
- ARIA attributes set:
aria-label,aria-hidden.
Read from the component's source and tests. See Accessibility for the patterns the library follows.
Related
ListToolbar(sort): the replacement.SelectBox.
See also: BulkBar · CopyLink · CreatorCell · DataTable
Source
src/kit/patterns/SortSelect.tsx (line 18) on GitHub.