mskocik / svelecte

Flexible autocomplete/select component written in Svelte,
https://svelecte.vercel.app
MIT License
469 stars 42 forks source link

Are IDs needed by Svelecte? #229

Closed jamesst20 closed 5 months ago

jamesst20 commented 5 months ago

Hi,

Simply a quick question, does Svelecte have any use for the element ID it uses internally?

Personally I don't make any use of IDs in my projects, however I always end up having this warning

[DOM] Found 4 elements with non-unique id #sv-svelecte-select

so I always end up wrapping it in a component to generate random ID (name) to get rid of the warning.

I think it's a good thing to be able to pass an ID, but maybe we could leave it unset if it's undefined?

mskocik commented 5 months ago

ID value is based on name property, which defines name property of underlying <select> element. So typically you want to name your Svelecte components correctly.

If you don't use HTML forms for submitting data, you can set name to empty string. In that case underlying <select> is not rendered at all and the warning should disappear.

jamesst20 commented 5 months ago

ID value is based on name property, which defines name property of underlying <select> element. So typically you want to name your Svelecte components correctly.

If you don't use HTML forms for submitting data, you can set name to empty string. In that case underlying <select> is not rendered at all and the warning should disappear.

<Svelecte
    name={""}
[DOM] Found 4 elements with non-unique id #sv--select-input:

There is 2 consecutive - so it appears to not work

mskocik commented 5 months ago

Okay, this is then extended to <input> element. And because name is empty, they have the same id. Set inputId property and warnings will disappear.

It will be fixed eventually, but not right now.