# Toolbar and status bar

> The ribbon toolbar with File, Home, Insert, Page Layout, Formulas, Data, Review and View tabs, opening and downloading files from the File tab, the classic, single-line and collapsed ribbon, the compact toolbar, custom buttons, keyboard access, the cell menu and the status bar with selection statistics and zoom.

The spreadsheet ships with a ribbon toolbar above the formula bar. It is on by default, needs no setup, follows the theme tokens in light and dark mode, and every command in it can be reached by keyboard.

```ts
import { createSpreadsheet } from '@birchui/spreadsheet';

const sheet = createSpreadsheet(document.querySelector('#budget')!, {
  toolbar: 'ribbon',
  height: '80vh',
});
```

| `toolbar` | Result |
| --- | --- |
| `'ribbon'` (default) | Eight tabs: File, Home, Insert, Page Layout, Formulas, Data, Review and View. Home is the tab shown first. |
| `'compact'` | One row with the essentials: undo, redo, bold, italic, underline, strikethrough, fill and text colour, horizontal alignment, number format, AutoSum, filter and find. |
| `false` | No toolbar. The keyboard shortcuts, the cell menu and the API keep working. |

Change it later with `sheet.update({ toolbar: 'compact' })`.

## Ribbon height: classic, single line, tabs only

The ribbon has three layouts. Pick one with `ribbon.mode`, or let the widget pick with `'auto'`:

```ts
const sheet = createSpreadsheet(host, {
  toolbar: 'ribbon',
  ribbon: { mode: 'auto' },
});
```

