Skip to content

Commit

Permalink
Use labels in FormInput select when available
Browse files Browse the repository at this point in the history
  • Loading branch information
rogargon committed Jul 10, 2024
1 parent 1e7c8b8 commit 3b345e1
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/components/@shared/FormInput/InputElement/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ const InputElement = forwardRef(
const sortedOptions =
!sortOptions && sortOptions === false
? options
: (options as string[]).sort((a: string, b: string) =>
a.localeCompare(b)
: (options as string[]).sort((a: any, b: any) =>
a.label ? a.label.localeCompare(b.label) : a.localeCompare(b)
)
return (
<select
Expand All @@ -96,8 +96,12 @@ const InputElement = forwardRef(
>
{field !== undefined && field.value === '' && <option value="" />}
{sortedOptions &&
(sortedOptions as string[]).map(
(option: string, index: number) => (
(sortedOptions as any[]).map((option, index: number) => {
return option.label ? (
<option key={index} value={option.value}>
{option.label}
</option>
) : (
<option key={index} value={option}>
<Option
option={option}
Expand All @@ -106,7 +110,7 @@ const InputElement = forwardRef(
/>
</option>
)
)}
})}
</select>
)
}
Expand Down

0 comments on commit 3b345e1

Please sign in to comment.