Skip to content

TableToolbar

The bar above a table or a list: what you are looking at on one side, what you can do with it on the other. On a phone the actions sit two by two.

import { TableToolbar } from '@sypnia/ui/react'

On this page
  1. Search and actions
  2. Name and count
  3. When to use it
  4. For everyone
  5. Props

Search and actions

A search field at the start; columns, export and the main action at the end.

Code
import { useState } from 'react';
import { Button, ColumnPicker, SearchInput, TableToolbar } from '@sypnia/ui/react';

const columns = [{ id: 'name', header: 'Name' }, { id: 'email', header: 'Email' }, { id: 'role', header: 'Role' }, { id: 'joined', header: 'Joined' }];

// What you are looking at on one side, what you can do with it on the other. On a phone the actions sit two by two.
export default function Basic() {
  const [hidden, setHidden] = useState<string[]>(['joined']);
  const [query, setQuery] = useState('');
  return (
    <TableToolbar label="Members"
      actions={<>
        <ColumnPicker columns={columns} hidden={hidden} onChange={setHidden} />
        <Button size="sm" icon="download">Export CSV</Button>
        <Button size="sm" variant="primary" icon="plus">Invite</Button>
      </>}>
      <SearchInput size="sm" aria-label="Search members" placeholder="Name or email" value={query} onChange={(e) => setQuery(e.target.value)} />
    </TableToolbar>
  );
}

Name and count

When there is nothing to search, the start says what the list is and how many there are.

Invoices 48
Code
import { Badge, Button, TableToolbar } from '@sypnia/ui/react';

// The start can be just the name of the list and how many there are.
export default function WithCount() {
  return (
    <TableToolbar label="Invoices"
      actions={<>
        <Button size="sm" icon="filter">Filters</Button>
        <Button size="sm" icon="download">Export CSV</Button>
      </>}>
      <strong>Invoices</strong> <Badge>48</Badge>
    </TableToolbar>
  );
}

When to use it

Use it when

  • A list has things to do with all of it: search, filter, choose columns, export, create.
  • Put the search or the name of the list at the start, and the actions at the end, the main one last.
  • DataTable draws its own toolbar; pass more buttons to it with toolbar.

Do not use it when

  • The actions belong to one row: RowActions.
  • They belong to the selected rows: BulkActionBar.
  • It is the top of a page: PageHeader.

For everyone

  • It is a group with a name (label), so a screen reader says what the buttons belong to.
  • On phones the actions sit two by two and every button is at least 44 px; nothing scrolls sideways.

Props

TableToolbarTypeDefault
actions

What can be done with the table, at the end: filter, choose columns, export, create.

ReactNode
children

What sits at the start: a search field, the name of the table, a count.

ReactNode
label

A name for screen readers.

string
  1. Search and actions
  2. Name and count
  3. When to use it
  4. For everyone
  5. Props

    Search pages, sections and terms