Skip to content

Commit 4a0df53

Browse files
committed
1 parent c60ad4a commit 4a0df53

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

src/SelectNext.tsx

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { cx } from "./tools/cx";
1919
import type { FrClassName } from "./fr/generatedFromCss/classNames";
2020
import { createComponentI18nApi } from "./i18n";
2121
import { useAnalyticsId } from "./tools/useAnalyticsId";
22+
import { exclude } from "tsafe/exclude";
2223

2324
export type SelectProps<Options extends SelectProps.Option[]> = {
2425
id?: string;
@@ -154,18 +155,23 @@ function NonMemoizedNonForwardedSelect<T extends SelectProps.Option[]>(
154155
disabled={disabled}
155156
>
156157
{[
157-
{
158-
"label": placeholder === undefined ? t("select an option") : placeholder,
159-
"selected": true,
160-
"value": "",
161-
"disabled": true
162-
},
158+
options.find(option => option.value === "") !== undefined
159+
? undefined
160+
: {
161+
"label":
162+
placeholder === undefined ? t("select an option") : placeholder,
163+
"selected": true,
164+
"value": "",
165+
"disabled": true
166+
},
163167
...options
164-
].map((option, index) => (
165-
<option {...(option as any)} key={`${option.value}-${index}`}>
166-
{option.label}
167-
</option>
168-
))}
168+
]
169+
.filter(exclude(undefined))
170+
.map((option, index) => (
171+
<option {...(option as any)} key={`${option.value}-${index}`}>
172+
{option.label}
173+
</option>
174+
))}
169175
</select>
170176
{state !== "default" && (
171177
<p id={stateDescriptionId} className={fr.cx(`fr-${state}-text`)}>

0 commit comments

Comments
 (0)