Skip to content

Commit 72b8f30

Browse files
authored
Merge pull request #254 from DogusErdem/feat/add-dropdown-value-prop
feat: Added dropdown value prop
2 parents 241eadb + d99c3db commit 72b8f30

1 file changed

Lines changed: 20 additions & 13 deletions

File tree

src/components/Dropdown/Dropdown.tsx

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,13 @@ const Dropdown: FCCWD<DrowdownProps> = (
2727
autoPosition = true,
2828
size = 'medium',
2929
disabled,
30+
value,
3031
defaultValue = {},
3132
testID,
3233
theme },
3334
) => {
3435
const [visible, setVisible] = useState(false);
35-
const [selectedObject, setSelectedObject] = useState(defaultValue);
36+
const [selectedObject, setSelectedObject] = useState(value || defaultValue);
3637
const [cord, setCord] = useState({ x: 0, y: 0, height: 0, width: 0 });
3738
const { statusTheme, componentTheme } = useComponentTheme(
3839
theme,
@@ -86,6 +87,10 @@ const Dropdown: FCCWD<DrowdownProps> = (
8687
openAnimation.value = withSpring(visible ? 1 : 0);
8788
}, [visible]);
8889

90+
useEffect(() => {
91+
if (value) setSelectedObject(value);
92+
}, [value]);
93+
8994
return (
9095
<View testID={testID} style={[containerStyle, { zIndex: visible ? 1000 : 0 }]}>
9196
<TouchableOpacity
@@ -95,13 +100,15 @@ const Dropdown: FCCWD<DrowdownProps> = (
95100
onLayout={event => setCord(event.nativeEvent.layout)}
96101
onPress={() => { setVisible(!visible); }}
97102
style={[Style.button, { borderWidth: 1, height: sizes[size].buttonHeight }, buttonStyle,
98-
{ borderColor: statusTheme.border,
99-
backgroundColor: statusTheme.background }]}
103+
{
104+
borderColor: statusTheme.border,
105+
backgroundColor: statusTheme.background,
106+
}]}
100107
>
101108
{leftElement && (
102-
<View style={Style.leftItem}>
103-
{leftElement}
104-
</View>
109+
<View style={Style.leftItem}>
110+
{leftElement}
111+
</View>
105112
)}
106113
<Text
107114
numberOfLines={1}
@@ -121,13 +128,13 @@ const Dropdown: FCCWD<DrowdownProps> = (
121128

122129
<View style={[Style.rightItem]}>
123130
{rightElement || (
124-
<Animated.View style={dropdownAnimation}>
125-
<FeatherIcon
126-
name="chevron-down"
127-
size={14}
128-
color={statusTheme.collapseIcon}
129-
/>
130-
</Animated.View>
131+
<Animated.View style={dropdownAnimation}>
132+
<FeatherIcon
133+
name="chevron-down"
134+
size={14}
135+
color={statusTheme.collapseIcon}
136+
/>
137+
</Animated.View>
131138
)}
132139
</View>
133140
</TouchableOpacity>

0 commit comments

Comments
 (0)