Skip to content

Commit 8897fcd

Browse files
authored
Improve usecases in selectlist explainer (#918)
* Improve usecases in selectlist explainer * go back to country flags * switch to optgroups
1 parent 450a8e7 commit 8897fcd

File tree

4 files changed

+56
-12
lines changed

4 files changed

+56
-12
lines changed
1 MB
Loading
-16.6 KB
Loading

site/src/layouts/ComponentLayout.astro

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const { name, pathToProposal, pathToResearch } = frontmatter
2424

2525
:global(.code-image-container img) {
2626
height: 100%;
27+
object-fit: contain;
2728
}
2829

2930
@media (max-width: 800px) {

site/src/pages/components/selectlist.mdx

+55-12
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,15 @@ This example adds "rich content" inside option elements in the form of country f
7777
```html
7878
<selectlist>
7979
<option>
80-
<img src="usa.jpg">
80+
<img src="usa.jpg" alt="flag of USA">
8181
USA
8282
</option>
8383
<option>
84-
<img src="germany.jpg">
84+
<img src="germany.jpg" alt="flag of Germany">
8585
Germany
8686
</option>
8787
<option>
88-
<img src="spain.jpg">
88+
<img src="spain.jpg" alt="flag of Spain">
8989
Spain
9090
</option>
9191
</selectlist>
@@ -165,18 +165,44 @@ This example has a `<listbox>` which enables it to put arbitrary content into th
165165
```html
166166
<selectlist>
167167
<listbox>
168-
<div>Heading</div>
169-
<div>First two options:</div>
170-
<option>one</option>
171-
<option>two</option>
172-
<div>Second two options:</div>
173-
<option>three</option>
174-
<option>four</option>
168+
<div class=container>
169+
<div>
170+
<optgroup label="1-2">
171+
<option>one</option>
172+
<option>two</option>
173+
</optgroup>
174+
</div>
175+
<div>
176+
<optgroup label="3-4">
177+
<option>three</option>
178+
<option>four</option>
179+
</optgroup>
180+
</div>
181+
<div>
182+
<optgroup label="5-6">
183+
<option>five</option>
184+
<option>six</option>
185+
</optgroup>
186+
</div>
187+
<div>
188+
<optgroup label="7-8">
189+
<option>seven</option>
190+
<option>eight</option>
191+
</optgroup>
192+
</div>
193+
</div>
175194
</listbox>
176195
</selectlist>
177196
<style>
178-
div {
179-
font-weight: bold;
197+
.container {
198+
display: grid;
199+
grid-template-rows: auto auto;
200+
grid-template-columns: 50px 50px;
201+
grid-column-gap: 10px;
202+
grid-row-gap: 10px;
203+
}
204+
.container > div {
205+
background-color: lightgray;
180206
}
181207
</style>
182208
```
@@ -189,6 +215,23 @@ div {
189215
</div>
190216
</div>
191217

218+
Here is another example with custom content in the listbox: [codepen](https://codepen.io/una/pen/PoXbgVW)
219+
220+
### Animations
221+
222+
<div className="code-image-container">
223+
<div>
224+
This example uses view transitions to animate the opening and closing of the listbox.
225+
[Link to codepen](https://codepen.io/argyleink/pen/wvYrZEV/ab71f1b613db0487f64ff8c6919b0173)
226+
</div>
227+
<div>
228+
<Image
229+
src="/images/selectlist-animation.gif"
230+
alt="A selectlist with a listbox that animates open and closed"
231+
/>
232+
</div>
233+
</div>
234+
192235
## Testing out the selectlist element
193236

194237
`<selectlist>` is currently implemented behind a flag in [Chromium](https://chromestatus.com/feature/5737365999976448). To use it, enable the **Experimental Web Platform features** flag in about:flags.

0 commit comments

Comments
 (0)