v22.18.0 release notes

DashboardGrid

DashboardGrid lays out tiles on a grid. In edit mode the tiles are dragged and resized with the mouse, a finger or the keyboard, the other tiles make room, and every move is announced to screen readers. The layout adapts to the width of the grid, renders on the server and has no dependency.

View as .md
import { DashboardGrid, DashboardGridItemTemplate } from '@exhaustive-ui/core/dashboardgrid';

DashboardGrid places tiles on a grid of columns, 12 by default, and rows of rowHeight pixels, with a gap between them. The layout is an array of tiles, each with an id, a column x and a row y counted from 0, a width w in columns and a height h in rows. The grid is a CSS grid, so the layout renders on the server and before the JavaScript loads.

The item template draws a tile: it receives the tile as the implicit variable, its position as displayed, and the editable, grabbed, dragging and resizing flags. Write it as <ng-template [pDashboardGridItem]="layout" let-tile> to type tile with the type of your layout, or as <ng-template #item let-tile>. With editable, tiles are dragged to move them and resized by their corner, and the grid updates layout with a new array, so bind it two-way with [(layout)].

Sales6 × 2
Visitors3 × 2
Orders3 × 2
Revenue4 × 2
Tickets4 × 2
Uptime4 × 2
Press Space or Enter to pick up the tile. While it is picked up, the arrow keys move it, Shift with the arrow keys resizes it, Space or Enter drops it and Escape cancels.

Without a drag handle, a tile drags from anywhere but its buttons, links and form fields. dragHandle takes a CSS selector, such as .drag-handle, and only the matching element of a tile starts a drag: the rest of the tile stays free for selecting text, scrolling and clicking, and on touch screens the page still scrolls when a finger moves over a tile. The grid gives the handle the grab cursor. The keyboard still moves the whole tile.

Inbox

12 unread messages, 3 flagged.

Calendar

Design review at 2:30 PM.

Tasks

5 tasks due this week.

Press Space or Enter to pick up the tile. While it is picked up, the arrow keys move it, Shift with the arrow keys resizes it, Space or Enter drops it and Escape cancels.

The buttons of the tiles still work.

resizeHandles lists the sides and corners that resize a tile: n, s, e, w, ne, nw, se and sw, with se alone by default. e is the inline end, the right side in left-to-right pages and the left side in right-to-left ones. A tile stays within its minW, maxW, minH and maxH, in cells, and within the columns; resizable: false or draggable: false turn off one of the two for a tile.

While a tile grows, the tiles in its way are pushed down. With compact set to vertical, the default, the tiles then move up to fill the gaps; with none they stay where they are dropped, and empty rows are kept.

CompactionVerticalNone
Free4 × 2Any size
Wide6 × 24 to 8 columns
Tall2 × 33 to 5 rows
Fixed size3 × 2Moves, does not resize
Pinned3 × 2Resizes, does not move
Press Space or Enter to pick up the tile. While it is picked up, the arrow keys move it, Shift with the arrow keys resizes it, Space or Enter drops it and Escape cancels.

A static tile never moves: it can not be dragged or resized, a dragged tile can not be dropped over it, and the tiles pushed or compacted go around it. It is not focusable in edit mode, since nothing can be done to it. Use it for a header, a notice or a tile the user must keep in view.

Quarterly overview
Static
Sales
Movable
Maintenance notice
Static
Traffic
Movable
Orders
Movable
Refunds
Movable
Press Space or Enter to pick up the tile. While it is picked up, the arrow keys move it, Shift with the arrow keys resizes it, Space or Enter drops it and Escape cancels.

The grid follows its own width, not the width of the window. breakpoints gives the number of columns at or below a maxWidth in pixels, and the smallest matching breakpoint applies. A breakpoint without a layout gets the base layout scaled to its columns; layouts holds a layout per breakpoint name, with the id, x, y, w and h of the tiles. A tile missing from it goes to the first free space, and the edits made at a breakpoint are saved in layouts, so bind it two-way with [(layouts)].

Below stackBelow pixels, 576 by default, the tiles are stacked in a single column in reading order, each with its height, and can not be edited. onBreakpointChange tells the breakpoint, the columns and whether the tiles are stacked. Resize the window to see the layout change.

