Skip to content

fix a11y: don't destroy/rebuild form elements #8279

@tomByrer

Description

@tomByrer

Describe the bug

AFAIK, it is bad for a11y & performance if you destroy then attach a new form element if you just want to change the text label of said element. If you keep the same form element around, the tab focus doesn't get lost.

Even the on:click function stays the same in the example.

Reproduction

https://svelte.dev/tutorial/else-blocks

{#if user.loggedIn}
	<button on:click={toggle}>
		Log out
	</button>
{:else}
	<button on:click={toggle}>
		Log in
	</button>
{/if}

vs my proposed

<button on:click={toggle}>
	{#if user.loggedIn}
		Log out
	{:else}
		Log in
	{/if}
</button>

Severity

annoyance

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions