Skip to content

Commit

Permalink
Fix select state placeholder duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
acasazza committed Aug 8, 2024
1 parent 67b2461 commit b6daee0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ export function AddressStateSelector(props: Props): JSX.Element {
const classNameComputed = !isEmptyStates()
? `${className} ${selectClassName} ${hasError ? errorClassName : ''}`
: `${className} ${inputClassName} ${hasError ? errorClassName : ''}`

return !isEmptyStates() ? (
<BaseSelect
{...p}
Expand Down
10 changes: 5 additions & 5 deletions packages/react-components/src/components/utils/BaseSelect.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { type ForwardRefRenderFunction } from 'react'
import Parent from './Parent'
import { type BaseSelectComponentProps } from '#typings'
import { findIndex } from 'lodash'

export type BaseSelectProps = BaseSelectComponentProps

Expand All @@ -16,10 +15,11 @@ const BaseSelect: ForwardRefRenderFunction<any, BaseSelectProps> = (
value = '',
...p
} = props
if (findIndex(options, placeholder) === -1) {
options.unshift(placeholder)
} else {
options[0] = placeholder
if (placeholder != null) {
const isPlaceholderInOptions = options.some((option) => option.value === placeholder.value)
if (!isPlaceholderInOptions) {
options.unshift(placeholder)
}
}
const Options = options.map((o, k) => {
const { label, ...option } = o
Expand Down

0 comments on commit b6daee0

Please sign in to comment.