# action.sort

Sorts a table by a column: the button inside its th. Put aria-sort="ascending" or "descending" on the th of the sorted column; the arrow follows it

Component: [`<Action>`](https://www.prongs.dev/docs/components/action.md) · Renders: `<button>` · Profile: [UI](https://www.prongs.dev/docs/intents/ui.md)

## Example

```tsx
<Action intent="action.sort" onClick={sortItem}>Sort</Action>
```

Code that says `sort`, `order`, `column` points here. `prongs check` warns when an element with this intent has a handler or label that points somewhere else.

## Choosing between neighbours

Find the row that describes your element, and use the intent on the right.

| If it is for… | Use |
|---|---|
| Sorts a table by a column: the button inside its th. Put aria-sort="ascending" or "descending" on the th of the sorted column; the arrow follows it | `action.sort` (this page) |
| Picking a sort order from a list of choices | [`choice.open`](https://www.prongs.dev/docs/intents/choice/open.md) |
| Sorting a table by one of its columns (rather than [`action.utility`](https://www.prongs.dev/docs/intents/action/utility.md)) | `action.sort` (this page) |

## Connections

Declared in the registry, both directions. Where an intent is used in your own code is something check and the gallery see; this site has no app code.

- Built from: [`control.quiet`](https://www.prongs.dev/docs/intents/ui.md#control-quiet)

## For registry authors

**Starter intents.** These are the intents `prongs add` puts in your registry, shown in this site’s theme. Yours are your own `registry.ts`: rename, restyle and add to them, and see them with `prongs add gallery`.

What this intent is built from and its entry in `components/prongs/registry.ts`. You only need this to change how it looks or to add an intent like it.

How action.sort resolves, and its definition

Each layer adds to the one before it; a later class wins over an earlier one that sets the same thing.

- [`control.base`](https://www.prongs.dev/docs/intents/ui.md#control-base) — Shape and behaviour shared by every button

  ```
  inline-flex shrink-0 items-center justify-center gap-2
  whitespace-nowrap rounded-md px-4 py-2 text-sm transition-colors
  focus-visible:outline-none focus-visible:ring-2
  focus-visible:ring-ring focus-visible:ring-offset-2
  ring-offset-surface disabled:pointer-events-none
  disabled:opacity-50 aria-disabled:pointer-events-none
  aria-disabled:opacity-50
  ```

- [`control.quiet`](https://www.prongs.dev/docs/intents/ui.md#control-quiet) — Small text command; shows a pressed state

  ```
  h-auto px-0 py-0 text-muted-foreground hover:text-foreground
  hover:underline underline-offset-4 aria-pressed:text-foreground
  ```

- `action.sort` (this page) — Sorts a table by a column: the button inside its th. Put aria-sort="ascending" or "descending" on the th of the sorted column; the arrow follows it

  ```
  gap-1 font-medium text-inherit no-underline after:text-[0.75em]
  after:opacity-40 after:content-['↕']
  in-[th[aria-sort=ascending]]:after:opacity-100
  in-[th[aria-sort=ascending]]:after:content-['↑']
  in-[th[aria-sort=descending]]:after:opacity-100
  in-[th[aria-sort=descending]]:after:content-['↓']
  ```

Final classes

```
inline-flex shrink-0 items-center justify-center
whitespace-nowrap rounded-md text-sm transition-colors
focus-visible:outline-none focus-visible:ring-2
focus-visible:ring-ring focus-visible:ring-offset-2
ring-offset-surface disabled:pointer-events-none
disabled:opacity-50 aria-disabled:pointer-events-none
aria-disabled:opacity-50 h-auto px-0 py-0 hover:text-foreground
hover:underline underline-offset-4 aria-pressed:text-foreground
gap-1 font-medium text-inherit no-underline after:text-[0.75em]
after:opacity-40 after:content-['↕']
in-[th[aria-sort=ascending]]:after:opacity-100
in-[th[aria-sort=ascending]]:after:content-['↑']
in-[th[aria-sort=descending]]:after:opacity-100
in-[th[aria-sort=descending]]:after:content-['↓']
```

Definition

```ts
'action.sort': {
  kind: 'semantic',
  description: 'Sorts a table by a column: the button inside its th. Put aria-sort="ascending" or "descending" on the th of the sorted column; the arrow follows it',
  refs: ['control.quiet'],
  keywords: ['sort', 'order', 'column'],
  binding: {
    classes: 'gap-1 font-medium text-inherit no-underline after:text-[0.75em] after:opacity-40 after:content-[\'↕\'] in-[th[aria-sort=ascending]]:after:opacity-100 in-[th[aria-sort=ascending]]:after:content-[\'↑\'] in-[th[aria-sort=descending]]:after:opacity-100 in-[th[aria-sort=descending]]:after:content-[\'↓\']',
  },
  notFor: [
    {
      context: 'picking a sort order from a list of choices',
      instead: 'choice.open',
    },
  ],
},
```
