Skip to content

Commit 8d7124c

Browse files
committed
docs: fix key prop in select objects demo even more
1 parent d2bcb48 commit 8d7124c

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

packages/site/src/routes/demo/select/_Objects.svelte

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@
44
Note: you need to provide a function as `key` that returns a unique string
55
for each option.
66
7-
It *must* be a string. (Hence the `${fruit && fruit.id}` part. That
8-
returns a string for the numberic `id` field and the `null` value even.)
7+
It *must* be a string. (Hence the `${(fruit && fruit.id) || ''}` part.
8+
That returns a string for the numberic `id` field and the `null` and
9+
`undefined` values even.) If the string is empty (""), the label will stop
10+
floating when that option is selected and the component is unfocused.
11+
Therefore, the option for that value shouldn't have any text, or the
12+
floating label will overlap it.
913
-->
1014
<Select
11-
key={(fruit) => `${fruit && fruit.id}`}
15+
key={(fruit) => `${(fruit && fruit.id) || ''}`}
1216
bind:value={valueA}
1317
label="Standard"
1418
>
@@ -26,7 +30,7 @@
2630
<div>
2731
<Select
2832
variant="filled"
29-
key={(fruit) => `${fruit && fruit.id}`}
33+
key={(fruit) => `${(fruit && fruit.id) || ''}`}
3034
bind:value={valueB}
3135
label="Filled"
3236
>
@@ -44,7 +48,7 @@
4448
<div>
4549
<Select
4650
variant="outlined"
47-
key={(fruit) => `${fruit && fruit.id}`}
51+
key={(fruit) => `${(fruit && fruit.id) || ''}`}
4852
bind:value={valueC}
4953
label="Outlined"
5054
>

0 commit comments

Comments
 (0)