Skip to content
Cynosurev0.5.0
SearchStorybookGitHubnpmColour mode: System. Switch to Light

Components / More

SortButton

The button in a sortable column's header: the header text and an icon that shows the sort. Table and DataGrid render it for their sortable columns.

Default

When to useLink to "When to use"

Use Table or DataGrid and mark columns sortable: they render SortButton for you. Reach for it directly only in a table of your own, inside a header cell that carries aria-sort.

Use something else when the control sorts a whole list from outside it (a Select of sort orders) or toggles an option (Button with pressed).

UsageLink to "Usage"

tsx
Copy
import { SortButton } from "@arshad-shah/cynosure";

<th aria-sort={sort?.key === "name" ? sort.direction : "none"}>
  <SortButton direction={sort?.key === "name" ? sort.direction : undefined} onClick={() => cycleSort("name")}>
    Name
  </SortButton>
</th>

fill makes it fill a fixed-height header cell, as in DataGrid; align="end" puts the icon before the label for numeric columns.

Fills its cell

PropsLink to "Props"

Every prop of SortButton
PropWhat it doesTypeDefault
children
The column's header text. It is cut short with an ellipsis when the column is too narrow.ReactNode
direction
How the column is sorted now; nothing when it is not. The icon follows it.SortDirection
onClick
Pressed: change the sort (Table and DataGrid cycle ascending, descending, unsorted with nextSort).(() => void)
fill
Fill the header cell (a data grid's fixed-height header); otherwise the button is as wide as its label.boolean
align
end (a numeric column) puts the icon before the label, so the label lines up with the values."start" | "end"
tabIndex
Tab order: a grid with one tab stop sets -1 on all but the active header.number
aria-keyshortcuts
The shortcuts the header also answers to (a resizable column's Alt+arrows).string
data-cell
A grid's cell coordinates, for its keyboard navigation.string
className
Added to the root element, for layout.string

Generated from the type definitions in @arshad-shah/cynosure 0.5.0.

Behaviour and accessibilityLink to "Behaviour and accessibility"

Behaviour and accessibility, table 1
KeyDoes
Enter, SpacePress: change the sort
  • The icon follows direction: both ways when unsorted, an arrow up for ascending, down for descending. It is decorative: the header cell's aria-sort says how the column is sorted.
  • A sorted column's button is drawn in the ink colour; an unsorted one takes the header's colour.
  • A long header is cut short with an ellipsis rather than overflowing its column.
  • tabIndex, aria-keyshortcuts and data-cell reach the button, for a grid with one tab stop.

TouchLink to "Touch"

The hit area is at least 24px tall, and 44px on touch screens; a filling button takes its cell's height.

ThemingLink to "Theming"

Tokens: --cy-sort-button-padding (inline padding when it fills its cell, default --cy-space-4). Colours come from the header around it.

Table, DataGrid.

These examples run Cynosure 0.5.0 (commit 50ce30b), the version on npm.

Getting started
Theming
Icons
Accessibility
Code editors and highlighters
Using Cynosure without React
Build-tool adapters
Components
Accordion
AppShell
AspectRatio
Breadcrumbs
Calendar
Card
Container
Disclosure
Divider
DocumentViewport
Grid
Inline
PageHeader
PanZoomCanvas
ScrollArea
SideNav
SortableList
SplitPane
Stack
StatusBar
Tabs
TitleBar
Toolbar
Tree
VirtualList
ZoomControls
Announcer
Avatar
Badge
CodeBlock
DescriptionList
EmptyState
ErrorBoundary
Field
Heading
IconTile
Image
Kbd
List
LoadingDots
Notice
ProgressBar
Prose
Skeleton
Stat
Steps
Table
Text
Button
Checkbox
Checklist
ColorField
ColorSwatches
Combobox
CompareSlider
CopyButton
DateField
FileDrop
IconButton
KeyValueEditor
Link
NumberField
Pagination
PathField
RadioGroup
SearchField
SegmentedControl
Select
SelectionFrame
SignaturePad
Slider
Switch
TagInput
TextArea
TextField
ThemeToggle
TimeField
ButtonBase
ChoiceBase
DialogBase
FileInputBase
HiddenValue
Icon
InputBase
LinkBase
LiveRegion
TextAreaBase
ChatMessage
Choice
DataGrid
DeviceFrame
HighlightedText
HotkeyField
ListRow
OptionList
OverlayFrame
QRCode
RowActions
Section
SiteFooter
SiteHeader
SkipLink
SortButton
VisuallyHidden
CommandPalette
ContextMenu
Dialog
FloatingToolbar
HoverCard
Menu
Menubar
Popover
ProgressOverlay
Sheet
Toast
Tooltip
Changelog