**`RibbonOptions`** (interface from `@birchui/spreadsheet`, full reference: https://docs.birchui.com/api/spreadsheet.md)

```ts
interface RibbonOptions
```

| Property | Type | Description |
| --- | --- | --- |
| `mode?` | `RibbonMode` |  |

| `ribbon.mode` | Result | Height |
| --- | --- | --- |
| `'classic'` (default) | Tabs over a panel with three rows of commands and a caption under each group. | 155 px |
| `'simplified'` | Tabs over one row with the most used commands of the tab. The other commands of the tab are behind the `…` (**More commands**) button at the end of the row, grouped as on the classic ribbon. | 74 px |
| `'collapsed'` | Tabs only. A click on a tab opens the classic panel over the sheet; the sheet does not move. The panel closes after a command, on `Escape`, on a second click on the tab and on a click outside. | 35 px |
| `'auto'` | `'simplified'`, or `'collapsed'` when the widget is less than 420 px tall or less than 480 px wide. It follows the size of the widget, not of the window, and changes when the widget is resized. | |

In a 714 px tall widget with the formula bar, the sheet tabs and the status bar shown, the classic ribbon leaves 21 sheet rows visible, the single-line ribbon 24 and the collapsed one 26; at 600 px it is 16, 19 and 21, at 900 px 29, 33 and 35 (default row height, 100 % zoom).

On the single-line ribbon, Home keeps undo, redo, paste, cut, copy, the format painter, font family and size, bold, italic, underline, borders, fill and text colour, horizontal alignment, wrap, merge, the number format, percent, the two decimal buttons, conditional formatting, format as table, the Format menu, AutoSum, Sort, Filter and Find in the row. Every other tab shows all of its commands in the row. When the row does not fit, labels are dropped first, then commands move behind **More commands** from the end of the row.

People change the layout themselves in two ways:

- the **Ribbon display options** button at the end of the tab row opens a menu with Classic ribbon, Single-line ribbon, Show tabs only and Automatic; the current one is ticked;
- `Ctrl` + `F1`, or a double click on a tab, collapses the ribbon and brings back the layout it had before.

The widget does not write that choice to any storage. It reports it, and you store it wherever you keep user settings and pass it back as the option:

```ts
const sheet = createSpreadsheet(host, {
  ribbon: { mode: settings.ribbonMode ?? 'auto' },
});

sheet.on('ribbonModeChange', ({ mode, resolved, source }) => {
  if (source === 'user') saveSetting('ribbonMode', mode);
});
```

`mode` is what was asked for (`'auto'` included), `resolved` is the layout on screen (`'classic'`, `'simplified'` or `'collapsed'`), and `source` is `'user'` for the menu, `Ctrl` + `F1` and the double click, or `'resize'` when `'auto'` changed the layout because the widget changed size. `sheet.update({ ribbon: { mode } })` changes the layout without an event. `sheet.getRibbonMode()` returns `{ mode, resolved }`.

`ribbon.mode` applies to `toolbar: 'ribbon'`. The `'compact'` toolbar has no tabs and ignores it.

## What is on each tab

| Tab | Groups and commands |
| --- | --- |
| **File** | Open · Download as Excel workbook (.xlsx), CSV (.csv), OpenDocument (.ods) or PDF (.pdf) · Print, Page setup. See [The File tab](#the-file-tab). |
| **Home** | Undo and redo · Clipboard: paste, paste values, paste special, cut, copy, format painter · Font: family, size, bold, italic, underline, strikethrough, borders, fill colour, text colour · Alignment: top, middle, bottom, left, centre, right, wrap text, merge · Number: format dropdown, currency, percent, comma, increase and decrease decimals · Styles: conditional formatting, format as table, cell styles · Cells: insert and delete cells (with a shift), rows and columns, hide and unhide, AutoFit · Editing: AutoSum with Average, Count, Max and Min, clear, sort A to Z and Z to A, Sort (the multi-level dialog), filter, find and replace, go to |
| **Insert** | Table, PivotTable, slicer · Chart menu with the ten [chart types](https://docs.birchui.com/spreadsheet/charts.md), sparklines · Picture, [object](https://docs.birchui.com/spreadsheet/embedded-objects.md), [shapes](https://docs.birchui.com/spreadsheet/shapes.md) and text box · Link, note · Cell controls: checkbox, dropdown |
| **Page Layout** | Page setup: margins (Normal, Wide, Narrow, custom), orientation, paper size, print area (set and clear), page breaks (insert, remove, reset all), print titles · Scale to fit: width, height, scale · Sheet options: print gridlines, print headings. See [The Page Layout tab](#the-page-layout-tab). |
| **Formulas** | Insert Function with search · the function library by category, built from `listFunctions()` · Name Manager · Trace precedents, trace dependents, remove arrows, show formulas, evaluate formula · Calculate now |
| **Data** | Sort A to Z, Z to A, multi-level sort, filter · Text to columns, flash fill, remove duplicates, data validation · Goal seek, data table · Group, ungroup, subtotal · PivotTable field list, refresh all |
| **Review** | New note, delete note, show all notes · New comment, show comments · Protect sheet, protect workbook · Workbook: properties, import report |
| **View** | Freeze panes, split · Gridlines, headings, formula bar, zero values, sheet right-to-left, show formulas · Zoom out, zoom level, zoom in, 100% |

Most commands are drawn with an icon from one set, Bold, Italic, Underline, Strikethrough and Percent style included, and have a tooltip with their name. Menus carry the same icons: each chart kind, every File and Page Layout command, the border presets, the sheet tab menu and the cell menu have one, and a menu that has an icon on any entry keeps one column free for them so that all labels start at the same position. The tabs of Format Cells and the header of a side pane show an icon as well. Toggle buttons such as Bold, Wrap text or Filter report their state with `aria-pressed`, and follow the active cell as the selection moves. Commands that change the workbook are disabled in `readOnly` mode and respect [sheet protection](https://docs.birchui.com/spreadsheet/protection.md).

Double-click **Format painter** to keep it on for several targets; press `Escape` to stop.

## The File tab

The File tab opens and saves files in the browser. Nothing is uploaded: files are read and written on the page.

| Command | What it does |
| --- | --- |
| **Open…** | Shows the file chooser for `.xlsx`, `.xlsm`, `.xltx`, `.xls`, `.xlt`, `.csv`, `.tsv`, `.txt` and `.ods`, and replaces the workbook with the file. The format is taken from the bytes of the file first and from its name second. |
| **Excel workbook (.xlsx)**, **CSV (.csv)**, **OpenDocument (.ods)**, **PDF (.pdf)** | Downloads the workbook in that format. CSV holds the active sheet and starts with a UTF-8 byte order mark so that Excel reads accented text; PDF holds the active sheet. The file is named after the file that was opened, or `workbook`. |
| **Print** | The same as `print()`. |
| **Page setup** | Opens the [page setup dialog](https://docs.birchui.com/spreadsheet/printing.md). |

Dropping a file on the spreadsheet opens it too. While a file is dragged over it the widget shows a dashed outline. Turn this off with `fileDrop: false`.

With `readOnly: true` the commands that do not change the workbook stay enabled: the four downloads and Print. **Open** and **Page setup** are disabled, and a file dropped on the spreadsheet is refused with a `readOnly` error event. `openFile()` in code still works, so your application can load another document into a read-only view.

The same actions are methods, and two events let you cancel them and do the work yourself, for example to load from and save to your server:

```ts
await sheet.openFile(file); // a File, Blob, Uint8Array or ArrayBuffer; resolves to false when cancelled
await sheet.openFile(file, 'Payroll.xlsx', { password }); // a password-protected xlsx, no dialog
await sheet.saveAs('xlsx', 'Q3 budget'); // 'xlsx' | 'csv' | 'ods' | 'pdf'
sheet.getFileName(); // 'Q3 budget', without the extension

sheet.on('beforeSave', async (event) => {
  if (event.format !== 'xlsx') return;
  event.preventDefault();
  await uploadToServer(event.fileName, await sheet.exportXlsx());
});

sheet.on('beforeOpen', (event) => {
  // event.fileName, event.format ('xlsx' | 'xls' | 'csv' | 'ods'), event.data (the bytes),
  // event.source ('picker' | 'drop' | 'api')
  if (event.data.length > 20_000_000) event.preventDefault();
});
```

`preventDefault()` must be called before the listener returns. A password-protected workbook that is picked or dropped opens a **Password required** dialog; a wrong password keeps the dialog open with a message, Cancel leaves the current workbook in place. `openFile()` in code does not prompt: pass the password as `openFile(file, fileName, { password })`. Without it, or with a wrong one, the promise rejects with an `EncryptionError` whose `code` is `'passwordRequired'` or `'wrongPassword'` and the current workbook stays. The password is ignored for a file that is not encrypted. Limits: `.xls` is read only, so there is no download in that format; the File tab has no "new workbook" or recent-files list.

## The Page Layout tab

Every command on this tab writes the [page setup](https://docs.birchui.com/spreadsheet/printing.md) of the active sheet, the object `getPageSetup()` returns and xlsx files carry, as one undo step each.

| Command | Writes |
| --- | --- |
| **Margins** | `margins`. Normal is 0.75 in top and bottom and 0.7 in left and right, Wide is 1 in all round, Narrow is 0.75 in and 0.25 in. **Custom margins…** opens the page setup dialog. |
| **Orientation**, **Size** | `orientation` and `paperSize` (Letter, Legal, Tabloid, A3, A4, A5). |
| **Print area** | **Set print area** stores the selected range in `printArea`; **Clear print area** removes it. One range only. |
| **Breaks** | **Insert page break** adds a break above the active row and left of the active column (`rowBreaks`, `columnBreaks`); in row 1 or column A only the other one. **Remove page break** removes the breaks at the active cell, **Reset all page breaks** removes all of them. |
| **Print titles** | **Repeat selected rows at top** and **Repeat selected columns at left** store the rows or columns of the selection in `printTitleRows` and `printTitleColumns`; **Clear print titles** removes both. |
| **Width**, **Height** | `fitToWidth` and `fitToHeight`, automatic or 1 to 9 pages. |
| **Scale** | `scale` in percent. It is switched off while a width or height is set, because the fit decides the scale then. |
| **Print gridlines**, **Print headings** | `gridlines` and `headings`. These affect print and PDF output only; the gridlines and headings on screen are on the View tab. |

The menus tick the current value. The tab is disabled with `readOnly: true`. Not on the tab: headers and footers and centring on the page, which are in the page setup dialog (File > Page setup); themes, backgrounds and the arrange commands of Excel's tab do not exist here.

## Command search

A search box sits at the end of the tab row. `Alt` + `Q` moves focus to it from anywhere in the spreadsheet. Type part of a command name and a list opens with up to twelve matches; each shows its icon, its name and where it lives, for example `Freeze panes` with `View › Window › Freeze panes`.

- The search covers every command of every tab that is not hidden, the entries of their menus (borders, the conditional formatting rules, Freeze panes, Go to special and so on) and your `customItems`. It uses the translated labels.
- Typing `freeze` lists Freeze panes, Freeze top row, Freeze first column and Unfreeze panes. `Enter` runs the highlighted one, `↓` and `↑` move through the list, a click runs any of them.
- Typing the start of a function name (two letters or more, for example `sumif`) lists the matching functions. Choosing one opens **Insert Function** with that function selected.
- A font, size, number format or colour command opens its tab and moves focus to the control instead of running.
- Commands that cannot run now are listed dimmed: the ones that change the workbook when it is `readOnly`, and ones such as Unfreeze panes when nothing is frozen.
- `Escape` clears the box; a second `Escape` returns to the grid.

The box is an ARIA combobox with a listbox; the number of matches is announced. In a widget narrower than 480 px it shrinks to its icon and widens over the tabs while it has focus. Hide it with `toolbarOptions: { hiddenItems: ['commandSearch'] }`; it is not part of the `'compact'` toolbar. The function category menus on the Formulas tab are left out of the search because the function names are already found.

## Sizes, states and tooltips

The ribbon, the menus and the dialogs follow one set of rules, shared with the Document Editor and the PDF viewer:

- **Three rows.** On the classic ribbon every tab has room for three rows of commands, so the ribbon keeps its height when you switch tabs; the single-line ribbon has one row on every tab. A command is 28 pixels tall with a 32 pixel hit area; tabs, menu entries, dialog buttons and fields are 32 pixels tall, and menu entries are 44 pixels on a coarse pointer.
- **Labels.** The most used commands of a tab carry their name beside the icon (Paste, AutoSum, Conditional formatting, Format as table, Cell styles, Format and everything on File, Insert, Page Layout, Data, Review and View where it fits). On Home, Wrap text, Merge cells, Sort, Filter, Find and Replace are labelled while the window is wide enough for all groups and fall back to icons before any command is moved to the More commands popup. All other commands, Cut and Copy among them, are icon-only with a tooltip.
- **Rows and separators.** On Home the groups are laid out as in Excel: Font has the family and size, then bold, italic, underline and strikethrough, then borders, a separator, and the fill and text colours. Alignment has vertical alignment, a separator and orientation; horizontal alignment, a separator and the indent buttons; then Wrap text and Merge cells. Number has the format, then currency, percent and comma style, then increase and decrease decimal on a row of their own.
- **Tooltips.** Every command has a tooltip with its name, followed by its shortcut in brackets when it has one, for example `Bold (Ctrl+B)`. The shortcut is also announced through `aria-keyshortcuts`.
- **States.** Hover, pressed (pointer down), selected (`aria-pressed`, the active tab, a ticked menu entry), focus (a 2 pixel ring in the focus colour), disabled (dimmed, with a not-allowed cursor), busy and invalid look the same on every control.
- **Fields.** Selects, the name box, the formula bar and dialog fields have an edge with at least 3:1 contrast against the surface in both themes.
- **Dialogs.** The title is at the top, the buttons are right-aligned under a divider with Cancel before the one primary button.

The values come from custom properties with the shared `--lq-*` tokens as their source, so setting a token on the page restyles all three products:

| Property | Source | Default |
| --- | --- | --- |
| `--lq-sheet-control-height` | `--lq-control-height` | `32px` |
| `--lq-sheet-control-compact` | `--lq-control-height-compact` | `28px` |
| `--lq-sheet-radius-control`, `--lq-sheet-radius`, `--lq-sheet-radius-dialog` | `--lq-radius-control`, `--lq-radius`, `--lq-radius-dialog` | `4px`, `6px`, `8px` |
| `--lq-sheet-text-xs`, `--lq-sheet-text-sm`, `--lq-sheet-font-size`, `--lq-sheet-text-lg` | `--lq-text-xs`, `--lq-text-sm`, `--lq-font-size`, `--lq-text-lg` | `11px`, `12px`, `13px`, `15px` |
| `--lq-sheet-hover` | `--lq-row-hover` | `#eef2f6` light, `#1f2630` dark |
| `--lq-sheet-input-border` | `--lq-input-border` | `#818b98` light, `#6e7681` dark |
| `--lq-sheet-danger` | `--lq-danger` | `#cf222e` light, `#ff7b72` dark |

## Narrow widths

When the eight tabs do not fit, the tab row scrolls sideways (swipe, a horizontal wheel or the arrow keys) and the active tab is kept in view. The row has no visible scrollbar; a fade at its edge shows that more tabs follow.

When the groups of the active tab do not fit, the ones at the end move into a **More commands** popup opened by the `…` button at the end of the toolbar; a group that fits in part keeps the commands that fit and moves the rest. Commands are never drawn clipped or on top of each other: at 1440 pixels the classic Home tab shows all of its groups with every label; at 1280 it shows all of them with the optional labels dropped; at 760 it shows Undo, Clipboard, Font, Alignment and part of Number. Nothing is dropped: the popup holds the same controls, with the same keyboard behaviour. The popup, like every menu and colour palette, is kept inside the widget: one that would cross the right or bottom edge is moved back in.

## Keyboard

The ribbon follows the WAI-ARIA tabs and toolbar patterns. The tab list and the toolbar are one tab stop each; the command search box and the Ribbon display options button after the tabs are two more.

| Keys | Action |
| --- | --- |
| `Alt` + `F`, `H`, `N`, `P`, `M`, `A`, `R`, `W` | Open File, Home, Insert, Page Layout, Formulas, Data, Review or View and focus its first command. Holding `Alt` shows the letters on the tabs. |
| `Alt` + `Q` | Focus the [command search](#command-search) |
| `Ctrl` + `F1` | Collapse the ribbon to its tabs, or bring it back |
| `F6`, `Shift` + `F6` | Move between the grid, the side panel, the sheet tabs, the status bar, the ribbon and the formula bar |
| `←` `→`, `Home`, `End` on a tab | Switch tabs |
| `↓` on a tab | Move into the toolbar; on a collapsed ribbon this opens the panel first |
| `←` `→`, `Home`, `End` in the toolbar | Move between commands |
| `↑` in the toolbar | Back to the tab list |
| `Enter`, `Space` | Run the command or open its menu |
| `↓` on a menu or colour button | Open it |
| Arrow keys in the colour palette | Move between swatches |
| `Escape` | Close a menu, close the panel of a collapsed ribbon, or return to the grid |

Mouse clicks on toolbar buttons leave focus in the grid, so you can keep typing. Keyboard activation keeps focus on the button, so a command can be repeated.

Turn the `Alt` key tips off with `toolbarOptions: { keyTips: false }` if your page uses those shortcuts.

## Hide tabs and commands, add your own

**`ToolbarOptions`** (interface from `@birchui/spreadsheet`, full reference: https://docs.birchui.com/api/spreadsheet.md)

```ts
interface ToolbarOptions
```

| Property | Type | Description |
| --- | --- | --- |
| `hiddenTabs?` | `ToolbarTabId[]` |  |
| `hiddenItems?` | `string[]` |  |
| `customItems?` | `ToolbarCustomItem[]` |  |
| `keyTips?` | `boolean` |  |

```ts
const sheet = createSpreadsheet(host, {
  toolbarOptions: {
    hiddenTabs: ['review'],
    hiddenItems: ['strike', 'cellStyles', 'clipboard'],
    customItems: [
      {
        id: 'submitForApproval',
        tab: 'home',
        group: 'Workflow',
        label: 'Submit for approval',
        onClick: (api) => submitBudget(api.toJSON()),
      },
    ],
  },
});
```

- `hiddenTabs` takes tab ids: `file`, `home`, `insert`, `pageLayout`, `formulas`, `data`, `review`, `view`.
- `hiddenItems` takes command ids or group ids. Every control carries its id in a `data-control` attribute and every group in `data-group`, so you can read them from the page. Common ids: `undo`, `redo`, `paste`, `pasteSpecial`, `formatPainter`, `fontFamily`, `fontSize`, `bold`, `italic`, `underline`, `strike`, `borders`, `fillColor`, `textColor`, `wrap`, `merge`, `numberFormat`, `currency`, `percent`, `comma`, `increaseDecimal`, `decreaseDecimal`, `conditionalFormatting`, `formatAsTable`, `cellStyles`, `autoSum`, `customSort`, `filter`, `find`, `pivotTable`, `chart`, `shapes`, `insertFunction`, `goalSeek`, `dataTable`, `protectSheet`, `freezePanes`, `openFile`, `downloadXlsx`, `downloadCsv`, `downloadOds`, `downloadPdf`, `print`, `pageSetup`, `margins`, `pageOrientation`, `paperSize`, `printArea`, `pageBreaks`, `printTitles`, `fitWidth`, `fitHeight`, `printScale`, `printGridlines`, `printHeadings`.
- `customItems` adds buttons. `group` names a new or existing group on that tab. `onClick` receives the spreadsheet API; an error thrown by it is logged and does not break the toolbar.

**`ToolbarCustomItem`** (interface from `@birchui/spreadsheet`, full reference: https://docs.birchui.com/api/spreadsheet.md)

```ts
interface ToolbarCustomItem
```

| Property | Type | Description |
| --- | --- | --- |
| `id` | `string` |  |
| `tab` | `ToolbarTabId` |  |
| `label` | `string` |  |
| `group?` | `string` |  |
| `glyph?` | `string` |  |
| `title?` | `string` |  |
| `onClick` | `(api: SpreadsheetApi) => void` |  |

## Translations

Toolbar text goes through the same [`localeText`](https://docs.birchui.com/grid/localization.md) mechanism as the rest of the widget, under keys that start with `spreadsheet.ribbon.`:

```ts
sheet.update({
  localeText: {
    'spreadsheet.ribbon.tab.home': 'Start',
    'spreadsheet.ribbon.tab.insert': 'Einfügen',
    'spreadsheet.ribbon.group.font': 'Schriftart',
    'spreadsheet.ribbon.wrap': 'Textumbruch',
  },
});
```

In right-to-left mode the tab and toolbar arrow keys are mirrored.

## Cell menu

A right-click, `Shift` + `F10` or the context-menu key opens the cell menu. Besides cut, copy and paste it offers paste special, format painter, insert and delete rows and columns, **Insert cells…** and **Delete cells…**, hide and unhide (on headers), format cells, cell styles, notes, links, create table, group and ungroup, page breaks, trace arrows, evaluate formula, clear contents, sort, custom sort, filter, data validation, conditional formatting, the notes panel, merge, freeze panes and find and replace. Inside a pivot table it adds **Refresh**, **Field list** and **Show details**.

## Status bar

The status bar shows the editing mode (or **Calculating…** while a [worker calculation](https://docs.birchui.com/spreadsheet/worker-calculation.md#with-the-spreadsheet-component) is outstanding), circular references, and for a selection of more than one cell its **Average**, **Count**, **Min**, **Max** and **Sum**. Hidden rows are left out.

On the right is the zoom control: a slider from 10% to 400% with zoom-out and zoom-in buttons, and the current percentage, which resets to 100% when clicked. The zoom buttons, the add-sheet button beside the sheet tabs and the filter buttons in header cells show a tooltip with the name a screen reader hears.

```ts
sheet.setZoom(125);
sheet.getZoom();
sheet.on('zoomChange', ({ zoom }) => saveViewPreference({ zoom }));
```

`Ctrl` + mouse wheel, `Ctrl` + `Alt` + `=`, `Ctrl` + `Alt` + `-` and `Ctrl` + `Alt` + `0` zoom from the grid. Zoom scales the grid geometry and text; column widths and row heights stay stored in unzoomed pixels. Start at another level with the `zoom` option, in percent.

Hide the bar with `statusBar: false`.
