diff --git a/app/src/components/Common.js b/app/src/components/Common.js
index b776fb86..d35fd03e 100644
--- a/app/src/components/Common.js
+++ b/app/src/components/Common.js
@@ -1709,7 +1709,19 @@ export function normalizeEstimate(estimate) {
export function useAPIButton(
color = 'violet',
- size = 'medium',
+ /*
+ * Undefined, not 'medium'. `size` was never put into `buttonArgs` below, so every
+ * APIButton in the app rendered at Mantine's default no matter what its call site asked
+ * for -- seventeen of them pass a size, from `xs` on the map's pin actions to `huge` on
+ * Settings, and all seventeen were ignored. The map's pin row is where it showed: three
+ * buttons meant to be `xs`, one of them 36px tall next to two 30px ones.
+ *
+ * Defaulting to 'medium' and passing that through would have fixed the bug by breaking
+ * everything else -- every APIButton that names no size would have grown from `sm` to
+ * `md`. Undefined lets Button's own default stand, so only the call sites that asked for
+ * something see a change.
+ */
+ size,
floated,
onClick,
disabled,
@@ -1795,7 +1807,7 @@ export function useAPIButton(
// `color` was a Semantic color name; a role carries the meaning instead, and a
// caller that really wants a color can still pass one through `props`.
const buttonArgs = {
- onClick: localOnClick, disabled, loading, type,
+ onClick: localOnClick, disabled, loading, type, size,
...props,
};
if (id) {
diff --git a/app/src/components/Map.js b/app/src/components/Map.js
index bb649c1f..46b832f3 100644
--- a/app/src/components/Map.js
+++ b/app/src/components/Map.js
@@ -15,7 +15,7 @@ import {
deleteMapFile, deleteMapPin, fetchMapSubscriptions, getMapFiles, getMapPins,
mapSubscribe, mapUnsubscribe, rebuildMapSearchIndex, updateMapPin
} from "../api";
-import {Button, Divider, Header, Icon, Modal, Table, TextInput} from "./ui";
+import {Button, Divider, Group, Header, Icon, Modal, Table, TextInput} from "./ui";
import {SortableTable} from "./SortableTable";
import {Media, StatusContext} from "../contexts/contexts";
import {MAP_VIEWER_URI} from "./Vars";
@@ -229,19 +229,23 @@ function MapCatalogRow({item, subscribedRegions, fetchData}) {
{name}{humanFileSize(size_estimate)}
- {bbox &&
{previewOpen && {pin.lat.toFixed(4)}, {pin.lon.toFixed(4)}
{pin.created}
- label.trim() && onSave(pin.id, label.trim(), color)}>Save
- Cancel
+ {/* A Group, not bare siblings: inline-block controls align on text baselines they
+ do not share, and JSX leaves no whitespace between them to space them out. */}
+
+ label.trim() && onSave(pin.id, label.trim(), color)}>Save
+ Cancel
+
;
}
@@ -524,21 +533,24 @@ function MapPins() {
{pin.created}
- setEditingId(pin.id)}/>
-
- handleDelete(pin.id)}
- />
+ {/* See PinEditRow: a Group so the three controls line up and are spaced. */}
+
+ setEditingId(pin.id)}/>
+
+ handleDelete(pin.id)}
+ />
+
;
};
diff --git a/app/src/components/Map.test.js b/app/src/components/Map.test.js
new file mode 100644
index 00000000..d8b99bc7
--- /dev/null
+++ b/app/src/components/Map.test.js
@@ -0,0 +1,78 @@
+import fs from 'fs';
+import path from 'path';
+
+/*
+ * The map pin table's action cells.
+ *
+ * Each row offers edit, add-to-playlist and delete, and they were laid out as bare siblings in
+ * a table cell. That makes them inline-block boxes aligned on their text BASELINES, and a
+ * Button's baseline is not an ActionIcon's -- measured on the running app, the middle control
+ * sat 4.3px above the other two -- and they touched, because JSX leaves no whitespace between
+ * elements. `Group` is what every other row of buttons in the app uses.
+ *
+ * Checked in the source because neither row is reachable from a test that could measure it:
+ * `MapPins` fetches its pins from the API and builds its rows through SortableTable, and the
+ * row builders are internal to the module. ui-layout.cy.js measures the pattern itself --
+ * that bare siblings really are misaligned and that a Group really does fix it -- so what is
+ * left to guard is that these cells use one.
+ */
+
+const source = fs.readFileSync(path.join(__dirname, 'Map.js'), 'utf8');
+
+/** The contents of every `` in the file. */
+const cells = () => {
+ const found = [];
+ const open = '', at);
+ if (end !== -1) found.push(source.slice(at, end));
+ }
+ return found;
+};
+
+describe('the map pin action cells', () => {
+ it('finds the cells at all', () => {
+ // The premise. A parser that matched nothing would report no offenders and read
+ // exactly like a file that was already correct.
+ expect(cells().length).toBeGreaterThan(5);
+ });
+
+ /*
+ * Named cells, not a count of control tags.
+ *
+ * Counting was tried first and does not work: a cell whose buttons are the two arms of a
+ * ternary renders exactly one of them and needs no Group -- the "Built" / "Build" cell on
+ * the map files table is that shape -- and excluding ternaries to allow for it also
+ * excluded the subscribe cell, whose `role={isSubscribed ? ... : ...}` has nothing to do
+ * with how many controls it holds. A guard that quietly stops covering a cell is worse
+ * than one with a stated scope.
+ *
+ * So each cell is named by something only it contains, and the general claim -- that bare
+ * inline controls really are misaligned and that a Group really does fix it -- is measured
+ * in ui-layout.cy.js instead.
+ */
+ const rows = [
+ {name: 'pin actions', marker: 'setEditingId(pin.id)'},
+ /*
+ * `role='cancel'`, not `onSave(...)`: the edit row's TextInput calls onSave from its
+ * own onKeyDown, in a different cell, so that marker matched the input's cell and this
+ * quietly checked the wrong one. A marker has to be unique to the cell it names.
+ */
+ {name: 'pin edit save/cancel', marker: "role='cancel'"},
+ {name: 'map file subscribe', marker: 'setPreviewOpen(true)'},
+ ];
+
+ rows.forEach(({name, marker}) => {
+ it(`groups the ${name} cell`, () => {
+ const cell = cells().find(candidate => candidate.includes(marker));
+
+ /*
+ * The premise and the claim in one object, because jest's `expect` takes no
+ * message argument -- that is chai, and passing one throws rather than annotating.
+ * A rename of the marker would otherwise turn this into a test of nothing.
+ */
+ expect({marker, found: cell !== undefined, grouped: !!cell?.includes('((
className={[fromRole?.className, className].filter(Boolean).join(' ') || undefined}
leftSection={soleIcon ? undefined : renderIcon(icon)}
rightSection={soleIcon ? undefined : renderIcon(iconAfter)}
+ /*
+ * Marks the icon-only case for ui.css, which makes such a button square so it matches
+ * an IconButton of the same size. A Button is as wide as its content plus padding and
+ * an ActionIcon is square, so a row mixing the two -- the map's pin actions are edit
+ * (Button), add-to-playlist (IconButton) and delete (Button) -- came out 46, 30 and 46
+ * wide at the same nominal size.
+ */
+ data-icon-only={soleIcon ? 'true' : undefined}
{...props}
size={resolveSize(props.size)}
>
diff --git a/app/src/components/ui/ui-layout.cy.js b/app/src/components/ui/ui-layout.cy.js
index 321c5113..4c408092 100644
--- a/app/src/components/ui/ui-layout.cy.js
+++ b/app/src/components/ui/ui-layout.cy.js
@@ -1,7 +1,7 @@
import React from 'react';
import {
ActionInput, Button, Card, Header, Icon, IconButton, IconStack, Loading, MultiSelect, Panel, PathInput,
- Message, Pagination, Placeholder, Progress, SearchBox, Statistic, StatisticGroup, Status, TabBar, Table,
+ Group, Message, Pagination, Placeholder, Progress, SearchBox, Statistic, StatisticGroup, Status, TabBar, Table,
tabClassName, TextInput,
} from './index';
import {MemoryRouter} from 'react-router';
@@ -13,6 +13,7 @@ import {monochromeThemes, themeNames} from '../../themes/names';
import {navColorNames} from '../../themes/navColors';
import {NavBarSample} from '../ThemeSamplePage';
import {DesktopNav, NavIconWrapper} from '../Nav';
+import {APIButton} from '../Common';
import {ShareButton} from '../Share';
/* `--panel` is authored as a hex; computed backgrounds come back as rgb(). */
@@ -3358,3 +3359,178 @@ describe('the search field\'s clear button is attached to it', () => {
});
});
});
+
+describe('icon-only action buttons in a row are one size', () => {
+ /*
+ * The map's pin table gives every row three actions: edit, add-to-playlist and delete,
+ * all asking for `size='xs'`. They rendered 46x30, 30x30 and 54x36 -- three different
+ * sizes, for three different reasons.
+ *
+ * Two of those are structural. `AddToPlaylistButton` renders an IconButton when it has no
+ * label, and an ActionIcon is square by construction, while a Button is as wide as its
+ * content plus its horizontal padding. Their heights already agree, because ActionIcon's
+ * size scale was remapped onto Button's; width was never aligned.
+ *
+ * The third is a plain bug: `useAPIButton` never put `size` into the props it hands to
+ * Button, so every APIButton in the app rendered at Mantine's default regardless of what
+ * its call site asked for. Seventeen call sites pass a size, from `xs` here to `huge` on
+ * Settings.
+ */
+ const sizes = ['xs', 'sm', 'md', 'lg'];
+
+ sizes.forEach((size) => {
+ it(`gives an icon-only Button and an IconButton the same box at ${size}`, () => {
+ cy.mountUI(
+
+
+
);
+
+ cy.get('[data-testid="action"]').should(($action) => {
+ const button = Cypress.$('[data-testid="plain"]')[0].getBoundingClientRect();
+ const icon = $action[0].getBoundingClientRect();
+
+ expect(button.height, `${size} heights`).to.be.closeTo(icon.height, 1);
+ expect(button.width, `${size} widths`).to.be.closeTo(icon.width, 1);
+ });
+ });
+ });
+
+ it('makes an icon-only button square, not merely equal to its neighbour', () => {
+ // Stated separately: two buttons could agree with each other and both be wrong. A
+ // lone glyph in a control belongs in a square one.
+ cy.mountUI();
+
+ cy.get('[data-testid="plain"]').should(($button) => {
+ const box = $button[0].getBoundingClientRect();
+
+ expect(box.width, 'square').to.be.closeTo(box.height, 1);
+ });
+ });
+
+ it('is a real constraint: a labelled button is still as wide as its label', () => {
+ // The inverse. Squaring must apply only to the icon-only case, or every labelled
+ // button in the app collapses to a square and clips its text.
+ cy.mountUI(Edit this pin);
+
+ cy.get('[data-testid="labelled"]').should(($button) => {
+ const box = $button[0].getBoundingClientRect();
+
+ expect(box.width, 'wider than it is tall').to.be.greaterThan(box.height * 2);
+ });
+ });
+});
+
+describe('APIButton honours the size its call site asks for', () => {
+ /*
+ * `useAPIButton` assembled the props it hands to Button and left `size` out, so it was
+ * dropped at every call site -- seventeen of them, from the map pins' `xs` to Settings'
+ * `huge`. The map's delete pin came out 36px tall beside two 30px siblings.
+ */
+ it('renders a small APIButton smaller than a large one', () => {
+ cy.mountUI(
);
+
+ cy.get('[data-testid="large"]').should(($large) => {
+ const small = Cypress.$('[data-testid="small"]')[0].getBoundingClientRect();
+
+ expect(small.height, 'xs is shorter than lg')
+ .to.be.lessThan($large[0].getBoundingClientRect().height - 4);
+ });
+ });
+
+ it('matches a plain Button given the same size', () => {
+ // The claim that matters at the call site: an APIButton and a Button asking for the
+ // same size are the same control.
+ cy.mountUI(
+ {}} data-testid='api'/>
+
+
);
+
+ cy.get('[data-testid="api"]').should(($api) => {
+ const plain = Cypress.$('[data-testid="plain"]')[0].getBoundingClientRect();
+ const api = $api[0].getBoundingClientRect();
+
+ expect(api.height, 'heights').to.be.closeTo(plain.height, 1);
+ expect(api.width, 'widths').to.be.closeTo(plain.width, 1);
+ });
+ });
+
+ it('is a real constraint: an APIButton with no size keeps the default it had', () => {
+ /*
+ * `useAPIButton` declared `size = 'medium'` as a parameter default while never using
+ * it. Passing that through would have fixed the bug by breaking everything else --
+ * every APIButton that names no size would have grown from Mantine's `sm` to `md`.
+ */
+ cy.mountUI(
+ {}} data-testid='default'/>
+
+
);
+
+ cy.get('[data-testid="default"]').should(($api) => {
+ const plain = Cypress.$('[data-testid="plain"]')[0].getBoundingClientRect();
+
+ expect($api[0].getBoundingClientRect().height, 'unchanged default')
+ .to.be.closeTo(plain.height, 1);
+ });
+ });
+});
+
+describe('a row of icon controls sits level and spaced', () => {
+ /*
+ * The map's pin actions are three icon controls in one table cell: edit (Button),
+ * add-to-playlist (IconButton) and delete (APIButton). They were laid out as bare
+ * siblings, so they were inline-block boxes aligned on their BASELINES -- and a Button's
+ * baseline is not an ActionIcon's, so the middle one sat 4.3px higher than the other two.
+ * They also touched, because JSX leaves no whitespace between elements.
+ *
+ * Both are what `Group` is for, which is how every other row of buttons in the app is
+ * built. Measured on the running app at tops 258.6 / 254.2 / 258.6 before the fix.
+ */
+ const controls = <>
+
+
+ {}} data-testid='delete'/>
+ >;
+
+ const tops = (root) => ['edit', 'add', 'delete']
+ .map(id => root.querySelector(`[data-testid="${id}"]`).getBoundingClientRect().top);
+
+ it('is misaligned without a Group, which is why one is needed', () => {
+ /*
+ * The premise for the case below, and the thing a reader will not believe otherwise:
+ * three controls of identical height still do not line up when they are laid out
+ * inline, because they are aligned on text baselines they do not share.
+ */
+ cy.mountUI(
{controls}
);
+
+ cy.get('[data-testid="bare"]').should(($bare) => {
+ const spread = Math.max(...tops($bare[0])) - Math.min(...tops($bare[0]));
+
+ expect(spread, 'bare siblings do not line up').to.be.greaterThan(1);
+ });
+ });
+
+ it('lines them up when wrapped in a Group', () => {
+ cy.mountUI({controls});
+
+ cy.get('[data-testid="grouped"]').should(($group) => {
+ const spread = Math.max(...tops($group[0])) - Math.min(...tops($group[0]));
+
+ expect(spread, 'all three share a top edge').to.be.lessThan(1);
+ });
+ });
+
+ it('leaves a gap between them', () => {
+ cy.mountUI({controls});
+
+ cy.get('[data-testid="grouped"]').should(($group) => {
+ const boxes = ['edit', 'add', 'delete']
+ .map(id => $group[0].querySelector(`[data-testid="${id}"]`).getBoundingClientRect());
+
+ expect(boxes[1].left - boxes[0].right, 'first gap').to.be.greaterThan(2);
+ expect(boxes[2].left - boxes[1].right, 'second gap').to.be.greaterThan(2);
+ });
+ });
+});
diff --git a/app/src/components/ui/ui.css b/app/src/components/ui/ui.css
index 1446b0d5..c4ea1251 100644
--- a/app/src/components/ui/ui.css
+++ b/app/src/components/ui/ui.css
@@ -1565,3 +1565,20 @@ html[data-theme="night"] .wrolpi-button-danger[data-disabled]:not([data-loading]
color: var(--danger);
border: 1.5px dashed var(--danger);
}
+
+/*
+ * A button whose only content is an icon is square, like the ActionIcon it sits beside.
+ *
+ * A Button is as wide as its content plus its horizontal padding; an ActionIcon is square by
+ * construction. So a row mixing the two at one nominal size came out at different widths --
+ * the map's pin actions are edit (Button), add-to-playlist (IconButton) and delete (Button),
+ * and measured 46, 30 and 46 wide. Their heights already agree, because ActionIcon's scale
+ * was remapped onto Button's; this is the other axis of the same alignment.
+ *
+ * `--button-height` is Mantine's own per-size height, so the two stay in step through every
+ * size without a table here to keep current.
+ */
+html .mantine-Button-root[data-icon-only] {
+ width: var(--button-height);
+ padding: 0;
+}