( value: string, options: readonly SelectOption[], placeholder?: string, )
| 28 | * @returns Display text for the select |
| 29 | */ |
| 30 | export function getSelectDisplayText( |
| 31 | value: string, |
| 32 | options: readonly SelectOption[], |
| 33 | placeholder?: string, |
| 34 | ): string { |
| 35 | if (value === "") { |
| 36 | const emptyOption = options.find((opt) => opt.value === ""); |
| 37 | if (!emptyOption) { |
| 38 | return placeholder ?? DEFAULT_PLACEHOLDER; |
| 39 | } |
| 40 | return emptyOption.label; |
| 41 | } |
| 42 | |
| 43 | const option = options.find((opt) => opt.value === value); |
| 44 | return option?.label ?? placeholder ?? DEFAULT_PLACEHOLDER; |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Find the index of an option by value. |
no outgoing calls
no test coverage detected