Skip to content

Commit 57ee967

Browse files
authored
Add alternatives for filterable select HTML opt in (#1443)
1 parent ab426a7 commit 57ee967

1 file changed

Lines changed: 34 additions & 3 deletions

File tree

site/src/pages/components/combobox.explainer.mdx

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ Here is a basic example:
8686

8787
## Associating an input element with a select element
8888

89+
There are two alternative solutions being considered to associate an input with a select element:
90+
91+
### Sibling input and listbox select elements
92+
8993
The `<input type=text>` element can be associated with a `<select>` element with the new `filter` attribute. The select element must be rendered as a listbox, not as a drop-down box.
9094

9195
```html
@@ -96,9 +100,7 @@ The `<input type=text>` element can be associated with a `<select>` element with
96100
</select>
97101
```
98102

99-
## Making your own picker for a filterable select
100-
101-
Unlike alternative proposals which allowed the author to put a filtering input inside a drop-down select element, this proposal requires the author to make their own picker containing a listbox select element like this:
103+
Making a drop-down select with this pattern would look like this:
102104

103105
```html
104106
<button commandfor=picker command=toggle-popover>
@@ -113,6 +115,29 @@ Unlike alternative proposals which allowed the author to put a filtering input i
113115
</dialog>
114116
```
115117

118+
Cons:
119+
- Author is required to set up idrefs
120+
- In order to use the `<selectedcontent>` element, we would have to make the selectedcontent element work outside of a select element with an idref, which would be a separate new feature.
121+
- Significantly more markup is required to make a dropdown select with this pattern.
122+
123+
### Nested input and select elements
124+
125+
The `<input type=text>` element can be associated with a `<select>` element by putting an input element inside of a listbox or dropdown select element:
126+
127+
```html
128+
<select>
129+
<input>
130+
<option>one</option>
131+
<option>two</option>
132+
</select>
133+
```
134+
135+
Cons:
136+
- Have to make additional changes to the HTML parser to allow `<input>` in `<select>`, which requires that it doesn't end up breaking existing sites and makes this feature harder to polyfill.
137+
- Option elements need to be slotted into a separate wrapper element from the input element in the UA shadow root of the select element, which may need a new part-like pseudo-element.
138+
- Input element could end up inside the scroller for the options, [see this issue](https://github.com/openui/open-ui/issues/1441).
139+
- May have to define how input in select works for appearance:auto dropdown select elements.
140+
116141
## Datalist becomes a popover
117142

118143
When the datalist element has base appearance, it will automatically become a popover without the need for the author to set the popover attribute on it. When the input element is focused, the datalist will be shown as a popover and anchored to the input element.
@@ -164,6 +189,12 @@ This explainer provides useful primitives for building this use case, but the ac
164189

165190
## Examples
166191

192+
### Demos
193+
194+
* Country picker: https://codepen.io/jarhar/pen/dPpPjqy
195+
* Wikipedia search box (uses combobox): https://codepen.io/jarhar/pen/vEXvWrW
196+
* Github labels picker (uses filterable select): https://codepen.io/jarhar/pen/NPRezMv
197+
167198
{/* TODO add more examples and use code-image-container */}
168199

169200
### Basic

0 commit comments

Comments
 (0)