Skip to content

Commit 5c39999

Browse files
authored
fix(citation): only use doc-noteref role on the linked form (#3546)
1 parent 4d9726d commit 5c39999

3 files changed

Lines changed: 18 additions & 3 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@astryxdesign/core': patch
3+
---
4+
5+
[fix] Citation: only apply `role="doc-noteref"` on the linked (anchor) form. On a plain unlinked span the role is not permitted (axe: aria-allowed-role), so it is omitted there while the `aria-label` still names the citation. (#3343)
6+
7+
@cixzhang

packages/core/src/Citation/Citation.test.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,11 @@ describe('Citation', () => {
6161
data-testid="citation"
6262
/>,
6363
);
64-
expect(screen.getByTestId('citation').tagName).toBe('SPAN');
64+
const el = screen.getByTestId('citation');
65+
expect(el.tagName).toBe('SPAN');
66+
// doc-noteref is a reference role that is not permitted on a plain
67+
// (unlinked) span (axe: aria-allowed-role), so it must be omitted here.
68+
expect(el).not.toHaveAttribute('role');
6569
});
6670

6771
it('renders astryx-* class names for theme targeting', () => {

packages/core/src/Citation/Citation.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@ export function Citation({
158158
const href = source.url;
159159
const icon = source.icon;
160160
const Tag = href ? 'a' : 'span';
161+
// `doc-noteref` is a reference role — only appropriate on the interactive
162+
// link form. On a plain (unlinked) span it is not a permitted role
163+
// (axe: aria-allowed-role), so omit it there; the aria-label still names it.
164+
const noteRole = href ? ('doc-noteref' as const) : undefined;
161165
const linkProps = href
162166
? {
163167
href,
@@ -176,7 +180,7 @@ export function Citation({
176180
<Tag
177181
{...rest}
178182
ref={elementRef}
179-
role="doc-noteref"
183+
role={noteRole}
180184
aria-label={`Citation ${number}: ${title}`}
181185
data-testid={testId}
182186
{...linkProps}
@@ -199,7 +203,7 @@ export function Citation({
199203
<Tag
200204
{...rest}
201205
ref={elementRef}
202-
role="doc-noteref"
206+
role={noteRole}
203207
aria-label={`Citation ${number}: ${title}`}
204208
data-testid={testId}
205209
{...linkProps}

0 commit comments

Comments
 (0)