|
1 |
| -<!DOCTYPE html> |
| 1 | +<!doctype html> |
2 | 2 | <html lang="en">
|
3 | 3 | <head>
|
4 | 4 | <meta charset="UTF-8" />
|
5 | 5 | <meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
6 | 6 | <meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
7 |
| - <title>Combo box</title> |
| 7 | + <title>Combo Box</title> |
8 | 8 | <script type="module" src="./common.js"></script>
|
| 9 | + |
9 | 10 | <script type="module">
|
10 |
| - import '@vaadin/combo-box'; |
11 |
| - import '@vaadin/combo-box/vaadin-combo-box-light.js'; |
12 |
| - import '@vaadin/tooltip'; |
| 11 | + import '@vaadin/combo-box/src/vaadin-lit-combo-box.js'; |
| 12 | + import '@vaadin/icon/src/vaadin-lit-icon.js'; |
| 13 | + import '@vaadin/vaadin-lumo-styles/vaadin-iconset.js'; |
| 14 | + import '@vaadin/icons'; |
13 | 15 | </script>
|
14 | 16 | </head>
|
15 | 17 | <body>
|
16 |
| - <vaadin-combo-box label="Country"> |
17 |
| - <vaadin-tooltip slot="tooltip" text="Loading might take time"></vaadin-tooltip> |
18 |
| - </vaadin-combo-box> |
| 18 | + <section> |
| 19 | + <h2>Plain</h2> |
| 20 | + <vaadin-combo-box></vaadin-combo-box> |
| 21 | + <vaadin-combo-box placeholder="Placeholder"></vaadin-combo-box> |
| 22 | + </section> |
19 | 23 |
|
20 |
| - <script type="module"> |
21 |
| - const comboBox = document.querySelector('vaadin-combo-box'); |
| 24 | + <section> |
| 25 | + <h2>Bells & Whistles</h2> |
| 26 | + <vaadin-combo-box |
| 27 | + label="Label" |
| 28 | + helper-text="Description for this field." |
| 29 | + clear-button-visible |
| 30 | + error-message="You need to write something in this field." |
| 31 | + required |
| 32 | + > |
| 33 | + <vaadin-icon icon="vaadin:search" slot="prefix"></vaadin-icon> |
| 34 | + </vaadin-combo-box> |
| 35 | + </section> |
| 36 | + |
| 37 | + <section> |
| 38 | + <h2>States</h2> |
| 39 | + <vaadin-combo-box |
| 40 | + label="Read-only" |
| 41 | + helper-text="Description for this field." |
| 42 | + clear-button-visible |
| 43 | + error-message="You need to write something in this field." |
| 44 | + required |
| 45 | + readonly |
| 46 | + > |
| 47 | + <vaadin-icon icon="vaadin:search" slot="prefix"></vaadin-icon> |
| 48 | + </vaadin-combo-box> |
22 | 49 |
|
23 |
| - /* |
24 |
| - const res = await fetch('https://demo.vaadin.com/demo-data/1.0/filtered-countries?count=200'); |
25 |
| - const arr = await res.json(); |
26 |
| - comboBox.items = arr.result; |
27 |
| - */ |
| 50 | + <vaadin-combo-box |
| 51 | + label="Disabled" |
| 52 | + helper-text="Description for this field." |
| 53 | + clear-button-visible |
| 54 | + error-message="You need to write something in this field." |
| 55 | + required |
| 56 | + disabled |
| 57 | + > |
| 58 | + <vaadin-icon icon="vaadin:search" slot="prefix"></vaadin-icon> |
| 59 | + </vaadin-combo-box> |
| 60 | + </section> |
| 61 | + |
| 62 | + <script type="module"> |
| 63 | + document.querySelectorAll('vaadin-combo-box').forEach((comboBox) => { |
| 64 | + comboBox.dataProvider = async (params, callback) => { |
| 65 | + const index = params.page * params.pageSize; |
| 66 | + const response = await fetch( |
| 67 | + `https://demo.vaadin.com/demo-data/1.0/filtered-countries?index=${index}&count=${params.pageSize}&filter=${params.filter}`, |
| 68 | + ); |
| 69 | + if (response.ok) { |
| 70 | + const { result, size } = await response.json(); |
| 71 | + // Emulate network latency for demo purpose |
| 72 | + setTimeout(() => { |
| 73 | + callback(result, size); |
| 74 | + }, 1000); |
| 75 | + } |
| 76 | + }; |
28 | 77 |
|
29 |
| - comboBox.dataProvider = async (params, callback) => { |
30 |
| - console.log(JSON.stringify(params)); |
31 |
| - const index = params.page * params.pageSize; |
32 |
| - const response = await fetch( |
33 |
| - `https://demo.vaadin.com/demo-data/1.0/filtered-countries?index=${index}&count=${params.pageSize}&filter=${params.filter}`, |
34 |
| - ); |
35 |
| - if (response.ok) { |
36 |
| - const { result, size } = await response.json(); |
37 |
| - // Emulate network latency for demo purpose |
38 |
| - setTimeout(() => { |
39 |
| - callback(result, size); |
40 |
| - }, 100); |
| 78 | + if (!comboBox.placeholder) { |
| 79 | + comboBox.selectedItem = 'Andorra'; |
41 | 80 | }
|
42 |
| - }; |
| 81 | + }); |
43 | 82 | </script>
|
44 | 83 | </body>
|
45 | 84 | </html>
|
0 commit comments