Skip to content

Commit f999826

Browse files
committed
fix: address CodeRabbit findings on #431
1. Mobile lang-toggle still had hardcoded aria-label="Toggle language". Now uses i18n.t('header.langToggleAria') + data-i18n-aria, matching the desktop fix from the parent commit. 2. de.json aria-label was English ("EN — switch to English"). Now properly localized: "EN — zu Englisch wechseln". 3. Anchor card heading ids are now namespaced with the category id. An anchor can belong to multiple categories and is rendered once per category section, so the previous "anchor-card-title-<id>" pattern produced duplicate DOM ids for those anchors. New pattern: "anchor-card-title-<categoryId>-<anchorId>".
1 parent d275104 commit f999826

3 files changed

Lines changed: 15 additions & 7 deletions

File tree

website/src/components/card-grid.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,21 @@ function renderCategorySection(category, allAnchors) {
9090
</h2>
9191
9292
<div class="anchor-cards-grid">
93-
${categoryAnchors.map((anchor) => renderAnchorCard(anchor, color)).join('')}
93+
${categoryAnchors.map((anchor) => renderAnchorCard(anchor, color, category.id)).join('')}
9494
</div>
9595
</section>
9696
`
9797
}
9898

9999
/**
100-
* Render a single anchor card
100+
* Render a single anchor card.
101+
*
102+
* The optional `categoryId` argument is used to namespace the heading id
103+
* used by `aria-labelledby`, since the same anchor may appear in multiple
104+
* category sections (anchors can belong to more than one category) and
105+
* the DOM must not contain duplicate ids.
101106
*/
102-
function renderAnchorCard(anchor, categoryColor) {
107+
function renderAnchorCard(anchor, categoryColor, categoryId) {
103108
const isUmbrella = anchor.subAnchors && anchor.subAnchors.length > 0
104109
const umbrellaClass = isUmbrella ? ' anchor-card-umbrella' : ''
105110
const rolesCount = anchor.roles ? anchor.roles.length : 0
@@ -110,6 +115,8 @@ function renderAnchorCard(anchor, categoryColor) {
110115
const editTitle = i18n.t('card.edit')
111116
const copyLinkTitle = i18n.t('card.copyLink')
112117
const safeId = escapeHtml(anchor.id)
118+
const safeCategoryId = escapeHtml(categoryId || 'uncat')
119+
const cardTitleId = `anchor-card-title-${safeCategoryId}-${safeId}`
113120

114121
return `
115122
<div
@@ -119,10 +126,10 @@ function renderAnchorCard(anchor, categoryColor) {
119126
data-tags="${escapeHtml(anchor.tags ? anchor.tags.join(',') : '')}"
120127
tabindex="0"
121128
role="button"
122-
aria-labelledby="anchor-card-title-${safeId}"
129+
aria-labelledby="${cardTitleId}"
123130
>
124131
<div class="anchor-card-header">
125-
<h3 id="anchor-card-title-${safeId}" class="anchor-card-title">${escapeHtml(anchor.title)}</h3>
132+
<h3 id="${cardTitleId}" class="anchor-card-title">${escapeHtml(anchor.title)}</h3>
126133
<div class="flex gap-1">
127134
<button
128135
class="anchor-copy-link-btn"

website/src/components/header.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ export function renderHeader() {
120120
<button
121121
id="lang-toggle-mobile"
122122
class="rounded-md px-2 py-1 text-sm font-medium text-[var(--color-text-secondary)] hover:text-[var(--color-text)] hover:bg-[var(--color-bg-secondary)] transition-colors"
123-
aria-label="Toggle language"
123+
aria-label="${i18n.t('header.langToggleAria')}"
124+
data-i18n-aria="header.langToggleAria"
124125
>${langLabel}</button>
125126
<button
126127
id="theme-toggle-mobile"

website/src/translations/de.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"app.title": "Semantic Anchors",
33
"app.description": "Gemeinsames Vokabular für LLM-Kommunikation",
44
"header.langToggle": "EN",
5-
"header.langToggleAria": "EN — switch to English",
5+
"header.langToggleAria": "EN — zu Englisch wechseln",
66
"header.slogan": "Ein Wort, und die KI versteht den Rest.",
77
"header.themeToggle.dark": "Zum Dunkelmodus wechseln",
88
"header.themeToggle.light": "Zum Hellmodus wechseln",

0 commit comments

Comments
 (0)