AdelRedaa97 / react-native-select-dropdown

react-native-select-dropdown is a highly customized dropdown | select | picker | menu for react native that works for andriod and iOS platforms.
MIT License
314 stars 134 forks source link

DefaultValue/defaultValueByIndex on custom button #112

Closed YoelEigner closed 1 year ago

YoelEigner commented 1 year ago

I'm having some issues setting the default value for a custom button whichever prop i try nothing happens defaultValueByIndex and defaultValue dont work, can this be updated?

AdelRedaa97 commented 1 year ago

It's working fine for me, Do you use last version ?

YoelEigner commented 1 year ago

It's working fine for me, Do you use last version ?

Could you please share your component? Or are you referring to the documentation component that’s working fine?

AdelRedaa97 commented 1 year ago

https://snack.expo.dev/@adelredaa97/default-value

YoelEigner commented 1 year ago

Thank you, but that is not a custom button

a dropdown with a custom button would look like this

            <SelectDropdown
                data={options}
                onSelect={(selectedItem, index) => {
                    handleChange(selectedItem, index)
                }}
                defaultValue={1}
                selectedRowTextStyle={{ fontFamily: 'Rubik-Bold' }}
                ref={dropdownRef}
                buttonStyle={{ backgroundColor: 'transparent', width: buttonWidth }}
                defaultValueByIndex={1}
                renderCustomizedButtonChild={(selectedItem, index) => {
                    return (
                        <View style={Styling.customDropDownBtnView}>
                            <Text
                                onLayout={handleTextLayout}
                                style={{ color: '#3994FF', textDecorationLine: 'underline', fontSize: 18, fontFamily: 'Rubik-Medium' }}>
                                {selectedItem ? selectedItem :  'Choose...'}
                            </Text>
                            { <MaterialCommunityIcons style={{marginTop:2}} name='arrow-down' color={'#3994FF'} size={18} />}
                        </View>
                    )
                }}
                buttonTextAfterSelection={(selectedItem, index) => {
                    return selectedItem
                }}
                rowTextForSelection={(item, index) => {
                    return item
                }}
            />
AdelRedaa97 commented 1 year ago

Look at this, I've updated it with an example that has a custom button https://snack.expo.dev/@adelredaa97/default-value

YoelEigner commented 1 year ago

I found the issue, I had a ref in there to reset the selection but when i removed it, the default value does work. Thank you very much