-->

Using the react-select to create the markup using

2019-06-12 21:05发布

问题:

I am new to the react-redux. Here I am trying to achieve the following markup

So from Here what I achieved using the following code is ,

<div className="row">
        <div className="col-md-12">
          <form className="form-inline">
            <div className="form-group col-md-4">
              <lable>Select Technolgoy </lable>
              <Select
                value={selectedOption}
                onChange={this.handleChange}
                options={options}
              />
            </div>
            <div className="form-group col-md-4">
              <lable>Select Component </lable>
              <Select
                value={selectedOption}
                onChange={this.handleChange}
                options={options}
              />
            </div>
            <div className="form-group col-md-4">
              <lable>Select Job </lable>
              <button className="btn btn-primary">
                Add
              </button>
              <button className="btn btn-primary">
                Remove
              </button>
            </div>
          </form>
        </div>
      </div>

So, here I am using the react-select.

What is it that I am doing wrong ? can anyone help me with this? Thanks

回答1:

You need to update the style of your selects like the following lines:

const styles = {
  container: base => ({
    ...base,
    flex: 1
  })
};

function App() {
  return (
    <div className="row">
      <div className="col-12">
        <form className="form-inline">
          <div className="form-group col-4">
            <lable>Select Technolgoy </lable>
            <Select styles={styles} options={options} />
          </div>
          <div className="form-group col-4">
            <lable>Select Component </lable>
            <Select styles={styles} options={options} />
          </div>
          <div className="form-group col-4 row">
            <lable className="col-4">Select Job </lable>
            <button className="btn btn-primary col-4">Add</button>
            <button className="btn btn-primary col-4">Remove</button>
          </div>
        </form>
      </div>
    </div>
  );
}

Here a live example.