Skip to content

Commit 4e4276a

Browse files
committed
fix: issue with selected option icon
1 parent 2bc148d commit 4e4276a

File tree

2 files changed

+10
-36
lines changed

2 files changed

+10
-36
lines changed

src/Shared/Components/SelectPicker/SelectPicker.component.tsx

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
SelectPickerLoadingIndicator,
1212
SelectPickerMenu,
1313
SelectPickerOption,
14-
SelectPickerValueContainer,
1514
} from './common'
1615
import { SelectPickerOptionType, SelectPickerProps } from './type'
1716

@@ -51,13 +50,6 @@ const SelectPicker = ({
5150
[],
5251
)
5352

54-
const renderValueContainer = useCallback(
55-
(valueContainerProps) => (
56-
<SelectPickerValueContainer {...valueContainerProps} showSelectedOptionIcon={showSelectedOptionIcon} />
57-
),
58-
[showSelectedOptionIcon],
59-
)
60-
6153
return (
6254
<div className="flex column left top dc__gap-4">
6355
{/* TODO Eshank: Common out for fields */}
@@ -89,7 +81,6 @@ const SelectPicker = ({
8981
Option: SelectPickerOption,
9082
Menu: renderMenu,
9183
ClearIndicator: SelectPickerClearIndicator,
92-
ValueContainer: renderValueContainer,
9384
}}
9485
styles={selectStyles}
9586
className="w-100"

src/Shared/Components/SelectPicker/common.tsx

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ import {
33
DropdownIndicatorProps,
44
ControlProps,
55
OptionProps,
6-
MenuProps,
76
ClearIndicatorProps,
8-
ValueContainerProps,
7+
MenuProps,
98
} from 'react-select'
109
import { Progressing } from '@Common/Progressing'
1110
import { ReactComponent as ICCaretDown } from '@Icons/ic-caret-down.svg'
@@ -35,39 +34,23 @@ export const SelectPickerControl = ({
3534
}: ControlProps<SelectPickerOptionType> & Pick<SelectPickerProps, 'icon' | 'showSelectedOptionIcon'>) => {
3635
const { children, getValue } = props
3736
const { startIcon, endIcon } = getValue()?.[0] ?? {}
38-
// Show the display icon if either the selected option icon is not to be shown or not available
39-
const showDisplayIcon = !!(icon && (!showSelectedOptionIcon || !(startIcon || endIcon)))
37+
38+
let iconToDisplay = icon
39+
40+
if (showSelectedOptionIcon && (startIcon || endIcon)) {
41+
iconToDisplay = startIcon || endIcon
42+
}
4043

4144
return (
4245
<components.Control {...props}>
43-
{showDisplayIcon && <div className="dc__no-shrink icon-dim-20 flex dc__fill-available-space">{icon}</div>}
46+
{iconToDisplay && (
47+
<div className="dc__no-shrink icon-dim-20 flex dc__fill-available-space">{iconToDisplay}</div>
48+
)}
4449
{children}
4550
</components.Control>
4651
)
4752
}
4853

49-
export const SelectPickerValueContainer = ({
50-
showSelectedOptionIcon,
51-
...props
52-
}: ValueContainerProps<SelectPickerOptionType> & Pick<SelectPickerProps, 'showSelectedOptionIcon'>) => {
53-
const { children, getValue, hasValue } = props
54-
const { startIcon, endIcon } = getValue()?.[0] ?? {}
55-
const showIcon = !!(showSelectedOptionIcon && hasValue && (startIcon || endIcon))
56-
57-
return (
58-
<components.ValueContainer {...props}>
59-
<div className="flex left dc__gap-8">
60-
{showIcon && (
61-
<div className="dc__no-shrink icon-dim-20 flex dc__fill-available-space">
62-
{startIcon || endIcon}
63-
</div>
64-
)}
65-
{children}
66-
</div>
67-
</components.ValueContainer>
68-
)
69-
}
70-
7154
export const SelectPickerLoadingIndicator = () => <Progressing />
7255

7356
export const SelectPickerOption = (props: OptionProps<SelectPickerOptionType>) => {

0 commit comments

Comments
 (0)