How to put Picker to start with "Select" in React Native

Asked

Viewed 325 times

2

I want to put the Picker to start with: "Select", the only alternative I found was to determine a Picker.item with label="Select" and value=" ". However it looks unpleasant at the time the user will select, look at the image below:

inserir a descrição da imagem aqui

My code is like this:

  <Picker
      selectedValue={this.props.genero}
      onValueChange={this.props.modificaGenero}
      style={{ height: 35, width: 150 }}>
      <Picker.Item label="Selecione" value="" />
      <Picker.Item label="Masculino" value="masculino" />
      <Picker.Item label="Feminino" value="feminino" />
   </Picker>

I’m sure this is a wrong programming practice.

  • 1

    In my projects I end up using the same way you did. Following this answer https://stackoverflow.com/a/42209072/9671639 from soen, I believe it would be a normal way to solve the problem.

1 answer

1


Luke, I also don’t know a way to hide the first item of selects, but there’s one thing you can do! You can pass a property color="#00000090" in the first item, to give an opacity in the text.

inserir a descrição da imagem aqui

Thus, we get a contrast with the other items.

  • It was a very cool alternative! Thanks.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.