|
1 | 1 | <div class="columns margins">
|
2 | 2 | <div>
|
3 | 3 | <!--
|
4 |
| - Note: you need to provide a function |
5 |
| - as `key` that returns a unique string |
| 4 | + Note: you need to provide a function as `key` that returns a unique string |
6 | 5 | for each option.
|
| 6 | +
|
| 7 | + It *must* be a string. (Hence the `${fruit.id}` part.) |
7 | 8 | -->
|
8 |
| - <Select |
9 |
| - key={(fruit) => (fruit && fruit.label) || ''} |
10 |
| - bind:value={valueA} |
11 |
| - label="Standard" |
12 |
| - > |
| 9 | + <Select key={(fruit) => `${fruit.id}`} bind:value={valueA} label="Standard"> |
13 | 10 | <Option value={null} />
|
14 | 11 | {#each fruits as fruit (fruit.label)}
|
15 | 12 | <Option value={fruit}>{fruit.label}</Option>
|
16 | 13 | {/each}
|
17 | 14 | </Select>
|
18 | 15 |
|
19 |
| - <pre |
20 |
| - class="status">Selected: {valueA ? valueA.label : 'None'}, Price: {valueA ? valueA.price : '-'}¢</pre> |
| 16 | + <pre class="status">Selected: {valueA |
| 17 | + ? valueA.label |
| 18 | + : 'None'}, Price: {valueA ? valueA.price : '-'}¢</pre> |
21 | 19 | </div>
|
22 | 20 |
|
23 | 21 | <div>
|
24 | 22 | <Select
|
25 | 23 | variant="filled"
|
26 |
| - key={(fruit) => (fruit && fruit.label) || ''} |
| 24 | + key={(fruit) => `${fruit.id}`} |
27 | 25 | bind:value={valueB}
|
28 | 26 | label="Filled"
|
29 | 27 | >
|
|
33 | 31 | {/each}
|
34 | 32 | </Select>
|
35 | 33 |
|
36 |
| - <pre |
37 |
| - class="status">Selected: {valueB ? valueB.label : 'None'}, Price: {valueB ? valueB.price : '-'}¢</pre> |
| 34 | + <pre class="status">Selected: {valueB |
| 35 | + ? valueB.label |
| 36 | + : 'None'}, Price: {valueB ? valueB.price : '-'}¢</pre> |
38 | 37 | </div>
|
39 | 38 |
|
40 | 39 | <div>
|
41 | 40 | <Select
|
42 | 41 | variant="outlined"
|
43 |
| - key={(fruit) => (fruit && fruit.label) || ''} |
| 42 | + key={(fruit) => `${fruit.id}`} |
44 | 43 | bind:value={valueC}
|
45 | 44 | label="Outlined"
|
46 | 45 | >
|
|
50 | 49 | {/each}
|
51 | 50 | </Select>
|
52 | 51 |
|
53 |
| - <pre |
54 |
| - class="status">Selected: {valueC ? valueC.label : 'None'}, Price: {valueC ? valueC.price : '-'}¢</pre> |
| 52 | + <pre class="status">Selected: {valueC |
| 53 | + ? valueC.label |
| 54 | + : 'None'}, Price: {valueC ? valueC.price : '-'}¢</pre> |
55 | 55 | </div>
|
56 | 56 | </div>
|
57 | 57 |
|
58 | 58 | <script lang="ts">
|
59 | 59 | import Select, { Option } from '@smui/select';
|
60 | 60 |
|
61 |
| - type Fruit = { label: string; price: number }; |
| 61 | + type Fruit = { id: number; label: string; price: number }; |
62 | 62 | let fruits: Fruit[] = [
|
63 |
| - { label: 'Apple', price: 35 }, |
64 |
| - { label: 'Orange', price: 38 }, |
65 |
| - { label: 'Banana', price: 28 }, |
66 |
| - { label: 'Mango', price: 25 }, |
| 63 | + { id: 1, label: 'Apple', price: 35 }, |
| 64 | + { id: 2, label: 'Orange', price: 38 }, |
| 65 | + { id: 3, label: 'Banana', price: 28 }, |
| 66 | + { id: 4, label: 'Mango', price: 25 }, |
67 | 67 | ];
|
68 | 68 |
|
69 | 69 | let valueA: Fruit | undefined = undefined;
|
|
0 commit comments