From b2ec1969e085ddfe666eb24c5a30a37d43d812ca Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Thu, 19 Nov 2026 18:07:42 +0100 Subject: [PATCH] refactor: hold the search hint in one attribute Two empty kbd elements with a data-key each added 24 bytes to every page and put RomM over its weight budget in test_site_platform_density. The hint is one data-key on the outer kbd, 50 bytes lighter than the text it replaced. --- tests/test_site_components.py | 2 +- website/src/components/Search.astro | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/tests/test_site_components.py b/tests/test_site_components.py index c96414a2a..4b8ce1327 100644 --- a/tests/test_site_components.py +++ b/tests/test_site_components.py @@ -1019,7 +1019,7 @@ class SearchButtonShowsOnlyItsName(unittest.TestCase): text = re.sub(r"<[^>]*>", "", button[button.index(">", button.index("aria-keyshortcuts")) + 1:]) self.assertEqual(text.split(), ["{Astro.locals.t('search.label')}"]) self.assertIn("kbd[data-key]::before", search) - self.assertIn("platformKey.dataset.key = '⌘';", search) + self.assertIn("shortcut.dataset.key = '⌘ K';", search) class LogosAtTheirWeight(unittest.TestCase): diff --git a/website/src/components/Search.astro b/website/src/components/Search.astro index 056b347ff..9cb6acfb2 100644 --- a/website/src/components/Search.astro +++ b/website/src/components/Search.astro @@ -32,9 +32,11 @@ if (project.trailingSlash === 'never') dataAttributes['data-strip-trailing-slash > - + @@ -69,9 +71,8 @@ if (project.trailingSlash === 'never') dataAttributes['data-strip-trailing-slash const openBtn = document.querySelector('button[data-open-modal]'); const shortcut = openBtn?.querySelector('kbd'); if (!openBtn || !(shortcut instanceof HTMLElement)) return; - const platformKey = shortcut.querySelector('kbd'); - if (platformKey && /(Mac|iPhone|iPod|iPad)/i.test(navigator.platform)) { - platformKey.dataset.key = '⌘'; + if (/(Mac|iPhone|iPod|iPad)/i.test(navigator.platform)) { + shortcut.dataset.key = '⌘ K'; openBtn.setAttribute('aria-keyshortcuts', 'Meta+K'); } shortcut.style.display = '';