diff --git a/CHANGELOG.md b/CHANGELOG.md index e89a6baab..2df8f1e72 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## unreleased +- Set `wrap` on a `big_number` component to show long titles and descriptions across multiple lines. + ## v0.48.0 (2026-11-12) - Updated Rust and browser dependencies, including ApexCharts 8.8.1, Tabler 1.7.4, Tabler icons 3.51, and Tom Select 2.7. Chart series names and labels now display HTML as text, fixing upstream script injection in legends and tooltips. diff --git a/examples/official-site/sqlpage/migrations/49_big_number.sql b/examples/official-site/sqlpage/migrations/49_big_number.sql index 42e93e968..acdb2858d 100644 --- a/examples/official-site/sqlpage/migrations/49_big_number.sql +++ b/examples/official-site/sqlpage/migrations/49_big_number.sql @@ -8,6 +8,7 @@ INSERT INTO component(name, icon, description, introduced_in_version) VALUES INSERT INTO parameter(component, name, description, type, top_level, optional) SELECT 'big_number', * FROM (VALUES -- Top-level parameters (for the whole big_number list) ('columns', 'The number of columns to display the big numbers in (default is one column per item).', 'INTEGER', TRUE, TRUE), + ('wrap', 'Wrap long titles and descriptions onto multiple lines. By default, they are truncated with an ellipsis.', 'BOOLEAN', TRUE, TRUE), -- id and class, at both levels, come from 99_shared_id_class_attributes.sql -- Item-level parameters (for each big number) ('title', 'The title or label for the big number.', 'TEXT', FALSE, TRUE), diff --git a/sqlpage/templates/big_number.handlebars b/sqlpage/templates/big_number.handlebars index 385b2ccfa..8f469376f 100644 --- a/sqlpage/templates/big_number.handlebars +++ b/sqlpage/templates/big_number.handlebars @@ -8,12 +8,12 @@ {{#unless ../columns}}style="min-width: 9rem;"{{/unless}} {{~#if id}} id="{{id}}"{{/if~}} > -
+
{{#if title}}
-
+
{{#if title_link}} -
{{description}}
+
{{description}}
{{#if change_percent}}
diff --git a/tests/end-to-end/fixtures/big-number/index.sql b/tests/end-to-end/fixtures/big-number/index.sql index 6070f5b31..b826f1790 100644 --- a/tests/end-to-end/fixtures/big-number/index.sql +++ b/tests/end-to-end/fixtures/big-number/index.sql @@ -21,3 +21,13 @@ SELECT 'default-color' AS id, 'Default value' AS title, '9,012' AS value; + +SELECT 'big_number' AS component, 2 AS columns, $wrap = 'true' AS wrap; + +SELECT + 'long-text' AS id, + 'Items checked across all locations during the reporting period' AS title, + 120 AS value, + 'Includes items from the main collection and all storage locations.' AS description; + +SELECT 'short-text' AS id, 'Locations' AS title, 8 AS value; diff --git a/tests/end-to-end/fixtures/big-number/test.ts b/tests/end-to-end/fixtures/big-number/test.ts index 8dd52dc06..d4bee5c1e 100644 --- a/tests/end-to-end/fixtures/big-number/test.ts +++ b/tests/end-to-end/fixtures/big-number/test.ts @@ -42,3 +42,37 @@ for (const theme of ["light", "dark"]) { } }); } + +test("long titles and descriptions wrap only when requested", async ({ + page, +}) => { + await page.setViewportSize({ width: 640, height: 800 }); + for (const wrap of [false, true]) { + await page.goto(`/big-number/?wrap=${wrap}`); + const card = page.locator("#long-text .card"); + const title = card.getByText("Items checked across all locations", { + exact: false, + }); + const description = card.getByText( + "Includes items from the main collection", + { + exact: false, + }, + ); + for (const text of [title, description]) { + const layout = await text.evaluate((element) => ({ + clipped: element.scrollWidth > element.clientWidth, + multiline: + element.clientHeight > + 1.5 * Number.parseFloat(getComputedStyle(element).lineHeight), + })); + expect(layout).toEqual({ clipped: !wrap, multiline: wrap }); + } + if (wrap) { + const neighbor = page.locator("#short-text .card"); + expect((await card.boundingBox())?.height).toBe( + (await neighbor.boundingBox())?.height, + ); + } + } +});