An open source design system that's fully customizable and agent ready
TypeScript
feat(core): the dropdown marker of a field with a list sits in its middle (#7526)
Christopher Chedeau1a2f1dc05bc3
diff --git a/.changeset/reset-list-marker.md b/.changeset/reset-list-marker.mdnew file mode 100644index 0000000000..dd4e81d51b--- /dev/null+++ b/.changeset/reset-list-marker.md@@ -0,0 +1,7 @@+---+'@astryxdesign/core': patch+---++[feat] `reset.css`: in Chromium, the dropdown marker of an `<input>` with a `list` sits in the middle of the field. Chromium sets the marker on the field's line-height, so above a line-height of 1 it sits low, and the reset makes every field inherit the page's 1.5: the marker sat 3.5px below the middle of a 40px field, and further down on taller lines. Date and time fields, whose calendar icon uses the same part, keep their icon where it was. To keep the old placement, add `input[list]::-webkit-calendar-picker-indicator { line-height: inherit; }` after the reset.++@vjeuxdiff --git a/.github/pages/assets/manifest.json b/.github/pages/assets/manifest.jsonindex 7d7b51c961..4c93f5b9fd 100644--- a/.github/pages/assets/manifest.json+++ b/.github/pages/assets/manifest.json@@ -6,7 +6,7 @@},"files": {"reset.css": {- "sha256": "463fa7b4a94245b25ea1bb03836e5cf6a36b9133193a747107fd307f4de7eb07"+ "sha256": "83b02da1fd4b88c734522f2358aa8cefe1ab1b6e35c9621553e8ab9a933a5a5a"},"astryx.css": {"sha256": "5865284828ab722b47d2ce2eeab79496d7f83bfe878286dba9861807f88d5e98"diff --git a/.github/pages/assets/reset.css b/.github/pages/assets/reset.cssindex 0b0231ba2e..a1aa6eff67 100644--- a/.github/pages/assets/reset.css+++ b/.github/pages/assets/reset.css@@ -265,6 +265,15 @@color: var(--color-text-secondary, light-dark(#4E606F, #AAAFB5));}+ /*+ * Chromium draws the dropdown marker of a field with a `list` as a glyph+ * set on the line-height the field inherits, so with any line-height above+ * 1 the marker sits below the middle of the field.+ */+ :where([list])::-webkit-calendar-picker-indicator {+ line-height: 1;+ }+/** Remove the inner padding and cancel buttons in search inputs* for Chrome and Safari.diff --git a/packages/core/src/reset.a11y.chromium.spec.ts b/packages/core/src/reset.a11y.chromium.spec.tsindex 53daf87f6b..31bc60fe5d 100644--- a/packages/core/src/reset.a11y.chromium.spec.ts+++ b/packages/core/src/reset.a11y.chromium.spec.ts@@ -4,7 +4,8 @@* @file reset.a11y.chromium.spec.ts* @input packages/core/src/reset.css, alone on a blank Chromium page* @output Browser evidence that the reset reaches ::before, ::after,- * ::placeholder and the search field's cancel button+ * ::placeholder, the search field's cancel button and the dropdown marker+ * of a field with a list* @position reset.css integration proof. A pseudo-element inside :where() is* invalid, and the forgiving list drops it without an error, so only a* shipping engine shows which of the reset's rules still match.@@ -13,6 +14,8 @@import * as fs from 'node:fs';import {fileURLToPath} from 'node:url';import {expect, test, type Page} from '@playwright/test';+// @ts-expect-error -- pngjs ships no declarations; runtime support is pinned.+import {PNG} from 'pngjs';const RESET_CSS = fs.readFileSync(fileURLToPath(new URL('./reset.css', import.meta.url)),@@ -154,6 +157,54 @@ test('a search field has no cancel button to clear it', async ({page}) => {await expect(query).toHaveValue('query');});+test('the dropdown marker of a field with a list sits in its middle', async ({+ page,+}) => {+ // Chromium shows the marker while the pointer is over the field and draws+ // it as a glyph set on the field's line-height, the 1.5 the reset inherits.+ await page.evaluate(() => {+ const field = document.createElement('input');+ field.id = 'fruit';+ field.setAttribute('list', 'fruits');+ const options = document.createElement('datalist');+ options.id = 'fruits';+ options.append(new Option('Apple'));+ document.body.append(field, options);+ });+ await page.addStyleTag({+ content: `+ #fruit {+ display: block;+ width: 240px;+ padding: 7px 11px;+ border: 1px solid;+ line-height: 1.5;+ }+ `,+ });+ const field = page.locator('#fruit');+ await field.hover();+ const png = PNG.sync.read(await field.screenshot({caret: 'hide'}));+ // The marker is the only ink in the field's last 32px, inside the border.+ const inkRows: number[] = [];+ for (let y = 2; y < png.height - 2; y++) {+ for (let x = png.width - 32; x < png.width - 2; x++) {+ const offset = (y * png.width + x) * 4;+ const luminance =+ (png.data[offset] + png.data[offset + 1] + png.data[offset + 2]) / 3;+ if (luminance < 160) {+ inkRows.push(y);+ break;+ }+ }+ }+ expect(inkRows.length, 'the hovered field shows its marker').toBeGreaterThan(+ 0,+ );+ const markerMiddle = (inkRows[0] + inkRows[inkRows.length - 1] + 1) / 2;+ expect(Math.abs(markerMiddle - png.height / 2)).toBeLessThanOrEqual(1);+});+test('a later layer and an unlayered rule still override the reset', async ({page,}) => {diff --git a/packages/core/src/reset.css b/packages/core/src/reset.cssindex 0b0231ba2e..a1aa6eff67 100644--- a/packages/core/src/reset.css+++ b/packages/core/src/reset.css@@ -265,6 +265,15 @@color: var(--color-text-secondary, light-dark(#4E606F, #AAAFB5));}+ /*+ * Chromium draws the dropdown marker of a field with a `list` as a glyph+ * set on the line-height the field inherits, so with any line-height above+ * 1 the marker sits below the middle of the field.+ */+ :where([list])::-webkit-calendar-picker-indicator {+ line-height: 1;+ }+/** Remove the inner padding and cancel buttons in search inputs* for Chrome and Safari.diff --git a/packages/core/src/reset.test.ts b/packages/core/src/reset.test.tsindex 3aaf57a832..e99e7b6b43 100644--- a/packages/core/src/reset.test.ts+++ b/packages/core/src/reset.test.ts@@ -172,6 +172,17 @@ describe('reset.css pseudo-element rules', () => {).toBe(true);});+ it('sets the dropdown marker of a field with a list on a single line', () => {+ const marker = ruleBlocks.filter(({selector}) =>+ topLevelSelectors(selector).some(entry =>+ entry.endsWith('::-webkit-calendar-picker-indicator'),+ ),+ );+ expect(marker.map(({body}) => body).join('\n')).toMatch(+ /line-height:\s*1;/,+ );+ });+it('falls back to the --color-text-secondary default for placeholders', () => {// A page that loads only the reset never defines the token. The fallback// repeats the token's own default, so that page shows the placeholder an