Skip to content

Commit

Permalink
Add appearance:base-select to select explainer
Browse files Browse the repository at this point in the history
Opt-ins to the new select have been discussed here:
openui#985
  • Loading branch information
josepharhar committed Apr 30, 2024
1 parent 2b96442 commit f35ab44
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions site/src/pages/components/selectlist.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ The [2020 MDN browser compatibility report had feedback](https://mdn.dev/archive

## Opting in to the new behavior

The `<select>` element will continue to behave as it currently does unless a `<button>` or `<datalist>` element is provided as a child of the `<select>`. `<button>` elements replace the native button which opens the listbox, and `<datalist>` replaces popup listbox. By replacing the native components with regular web content, the contents are fully stylable and customizable.

The current behavior in the HTML parser for `<select>` is to remove all tags which aren't `<option>` or `<optgroup>`. We will change the HTML parser to allow `<datalist>` and `<button>` as a child of `<select>`, and allow any other content within that `<datalist>` or `<button>`.
The `<select>` element will continue to behave as it currently does unless it has the `appearance:base-select` CSS property. Previously proposed opt-ins included a new tag name, an additional HTML attribute, and the presence of a child `<button>` or `<datalist>`.

Here is a basic `<select>` element today:
```html
Expand All @@ -54,7 +52,19 @@ Here is a basic `<select>` element today:

And here the same `<select>` with opt ins to the new stylability behavior which this explainer proposes:
```html
<select>
<select style="appearance:base-select">
<option>one</option>
<option>two</option>
</select>
```

## HTML parser changes

The current behavior in the HTML parser for `<select>` is to remove all tags which aren't `<option>` or `<optgroup>`. We will change the HTML parser to allow `<datalist>` and `<button>` as a child of `<select>`, and allow any other content within that `<datalist>` or `<button>`. The `<button>` allows authors to replace the in-page button which opens the popup, and the `<datalist>` allows authors to replace the popup element containing the options.

Here is a basic example which uses the parser changes:
```html
<select style="appearance:base-select">
<button>
<selectedoption></selectedoption>
</button>
Expand Down Expand Up @@ -534,3 +544,6 @@ The HTML parser will not allow `<button>` or `<datalist>` children when the `mul
- [Why not make selection follow focus](https://github.com/openui/open-ui/issues/742)
- [Why not allow select or datalist in size/multiple select](https://github.com/openui/open-ui/issues/977#issuecomment-1910874971)
- [Why `<button type=popover>`](https://github.com/openui/open-ui/issues/939#issuecomment-1910837275)
- Why opt-in with CSS
- https://github.com/whatwg/html/issues/9799#issuecomment-1789202391
- https://github.com/whatwg/html/issues/9799#issuecomment-1926411811

0 comments on commit f35ab44

Please sign in to comment.