8000 Make a11y warnings on `svelte:element` consistent with computed value(s) of `this` binding · Issue #7939 · sveltejs/svelte · GitHub
[go: up one dir, main page]

Skip to content
Make a11y warnings on svelte:element consistent with computed value(s) of this binding #7939
Closed
@emmnull

Description

@emmnull

Describe the problem

After the recent update touching a11y, dynamic elements (<svelte:element />) often end up coated with warnings that are not valid based on the possible element outcome, breaking the expected consistency from a DX point of view.

Take this simple example:

<script lang="ts">
  export let href: string = undefined;
  export let tabindex: number = undefined;
</script>

<!-- These work as expected -->
<button on:click {tabindex}></button>
<a {href} on:click {tabindex}>Content</a>

<!-- This one doesn't:
  A11y: visible, non-interactive elements with an on:click event must be accompanied by an on:keydown, on:keyup, or on:keypress event.svelte(a11y-click-events-have-key-events)
  A11y: not interactive element cannot have positive tabIndex valuesvelte(a11y-no-noninteractive-tabindex)
-->
<svelte:element this={href ? 'a' : 'button'} {href} on:click {tabindex}>Content</svelte:element>

Describe the proposed solution

Somehow parse the contents of svelte:element's this={}?

Alternatives considered

Quick fix for those who want: mute the concerned warnings.

Importance

nice to have

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0