Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Text disapper after select an item from drop down list #90

Open
cksiow opened this issue Nov 11, 2022 · 3 comments
Open

Text disapper after select an item from drop down list #90

cksiow opened this issue Nov 11, 2022 · 3 comments

Comments

@cksiow
Copy link

cksiow commented Nov 11, 2022

When using the component setting as below
<SearchableDropdown
ref={control => this.placeTypeControl = control}
onItemSelect={(item) => {
this.state.saveData.placeTypeId = item.id;
this.setState({});
}}
containerStyle={{ marginTop: 10 }}
itemStyle={{
padding: 10,
marginTop: 2,
backgroundColor: 'white',
borderColor: '#bbb',
borderWidth: 1,
borderRadius: 5,
}}
itemTextStyle={{ color: '#222' }}
itemsContainerStyle={{ height: 125 }}
items={this.state.placeType}
resetValue={false}
textInputProps={
{
placeholder: "",
underlineColorAndroid: "transparent",
style: {
paddingTop: 12,
paddingBottom: 12,
fontSize: 20,
borderWidth: 1,
borderColor: 'black',
borderRadius: 0,
},
onSelectionChange: (e) => {
this.state.saveData.placeTypeId = null;
this.setState({
});
}
}
}
listProps={
{
nestedScrollEnabled: true,
}
}
/>

sample of this.state.placeType
[
{
id: "1",
name: "test1"
},
{
id: "2",
name: "test1"
}
]

after select an item, a while the display text will become blank, after debug and check, found out in onBlur event
this.setState({ focus: false, item: this.props.selectedItems });
change to
this.setState({ focus: false, item: this.props.selectedItems ? this.props.selectedItems : this.state.item });

will resolve the issuedue to this.props.selectedItems set to undefined after while.

@varunkumarmedam
Copy link

same issue here. any working resolution?

@cksiow
Copy link
Author

cksiow commented Nov 29, 2022

same issue here. any working resolution?

after select an item, a while the display text will become blank, after debug and check, found out in onBlur event
this.setState({ focus: false, item: this.props.selectedItems });
change to
this.setState({ focus: false, item: this.props.selectedItems ? this.props.selectedItems : this.state.item });

will resolve the issuedue to this.props.selectedItems set to undefined after while.

@p8ul
Copy link

p8ul commented Jun 28, 2023

Might not be the best practice but adding a timeout before setting the value works. Although with some glitch.

At around line 124:

 <TouchableOpacity
          style={{ ...this.props.itemStyle }}
          onPress={() => {
            this.setState({ item: item, focus: false }); // replace this with the code below
            setTimeout(() => { // timeout before setting value
              this.setState({ item: item, focus: false }); 
            }, 100);
            
            Keyboard.dismiss();
            setTimeout(() => {
              this.props.onItemSelect(item);
              if (this.props.resetValue) {
                this.setState({ focus: true, item: defaultItemValue });
                this.input.focus();
              }
            }, 0);
          }}
        >```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants