fix(widgets): keep a pinned panel in place

A pinned floating panel no longer renders its move and resize handles,
so it cannot be dragged, moved by arrow keys, dropped onto the sidebar
or resized. Unpinning brings the handles back at the stored size and
offset; the viewport clamp still applies while pinned.

The panel now starts unpinned, migrated panels included; a stored
layout keeps the pin it was saved with.
This commit is contained in:
Zakk committed 2026-10-04 20:43:39 +11:00
1 parent b38e974d79
commit 09da41dbfa
6 files changed
+73 -25

No files matched your search

+4
View File
@@ -0,0 +1,4 @@
Fixed
- A pinned widgets panel stays in place: it can no longer be dragged, moved by arrow keys, dragged onto the sidebar or resized until it is unpinned.
- The widgets panel now starts unpinned.
+49 -12
View File
@@ -1,4 +1,4 @@
import {test, expect, mockBackend, moreAction, settle, box} from './fixtures';
import {test, expect, mockBackend, moreAction, settle, settleFrames, box} from './fixtures';
import {ApiError} from '../src/api/error';
import {defaults, defaultWidget, type Layout, type WidgetId} from '../src/shell/widgets/layout';
import type {Locator, Page} from '@playwright/test';
@@ -733,19 +733,57 @@ test('the anchored panel resizes by keyboard within its limits and keeps the siz
expect(await page.evaluate(() => String(getSelection()))).toBe('');
});
test('the panel starts pinned and open; unpinned, it collapses on another page and stays unpinned', async ({page}) => {
test('the panel starts unpinned and open and collapses on another page; pinned, it stays open and stays pinned', async ({page}) => {
await page.goto('/#/settings');
const unpin = floating(page).getByRole('button', {name: 'Unpin panel', exact: true});
await expect(unpin).toHaveAttribute('aria-pressed', 'true');
const pin = floating(page).getByRole('button', {name: 'Pin panel', exact: true});
await expect(pin).toHaveAttribute('aria-pressed', 'false');
await page.goto('/#/connections');
await expect(floating(page).getByRole('button', {name: 'Collapse widgets', exact: true})).toBeVisible();
await unpin.click();
await expect(floating(page).getByRole('button', {name: 'Pin panel', exact: true})).toHaveAttribute('aria-pressed', 'false');
await floating(page).getByRole('button', {name: 'Expand widgets', exact: true}).click();
await pin.click();
await expect(floating(page).getByRole('button', {name: 'Unpin panel', exact: true})).toHaveAttribute('aria-pressed', 'true');
await settle(page);
await page.reload();
await expect(floating(page).getByRole('button', {name: 'Pin panel', exact: true})).toHaveAttribute('aria-pressed', 'false');
await expect(floating(page).getByRole('button', {name: 'Unpin panel', exact: true})).toHaveAttribute('aria-pressed', 'true');
await page.goto('/#/settings');
await expect(floating(page).getByRole('button', {name: 'Expand widgets', exact: true})).toBeVisible();
await expect(floating(page).getByRole('button', {name: 'Collapse widgets', exact: true})).toBeVisible();
});
test('a pinned panel keeps its place and size; unpinned, it moves and resizes again', async ({page}) => {
await save(page, {...defaults(), pinned: true});
await page.goto('/#/settings');
const panel = floating(page);
const start = await box(panel);
const drag = async (from: {x: number; y: number}, dx: number, dy: number) => {
await page.mouse.move(from.x, from.y);
await page.mouse.down();
await page.mouse.move(from.x + dx, from.y + dy, {steps: 4});
await page.mouse.up();
};
const name = await box(panel.locator('.rp-widget-backend'));
const actions = await box(panel.locator('.rp-widget-actions'));
const grip = {x: (name.x + name.width + actions.x) / 2, y: actions.y + actions.height / 2};
// Pinned, the panel has no move or resize handle to drag or focus, and the header and corner stay put.
await expect(panel.locator('.rp-panel-move, .rp-panel-resize')).toHaveCount(0);
await drag(grip, -60, -40);
await drag({x: start.x + 1, y: start.y + 1}, -40, -40);
await panel.getByRole('button', {name: 'Unpin panel', exact: true}).focus();
for (const key of ['ArrowLeft', 'ArrowUp']) await page.keyboard.press(key);
await settleFrames(page);
expect(await box(panel)).toEqual(start);
// Unpinned, the same size and place come back with the handles.
await panel.getByRole('button', {name: 'Unpin panel', exact: true}).click();
await expect(panel.getByRole('button', {name: 'Move panel', exact: true})).toBeVisible();
expect(await box(panel)).toEqual(start);
await drag(grip, -60, -40);
await expect.poll(async () => (await box(panel)).x).toBe(start.x - 60);
expect((await box(panel)).y).toBe(start.y - 40);
await panel.getByRole('button', {name: 'Move panel', exact: true}).focus();
await page.keyboard.press('ArrowRight');
await expect.poll(async () => (await box(panel)).x).toBe(start.x - 44);
const moved = await box(panel);
const corner = await box(panel.getByRole('button', {name: 'Resize widgets panel', exact: true}));
await drag({x: corner.x + corner.width / 2, y: corner.y + corner.height / 2}, -40, 0);
await expect.poll(async () => (await box(panel)).width).toBe(moved.width + 40);
});
test('the default panel draws both rates in one chart without scrolling', async ({page}) => {
@@ -849,7 +887,7 @@ test.describe('header and edge at 1440', () => {
const order = await header
.locator('.rp-widget-actions button')
.evaluateAll(items => items.map(item => [item.getBoundingClientRect().left, item.getAttribute('aria-label')]));
expect(order.map(([, name]) => name)).toEqual(['Panel options', 'Unpin panel', 'Collapse widgets']);
expect(order.map(([, name]) => name)).toEqual(['Panel options', 'Pin panel', 'Collapse widgets']);
expect(order.map(([left]) => left)).toEqual(order.map(([left]) => left).sort((a, b) => Number(a) - Number(b)));
await openEditor(page);
await editor(page).getByRole('button', {name: 'Cancel', exact: true}).click();
@@ -859,8 +897,7 @@ test.describe('header and edge at 1440', () => {
await expect(speeds).toHaveText(['999 MB/s', '3.5 MB/s']);
await expect(header.locator('.rp-widget-speed')).toContainText('Download');
for (const speed of await speeds.all()) expect(await speed.evaluate(el => el.scrollWidth <= el.clientWidth)).toBe(true);
// Hiding at an edge applies to an unpinned panel.
await header.getByRole('button', {name: 'Unpin panel', exact: true}).click();
// Hiding at an edge applies to an unpinned panel, as the panel starts.
await options(page).click();
await expect(page.getByRole('menuitem', {name: 'Edit widgets'})).toBeVisible();
const edge = page.getByRole('menuitemcheckbox', {name: 'Hide at edge', exact: true});
+1
View File
@@ -101,6 +101,7 @@ export function PanelHost({
onMove={offset => patchLayout({offset})}
header={header}
collapsed={collapsed}
locked={layout.pinned}
dockTarget={() => document.querySelector('.rp-dock-slot')}
onDock={() => dock(true)}
edge={
+7 -5
View File
@@ -31,7 +31,7 @@ it('migrates v1, drops version and malformed items before deduplication', () =>
{id: 'group', group: 'backend-specific', form: 'kv', size: 'medium'},
{id: 'ranking', by: 'domain', form: 'ranked', size: 'medium'}
]);
expect(layout).toMatchObject({version: 4, collapsed: true, pinned: true});
expect(layout).toMatchObject({version: 4, collapsed: true, pinned: false});
for (const key of ['position', 'corner', 'floating', 'placement']) expect(layout).not.toHaveProperty(key);
expect(parseLayout({...defaults(), pinned: true}).pinned).toBe(true);
});
@@ -127,12 +127,14 @@ it('offers the divider in the panel, several times, and never on the dashboard',
const saved = {version: 4, items: [{id: 'speed', form: 'sparkline', size: 'medium'}], collapsed: false, pinned: false, visible: true};
expect(parseLayout(saved)).toEqual(saved);
});
it('defaults to a floating, pinned, open panel and pins a panel saved before version 4', () => {
expect(defaults()).toMatchObject({version: 4, pinned: true, collapsed: false});
it('defaults to a floating, unpinned, open panel and keeps the pin a panel was saved with', () => {
expect(defaults()).toMatchObject({version: 4, pinned: false, collapsed: false});
expect(defaults()).not.toHaveProperty('docked');
const placed = {docked: true, dockHeight: 300, size: {width: 400, height: 300}, offset: {x: 120, y: 48}};
const migrated = parseLayout({...defaults(), ...placed, version: 3, pinned: false});
expect(migrated).toMatchObject({version: 4, pinned: true, ...placed});
const migrated = parseLayout({...defaults(), ...placed, version: 3});
expect(migrated).toMatchObject({version: 4, pinned: false, ...placed});
expect(parseLayout({...defaults(), version: 3, pinned: true}).pinned).toBe(true);
expect(parseLayout({...defaults(), pinned: true}).pinned).toBe(true);
expect(parseLayout({...defaults(), pinned: false}).pinned).toBe(false);
});
it('starts with the rates, memory and mode, and keeps a stored divider', () => {
+4 -5
View File
@@ -157,7 +157,8 @@ export type Layout = {
// How far the reader moved the panel from its corner; absent until moved.
offset?: PanelOffset;
collapsed: boolean;
// A pinned panel stays as the reader left it on every page; otherwise it collapses when the page changes.
// A pinned panel stays as the reader left it on every page and can be neither moved nor resized; otherwise it
// collapses when the page changes.
pinned: boolean;
// The panel shows each widget's title above it; absent while hidden, when the title stays the widget's accessible name.
titles?: true;
@@ -173,7 +174,7 @@ export const defaults = (): Layout => ({
version: 4,
items: [defaultWidget('speed'), {id: 'memory', form: 'text', size: 'medium'}, defaultWidget('mode')],
collapsed: false,
pinned: true,
pinned: false,
visible: true
});
// Restore defaults puts the panel where a fresh profile has it: floating at its corner, at its own size.
@@ -247,9 +248,7 @@ export function parseLayout(value: unknown): Layout {
? {offset: clampPanelOffset({x: value.offset.x, y: value.offset.y, ...(value.offset.top === true && {top: true as const})})}
: {}),
collapsed: value.collapsed === true,
// Before version 4 a panel was unpinned by default, which a stored false cannot tell from a choice: it reads as
// pinned, the default since.
pinned: value.version !== 4 || value.pinned === true,
pinned: value.pinned === true,
...(value.titles === true ? {titles: true} : {}),
...(value.docked === true ? {docked: true} : {}),
...(finite(value.dockHeight) && value.dockHeight > 0 ? {dockHeight: Math.round(value.dockHeight)} : {}),
+8 -3
View File
@@ -309,7 +309,9 @@ function useEdgeHide(edge: EdgeHide | undefined, settled: boolean, laidOut: stri
// frame's upper half keeps its top edge and one in the lower half its bottom edge, so expanding or resizing grows it
// towards the room; the frame keeps it inside the viewport. Dropping the header over `dockTarget` docks the panel
// instead of moving it. A collapsed panel is its header alone and keeps only its width; expanding restores the stored
// height. With `edge` the panel hides at the screen edge nearest to it behind a handle, as useEdgeHide describes.
// height. A `locked` panel keeps its place and size: it renders no move or resize handles, so neither pointer nor
// keyboard moves it, while the frame still keeps it inside the viewport. With `edge` the panel hides at the screen edge
// nearest to it behind a handle, as useEdgeHide describes.
export function FloatingPanel({
label,
resizeLabel,
@@ -321,6 +323,7 @@ export function FloatingPanel({
onMove,
header,
collapsed = false,
locked = false,
children,
dockTarget,
onDock,
@@ -336,6 +339,7 @@ export function FloatingPanel({
onMove: (offset: PanelOffset) => void;
header: ReactNode;
collapsed?: boolean;
locked?: boolean;
children?: ReactNode;
dockTarget?: () => HTMLElement | null;
onDock?: () => void;
@@ -447,6 +451,7 @@ export function FloatingPanel({
}
>
{!collapsed &&
!locked &&
edges.map((side, index) => (
<ResizeHandle
key={index}
@@ -463,8 +468,8 @@ export function FloatingPanel({
}}
/>
))}
<div className="rp-panel-head" onPointerDown={onPointerDown}>
<button type="button" {...move.props} onPointerDown={onPointerDown} className="rp-panel-move" aria-label={moveLabel} />
<div className="rp-panel-head" onPointerDown={locked ? undefined : onPointerDown}>
{!locked && <button type="button" {...move.props} onPointerDown={onPointerDown} className="rp-panel-move" aria-label={moveLabel} />}
{header}
</div>
{children}