Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<datalist> displaying both label and values for option elements is a little confusing #10594

Open
joshdales opened this issue Sep 1, 2024 · 2 comments

Comments

@joshdales
Copy link

joshdales commented Sep 1, 2024

What is the issue with the HTML Standard?

When using a datalist it is not obvious reading the spec that both the label and value will be shown, and even then that value takes precedence when displayed. When I use an option in a select element I don't see the value I only see the label, but when used in a datalist the value is always present and takes a high emphasis over the label.

I know that the spec is clear that the datalist is distinct from a select element however it does not mention anything about this and as they both use option elements I would have expected the behaviour to be closer to each other.

I've used this before and it's always found this behaviour slightly confusing and it's caused a few problems. As I didn't want to show the value just the label (like a select) but wanted the input & datalist to function as a select-like element that you can type in. As such I just had to just display the label text and then match that to the matching value with JS once it had been selected, rather than just rely on the value.

@joshdales joshdales changed the title <datalist> displaying both label and values in option elements <datalist> displaying both label and values for option elements Sep 1, 2024
@joshdales joshdales changed the title <datalist> displaying both label and values for option elements <datalist> displaying both label and values for option elements is a little confusing Sep 1, 2024
@annevk
Copy link
Member

annevk commented Sep 2, 2024

While user agents can tweak what is presented, the script-observable behavior cannot be changed without some kind of additional opt-in feature.

But perhaps steering it all towards a list of values is best as an end user is able to change them afterwards after all.

@joshdales
Copy link
Author

That makes sense - and I think was a misunderstanding on my part when I first used it. And I think that was probably because I expected it to be behave more like the option list in a select.

I wonder if it might be worth more explicitly calling that out?

@whatwg whatwg deleted a comment from Jayok123456 Sep 19, 2024
@whatwg whatwg deleted a comment from Jayok123456 Sep 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants