Skip to Content
BBRICKSv0.7.4
KitLists and tables

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.

sortSelect
KeyEnglishArabic
dirSort 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

  1. Wrapper (div.kit-sortsel).
  2. Field select: SelectBox with label ("Sort by").
  3. Direction button (button.kit-sortsel-dir): a 16px ⇅ SVG, aria-label "Sort direction: descending".

Variants

None.

States

StateTriggerLook
Valuevalue setThat field and direction
No valuevalue=nullFirst option with its default direction
No optionsoptions=[]Renders nothing
Focus-visibleTab to the toggleShared 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

Don't

  • Don't use it beside a sortable DataTable header.

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 to ListToolbar.
  • 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.

See also: BulkBar · CopyLink · CreatorCell · DataTable

Source

src/kit/patterns/SortSelect.tsx (line 18) on GitHub.

On this page