sveltejs / svelte

web development for the rest of us
https://svelte.dev
MIT License
80.02k stars 4.26k forks source link

Readonly input with on:click event should be warned. #9977

Closed hyunbinseo closed 2 weeks ago

hyunbinseo commented 11 months ago

Description

The read-only input cannot be clicked with keyboard.

<input on:click={() => {}} type="text" readonly />

Proposed solution

It should show a similar error to this.

A11y: visible, non-interactive elements with an on:click event must be accompanied by a keyboard event handler.

<div on:click={() => {}}></div>

Alternatives

No response

Additional Information, eg. Screenshots

Since there was a similar S/O post that got multiple down votes, some explanation.

I am using the following workflow.

I've landed on the following solution / workaround.

<input on:click={reset} type="text" readonly />
<button on:click={reset} type="button" class="sr-only">Reset</button>
jasonlyu123 commented 11 months ago

I don't think clicking on text input to reset is common. So not sure who will benefit from this.

hyunbinseo commented 11 months ago

Thanks for the repository transfer.

How about click the read-only input to copy the URL?

I can't find an exact example - haven't wrote it down somewhere.

But here is an example that uses a read-only input - mobile HiMart.

스크린샷 2023-12-21 오전 10 26 54
theetrain commented 2 months ago

You could place a 'copy' button adjacent to the input, similar to the "URL" label in your example. I believe the common expectation for a readonly input is to be able to select its contents manually, and possibly copy their contents.

With that said I don't think a warning is really needed here. Though if there can be a less-severe "info" notice about "click handlers cannot be triggered by the keyboard on an input" (with or without readonly), I can see that as being helpful.

dummdidumm commented 2 weeks ago

Closing - as other point out, a warning isn't justified for such an edge case.