Skip to content

Empty aria-label with role=presentation trips axe presentation-role-conflict #1263

Description

@steve02081504

Describe the bug

When label is unset (default ''), Svg.svelte always sets:

aria-label={label}
role={label ? 'img' : 'presentation'}

That produces role="presentation" and aria-label="". An empty aria-label is still a global ARIA attribute, so axe-core rule presentation-role-conflict fails on every unlabeled icon.

Downstream report: josdejong/svelte-jsoneditor#584 (toolbar icons via svelte-awesome).

This also shows up in the HTML from #965:

aria-label="" role="presentation"

Expected behaviour

When label is empty:

  • omit aria-label entirely (do not set it to "")
  • keep role="presentation"

When label is set: role="img" + non-empty aria-label is fine.

Suggested fix

Only set naming attributes when label is non-empty, e.g.:

role={label ? 'img' : 'presentation'}
{...(label ? { 'aria-label': label } : {})}

Do not pair role="presentation" with aria-hidden="true" by default — aria-hidden is also a global ARIA attribute and trips the same axe rule. Consumers who want aria-hidden can still pass it via restProps; the important part is not emitting an empty aria-label.

Reproduction

<script>
  import Icon from 'svelte-awesome'
  import { faSearch } from '@fortawesome/free-solid-svg-icons'
</script>

<Icon data={faSearch} />

Inspect the SVG: role="presentation" + aria-label="". Run axe with presentation-role-conflict enabled.

Environment

  • svelte-awesome 3.3.5
  • axe-core (presentation-role-conflict)

Downstream follow-up (fount / svelte-jsoneditor#584)

fount Playwright hard-fails on axe hits. Until a fixed svelte-awesome release is consumed by svelte-jsoneditor / vanilla-jsoneditor:

  1. Bump / pick up the fixed svelte-awesome in svelte-jsoneditor
  2. Release a vanilla-jsoneditor that includes it
  3. In fount: bump the CDN pin in src/public/pages/scripts/components/jsonEditor.mjs and remove the temporary aria-ignore for issue 584

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions