Dropdown not expanding even after having values

Viewed 49

I am facing an issue where my 2nd dropdown is receiving values but is not expanding:-

class clusterServersDropdown extends Component {
  constructor() {
    super();
    this.state = {
      clusterslist: [],
      servertype: [],
      selectserver: "",
      selectcluster: ""
    };
  }
  componentDidMount() {
    this.setState({
        clusterslist:[
            {label: "cluster1", servertype:["test1","test2","test3"]},
            {label: "cluster2", servertype:["test1","test2","test3"]},
            {label: "cluster3", servertype:["test1","test2","test3"]},
        ]
    });
  }
  selectclusterChange(e) {
    console.log(e.label)
    this.setState({ selectcluster: e.label },() =>{
      console.log(this.state.selectcluster)
    });
   
    this.setState({
      servertype: this.state.clusterslist.find(
        (x) => x.label === e.label
      ).servertype
    },() =>{
      console.log(this.state.servertype)
    }
    );    
  }

  routeChange = (e) => {
        console.log(e.label)
        this.setState({ selectserver: e.label}, () => {
        console.log(this.state.selectserver);
        let path = "/inventory/cluster/" + this.state.selectcluster +"/servertype/" + this.state.selectserver;
        console.log(path);
        this.props.history.push(path);
      });
  };

  render() {
    return (
      <div>
        <center>
          <label>
            Select cluster and server type
              <Select className="react-select" classNamePrefix="react-select"
                onChange={this.selectclusterChange.bind(this)}
                options={this.state.clusterslist.map((x) => {
                  return {label: x.label};
                })}
              />
              <Select className="react-select" classNamePrefix="react-select" 
                onChange={this.routeChange.bind(this)}
                options={this.state.servertype.map((y) => {
                  return {label: y};
                })}
              />
          </label>
        </center>
      </div>
    );
  }
}


export default withRouter(clusterServersDropdown);

Please see below snaps:- enter image description here

Whenever I am clicking on the 2nd dropdown it retracts and am not able to select the value and proceed. Strangely this works if i replace label by h5, see as below:- enter image description here

Am i using label wrongly?

1 Answers

Removed label and used h5 with some font formatting instead.

  render() {
    return (
      <div>
        <center>
          <h5 style={{'font-family':"Pacifico"}}>
            Select cluster and server type from dropdown to view its inventory
              <Select className="react-select" classNamePrefix="react-select"
                onChange={this.selectclusterChange.bind(this)}
                options={this.state.clusterslist.map((x) => {
                  return {label: x.label};
                })}
              />
              <Select className="react-select" classNamePrefix="react-select" 
                onChange={this.routeChange}
                options={this.state.servertype.map((y) => {
                  return {label: y};
                })}
              />
            </h5>
        </center>
      </div>
    );
  }
}

Working as expected now.

Related