You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: site/src/pages/components/combobox.explainer.mdx
+34-3Lines changed: 34 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -86,6 +86,10 @@ Here is a basic example:
86
86
87
87
## Associating an input element with a select element
88
88
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
+
89
93
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.
90
94
91
95
```html
@@ -96,9 +100,7 @@ The `<input type=text>` element can be associated with a `<select>` element with
96
100
</select>
97
101
```
98
102
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:
102
104
103
105
```html
104
106
<buttoncommandfor=pickercommand=toggle-popover>
@@ -113,6 +115,29 @@ Unlike alternative proposals which allowed the author to put a filtering input i
113
115
</dialog>
114
116
```
115
117
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
+
116
141
## Datalist becomes a popover
117
142
118
143
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
164
189
165
190
## Examples
166
191
192
+
### Demos
193
+
194
+
* Country picker: https://codepen.io/jarhar/pen/dPpPjqy
195
+
* Wikipedia search box (uses combobox): https://codepen.io/jarhar/pen/vEXvWrW
0 commit comments