mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-22 17:47:48 -06:00
fix: draw the search shortcut hint from CSS
The search button is named "Search" and showed "Ctrl K" as text in its content, so Lighthouse flagged label-content-name-mismatch. The keys are drawn from data-key with ::before, and aria-keyshortcuts still announces the shortcut.
This commit is contained in:
1 parent
76468c6599
commit
7e4192870f
2 files changed
+27
-4
No files matched your search
@@ -984,6 +984,23 @@ class SearchLoadsOnFirstUse(unittest.TestCase):
|
||||
self.assertNotIn("TODO", search)
|
||||
|
||||
|
||||
class SearchButtonShowsOnlyItsName(unittest.TestCase):
|
||||
"""Lighthouse flagged label-content-name-mismatch: the button is named
|
||||
"Search" and showed "Ctrl K" as text. The hint is drawn from data-key,
|
||||
the shortcut is announced by aria-keyshortcuts."""
|
||||
|
||||
def test_no_text_in_the_button_but_its_name(self):
|
||||
search = _read(COMPONENTS / "Search.astro")
|
||||
start = search.index("<button\n\t\tdata-open-modal")
|
||||
button = search[start:search.index("</button>", start)]
|
||||
self.assertIn("aria-label={Astro.locals.t('search.label')}", button)
|
||||
self.assertIn('aria-keyshortcuts="Control+K"', button)
|
||||
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)
|
||||
|
||||
|
||||
class LogosAtTheirWeight(unittest.TestCase):
|
||||
"""2.7: two logos were Inkscape files, one with a 441 x 334 PNG inside."""
|
||||
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
---
|
||||
// Starlight's search (@astrojs/starlight 0.42.6, components/Search.astro),
|
||||
// with one change: the Pagefind UI (ui-core.js, 26 KiB) loads when the
|
||||
// with two changes. The Pagefind UI (ui-core.js, 26 KiB) loads when the
|
||||
// reader reaches for search, a pointer on the button, focus on it, a tap,
|
||||
// Ctrl+K, and not on idle on every page. It was a third of the home page's
|
||||
// weight. The markup and the styles are Starlight's own.
|
||||
// weight. The Ctrl K hint is drawn from data-key, not written as text: the
|
||||
// button is named "Search", the shortcut is in aria-keyshortcuts, and a
|
||||
// visible "Ctrl K" in its content made the name differ from its label
|
||||
// (WCAG 2.5.3). The rest of the markup and the styles are Starlight's own.
|
||||
import { Icon } from '@astrojs/starlight/components';
|
||||
import project from 'virtual:starlight/project-context';
|
||||
|
||||
@@ -30,7 +33,7 @@ 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>{Astro.locals.t('search.ctrlKey')}</kbd><kbd>K</kbd>
|
||||
<kbd data-key={Astro.locals.t('search.ctrlKey')}></kbd><kbd data-key="K"></kbd>
|
||||
</kbd>
|
||||
</button>
|
||||
|
||||
@@ -68,7 +71,7 @@ if (project.trailingSlash === 'never') dataAttributes['data-strip-trailing-slash
|
||||
if (!openBtn || !(shortcut instanceof HTMLElement)) return;
|
||||
const platformKey = shortcut.querySelector('kbd');
|
||||
if (platformKey && /(Mac|iPhone|iPod|iPad)/i.test(navigator.platform)) {
|
||||
platformKey.textContent = '⌘';
|
||||
platformKey.dataset.key = '⌘';
|
||||
openBtn.setAttribute('aria-keyshortcuts', 'Meta+K');
|
||||
}
|
||||
shortcut.style.display = '';
|
||||
@@ -221,6 +224,9 @@ if (project.trailingSlash === 'never') dataAttributes['data-strip-trailing-slash
|
||||
kbd {
|
||||
font-family: var(--__sl-font);
|
||||
}
|
||||
kbd[data-key]::before {
|
||||
content: attr(data-key);
|
||||
}
|
||||
|
||||
dialog {
|
||||
margin: 0;
|
||||
|
||||
Reference in new issue
Block a user