Open smhigley opened 3 weeks ago
label
: right now this overrides the displayed text of the<option>
if defined. Repurposing this to no longer override the text could be considered breaking (maybe?), although otherwise this feels like a good fit.
I agree it feels like a good fit, but going through with it is probably going to be complicated. The current behavior is very unfortunate. Hopefully we can just stop rendering the label attribute for the new mode: https://github.com/openui/open-ui/issues/1115
value
: even though the word "value" captures the idea of this feature, repurposing current behavior ofvalue
-- which is the form-submitted non-human-readable value -- would be a bigger and more breaking change.
Yeah I'm not sure the value attribute should be used for typeahead or anything thats exposed to the user at all.
Assuming we add or repurpose an attribute for this, should that attribute ever be used as the displayed text in the select trigger?
It sounds like ideally we would not use the label attribute when rendering anything so that it could be used for this use case.
Should it ever be used in the calculation of the accessible value string? (which should probably match the displayed text most of the time)
Great question!
I think we still need to figure out how we are going to incorproate the option label attribute for accessibility mappings, but
Proposed resolution: Use the option's label attribute for typeahead. If there is no label attribute, then use the option's text content for typeahead.
The tone about standardizing keyboard behavior makes me believe that getting interoperable typeahead isn't going to be possible: https://github.com/openui/open-ui/issues/1087
I think this means that we can't add a new attribute for typeahead, but I'm happy to implement whatever typeahead behavior you think is best in chromium.
The Open UI Community Group just discussed select: provide a way for authors to define the string value of rich options
.
Introducing the ability to render structured rich content within options also introduces the need for authors to be able to separately define the rendered DOM in the option vs. the string-typed text used for features like typeahead / type-to-navigate.
I ran into this exact issue while creating the Dropdown & Combobox controls in the library I work on. A concrete example can be found in UI like this:
When displaying the selected value in the trigger button we only want to display the text of the person's name. This is currently possible using
<selectedoption>
+ custom CSSdisplay: none
styles. What isn't currently possible is enabling users to type e.g "Elv" to jump to "Elvia Atkins", Or repeatedly typing the same letter to cycle through multiple people whose names all start with that letter.The best we can do as a browser fallback is to use the text content of the entire option, which is not always conceptually the text that a user would try to type. That still seems fine to me as a default, but authors who want to do the right thing currently have no ability to customize this.
The other potential reason for needing this is if we keep the same
<option>
model & attributes in a future editable select, there will need to be a way to define what string-only value gets inserted into the<input>
when an option is selected.Solutions
There are a couple current HTML attributes on the option element that are at least conceptually similar to this idea:
label
: right now this overrides the displayed text of the<option>
if defined. Repurposing this to no longer override the text could be considered breaking (maybe?), although otherwise this feels like a good fit.value
: even though the word "value" captures the idea of this feature, repurposing current behavior ofvalue
-- which is the form-submitted non-human-readable value -- would be a bigger and more breaking change.The other option (heh) is to create a new HTML attribute specifically for the string version of option's primary text. This is what we do in my library, using
text
. For example, the options in the above screenshot have roughly this code:Open questions:
Related: #1117