Skip to content

Commit 6f101cc

Browse files
authored
chore: improve select dev page, add custom renderer example (#9567)
1 parent 1c265f6 commit 6f101cc

File tree

1 file changed

+36
-13
lines changed

1 file changed

+36
-13
lines changed

dev/select.html

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,24 @@ <h2 class="heading">Bells & Whistles</h2>
2828
label="Label"
2929
helper-text="Description for this field."
3030
value="s"
31-
clear-button-visible
3231
error-message="You need to write something in this field."
3332
required
3433
>
3534
<vaadin-icon icon="vaadin:search" slot="prefix"></vaadin-icon>
3635
</vaadin-select>
3736
</section>
3837

38+
<section>
39+
<h2 class="heading">Custom renderer</h2>
40+
<vaadin-select id="custom" value="s"></vaadin-select>
41+
</section>
42+
3943
<section class="section">
4044
<h2 class="heading">States</h2>
4145
<vaadin-select
4246
label="Read-only"
4347
helper-text="Description for this field."
4448
value="s"
45-
clear-button-visible
4649
error-message="You need to write something in this field."
4750
required
4851
readonly
@@ -54,7 +57,6 @@ <h2 class="heading">States</h2>
5457
label="Disabled"
5558
helper-text="Description for this field."
5659
value="s"
57-
clear-button-visible
5860
error-message="You need to write something in this field."
5961
required
6062
disabled
@@ -63,17 +65,38 @@ <h2 class="heading">States</h2>
6365
</vaadin-select>
6466
</section>
6567

66-
<script>
68+
<script type="module">
69+
import { html, render } from 'lit';
70+
6771
document.querySelectorAll('vaadin-select').forEach((select) => {
68-
select.items = items = [
69-
{ label: 'Show all', value: 'all' },
70-
{ component: 'hr' },
71-
{ label: 'XS (out of stock)', value: 'xs', disabled: true },
72-
{ label: 'S', value: 's' },
73-
{ label: 'M', value: 'm' },
74-
{ label: 'L', value: 'l' },
75-
{ label: 'XL', value: 'xl' },
76-
];
72+
if ((select.id = 'custom')) {
73+
select.renderer = (root) => {
74+
render(
75+
html`
76+
<vaadin-select-list-box>
77+
<vaadin-select-item value="all">Show all</vaadin-select-item>
78+
<hr />
79+
<vaadin-select-item value="xs" disabled>XS (out of stock)</vaadin-select-item>
80+
<vaadin-select-item value="s">S</vaadin-select-item>
81+
<vaadin-select-item value="m">M</vaadin-select-item>
82+
<vaadin-select-item value="l">L</vaadin-select-item>
83+
<vaadin-select-item value="xl">XL</vaadin-select-item>
84+
</vaadin-select-list-box>
85+
`,
86+
root,
87+
);
88+
};
89+
} else {
90+
select.items = [
91+
{ label: 'Show all', value: 'all' },
92+
{ component: 'hr' },
93+
{ label: 'XS (out of stock)', value: 'xs', disabled: true },
94+
{ label: 'S', value: 's' },
95+
{ label: 'M', value: 'm' },
96+
{ label: 'L', value: 'l' },
97+
{ label: 'XL', value: 'xl' },
98+
];
99+
}
77100
});
78101
</script>
79102
</body>

0 commit comments

Comments
 (0)