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.
This commit is contained in:
Abdessamad Derraz committed 2026-11-19 18:42:55 +01:00
1 parent 9760c2fadd
commit b2ec1969e0
2 files changed
+8 -7

No files matched your search

+7 -6
View File
@@ -32,9 +32,11 @@ if (project.trailingSlash === 'never') dataAttributes['data-strip-trailing-slash
>
<Icon name="magnifier" />
<span class="sl-hidden md:sl-block" aria-hidden="true">{Astro.locals.t('search.label')}</span>
<kbd class="sl-hidden md:sl-flex" style="display: none;">
<kbd data-key={Astro.locals.t('search.ctrlKey')}></kbd><kbd data-key="K"></kbd>
</kbd>
<kbd
class="sl-hidden md:sl-flex"
style="display: none;"
data-key={`${Astro.locals.t('search.ctrlKey')} K`}
></kbd>
</button>
<dialog style="padding:0" aria-label={Astro.locals.t('search.label')}>
@@ -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 = '';