12 columns

SalesColumn 1, row 1
GoalColumn 9, row 1
VisitorsColumn 1, row 3
OrdersColumn 5, row 3
StorageColumn 9, row 3
Press Space or Enter to pick up the tile. While it is picked up, the arrow keys move it, Shift with the arrow keys resizes it, Space or Enter drops it and Escape cancels.

addItem adds a tile: without x and y, or when its place is taken, it goes to the first free space, found with findFreeSpace, and it is also placed in every layout of layouts. removeItem removes a tile by its id, and the others move up. Both update layout, emit onLayoutChange with the add or remove action and are announced to screen readers.

A tile holds any component. Give the content of a tile flex-1 min-h-0 to fill its height, as the charts below do.

Visits
Quarter goal
72%
Orders
Storage
  1. Apps (16%)
  2. Messages (8%)
  3. Media (24%)
  4. System (10%)
Press Space or Enter to pick up the tile. While it is picked up, the arrow keys move it, Shift with the arrow keys resizes it, Space or Enter drops it and Escape cancels.

onLayoutChange is emitted once a tile is dropped, resized, added or removed, after layout or layouts is updated, with the layout as displayed, the breakpoint that was edited, the columns, the action and the item. A keyboard move only emits when the tile is dropped, and Escape emits nothing. Save the positions from there: this demo keeps them in the local storage of the browser, so the layout is the same after a reload.

Save only the id, x, y, w and h of the tiles and merge them with the tiles of the application when loading, so that new tiles and new settings are not lost.

SalesColumn 1, row 1
VisitorsColumn 7, row 1
OrdersColumn 1, row 3
RefundsColumn 5, row 3
Press Space or Enter to pick up the tile. While it is picked up, the arrow keys move it, Shift with the arrow keys resizes it, Space or Enter drops it and Escape cancels.

Screen Reader

The grid is a list and each tile a list item, in reading order, row by row, whatever the order of the layout array, so the tab order and the reading order follow what is on screen. A tile is named by its label, or by the field or function given to itemLabel. Name the grid with ariaLabel or ariaLabelledBy: it then gets the group role.

In edit mode, every tile that can move or be resized is focusable and described with aria-describedby by the instructions to move it. A tile is moved and resized with the keyboard alone, and a polite live region announces each step: "Picked up Sales, column 1, row 1, 4 columns wide and 2 rows high", "Moved Sales to column 3, row 2", "Resized Sales to 6 columns wide and 2 rows high", "Dropped Sales at column 3, row 2, 6 columns wide and 2 rows high" or "Cancelled, Sales returned to column 1, row 1". A move blocked by the edge or a static tile, and a size beyond the limits of a tile, are announced too, and so are the tiles added and removed with addItem and removeItem. Translate every text with labels.

The resize handles are drawn for the pointer and hidden from assistive technologies, since Shift and the arrow keys resize a tile. Static tiles are not focusable. Keep the content of a tile reachable: its buttons, links and fields work as usual, and the keys pressed in them never move the tile. The tiles glide to their new place unless the user prefers reduced motion.

<h2 id="overview">Overview</h2>
<p-dashboard-grid [(layout)]="layout" editable ariaLabelledBy="overview" [labels]="{ moved: '{0} déplacé en colonne {1}, ligne {2}' }" />

Tile Keyboard Support

KeyFunction
tabMoves focus to the next tile or to the content of the tile. Leaving a picked up tile cancels its move.
space / enterPicks up the focused tile, or drops the picked up tile where it is.
left arrow / right arrowMoves the picked up tile one column to the left or the right, pushing the tiles in its way down. Reversed in right-to-left layouts.
up arrow / down arrowMoves the picked up tile up or down, past the next tile when the layout is compacted, so that the two swap.
shift + left arrow / right arrowMakes the picked up tile one column narrower or wider, within its limits. Reversed in right-to-left layouts.
shift + up arrow / down arrowMakes the picked up tile one row shorter or taller, within its limits.
escapeCancels the move and puts the tiles back where they were. Also cancels a drag or a resize with the pointer.

The changes are only emitted when the tile is dropped, so a cancelled keyboard move never reaches layout or onLayoutChange.