Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update explainer with button behaviors #1125

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 8 additions & 29 deletions site/src/pages/components/customizableselect.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,13 @@ select, ::picker(select) {
</div>
</div>


#### Why a `<button>`?

To replace the select's built-in button, a native `<button>` element is used. That tells the browser that everything inside the `<button>` should be included in the in-page display of the `<select>` element. I.e. it's just a simple placeholder/container. Normal button activities and attributes, e.g. form submission, are routed to the `<select>` to handle.

To ensure the behavior described above, the nested `<button>` is rendered `inert`. It is also set to `display:contents` by the UA stylesheet, so that there aren't two sets of box decorations. The button and it's descendants do not participate in the a11y tree; therefore, any attributes on the button or descendants have no effect in the a11y tree.
mfreed7 marked this conversation as resolved.
Show resolved Hide resolved

### Rendering the `<option>` differently in the button

This example uses the customizable `<select>` element with custom CSS to target it which renders the option differently in the listbox vs in the button.
Expand Down Expand Up @@ -296,34 +303,6 @@ Here is another example with custom content in the listbox: [codepen](https://co
</div>
</div>

### Split buttons

<div className="code-image-container">
<div>
This example uses the [selectedcontentelement](#the-selectedcontentelement-attribute) attribute in order to have separate buttons which open the select's popover and another one which has the selected option content and submits a form. The image is taken from a richer example here: [link to codepen](https://codepen.io/una/pen/KKbNYbo).
```html
<button><selectedcontent id=myselectedcontent></selectedcontent></button>
<select selectedcontentelement=myselectedcontent>
<button>⬇️</button>
<option>Create a merge commit</option>
<option>Squash and merge</option>
<option>Rebase and merge</option>
</select>
<style>
select, ::picker(select) {
appearance: base-select;
}
</style>
```
</div>
<div>
<Image
src="/images/select-split-button.png"
alt="A customizable select element with a split button"
/>
</div>
</div>

## Button behavior

The first child `<button>` of a `<select>` will be slotted into the `<select>`'s UA ShadowRoot and will open the popup list of options.
Expand Down Expand Up @@ -355,7 +334,7 @@ Because the various parts of the select element can be styled, it's important to
- `<legend>` - Used to provide a label to an `<optgroup>` element. It must be the first child of the `<optgroup>`.
- `<option>` - Can have one or more and represents the potential values that can be chosen by the user.

## Styling
## Styling

Customizable `<select>` provides a variety of tools to help with styling, including pseudo-selectors for different states and pseudo-elements for different parts.

Expand Down