Description
A while back we discussed #447 about how to handle <select multiple>
, and resolved that this question should be settled through specification of a <listbox>
element supporting single and multi-select. This element would then be used as <selectmenu>
's listbox, and could also be used as a standalone element on the page (similar to <select>
today with size
attribute > 1).
I think we should reconsider this resolution in order to rein in the scope of V1 <selectmenu>
to something that is spec-cable and implementable in a reasonable timeframe. A separate <listbox>
element introduces a lot of complexity and seems to be an inversion of priorities given the clear developer demand for a customizable <select>
vs that for <listbox>
*.
Having <listbox>
/<selectmenu>
as a compound control introduces new issues that don’t currently exist in the platform. In order to be useful as a standalone element on the page, <listbox>
will need to have the full set of APIs associated with form controls (value
, disabled
, checkValidity()
, etc), and will need to be able to participate as part of a <form>
on its own. But when a <listbox>
is used as part of a <selectmenu>
we would need to decide how the <listbox>
’s state is exposed. Does it still have its own value
property, and is its value included separately in form submission? Does it still run its own form validation, or does it delegate to the <selectmenu>
? What happens if the <listbox>
’s disabled
attribute is set, and the <selectmenu>
’s is not, and vice versa?
In short, the use of <listbox>
together with <selectmenu>
makes using <selectmenu>
more complicated for both web developers and for browser implementers without adding any clear value aside from, perhaps, semantic clarity. There is no benefit for <listbox>
in terms of accessibility, since the platform can assign the proper a11y roles to <div behavior=”listbox” popup=”popup”>
when used as the <selectmenu>
’s listbox, the same as if <listbox>
were used.
If, however, we wanted to add a <listbox>
element to the platform sometime in the future, <selectmenu>
could be updated to allow authors to slot it in as a custom listbox part, as an alternative to <div behavior="listbox">
(once we’ve worked through the aforementioned spec complications). Controller code in in the <selectmenu>
could ensure that the following have the same appearance and behaviors:
<selectmenu>
<div slot="listbox" behavior="listbox" popup="popup">
<option>Thing one</option>
...
</div>
</selectmenu>
<selectmenu>
<listbox slot="listbox" behavior="listbox" popup="popup"> <!-- or maybe behavior="listbox" could be implicit here -->
<option>Thing one</option>
...
</listbox>
</selectmenu>
The styles and controller code in the shadow DOM would ensure that <listbox>
has the same default appearance and mouse/keyboard interactions as <div behavior="popup">
regardless of how <listbox>
behaves as a standalone element. For the same reason, the default listbox part in the <selectmenu>
's user-agent shadow DOM could also be converted from a <div behavior="listbox">
to a <listbox behavior="listbox">
. The value of doing so is not clear, though, since such a conversion would be opaque to authors. They can't directly reference the default listbox part via script, and there would be no change in appearance or mouse/keyboard interaction as per the above.
Regarding the original question of what to do for multi-select, I propose that we simply punt on this for now. The point of doing so is, again, to scale back feature creep around <selectmenu>
and scope it to a manageable core that will meet the developer demand for a customizable <select>
.
It can be added in the future with minimal compat risk if we just have the multiple
attribute (<selectmenu multiple
> and <div behavior="listbox" multiple>
) do nothing for the time being, and perhaps emit a console warning. The multiselect functionality can then be lit up later either with an attribute or with a new element.
* @mfreed7 pointed out to me that demand for a <listbox>
with multiselect might be lower than it appears from usage statistics due to how badly the current <select multiple>
works today. I think however the expressed developer demands still points to customizable single-<select>
being the number one priority.