...

/

The SelectDropdown Component

The SelectDropdown Component

Learn how to create a reusable SelectDropdown component with React and Formik.

We'll cover the following...

When we want our users to select an option from the given options, we use the RadioGroup component. But if there are a lot of options to be selected from, the radio group isn’t a suitable choice because there will be a lot of radio buttons littered around the interface. In this situation, our best choice is to use the SelectDropdown component.

Just like the date input field, the appearance of the drop-down that is displayed when a select field is clicked is dependent on the browser rendering the page and the operating system of the device. There are libraries that can help us customize the appearance of the drop-down, one of which is the react-select library. But before we look into it, let’s create a SelectDropdown component without a select drop-down library.

.form-container {
  background: white;
  box-shadow: 0px 4px 0px #eff1f3;
  border-radius: 20px;
  max-width: 480px;
  margin: 56px auto;
  padding: 40px;
}

.header-text {
  font-weight: 700;
  font-size: 24px;
  line-height: 120%;
  text-align: center;
  color: #231942;
}

.sub-text {
  font-weight: 400;
  font-size: 16px;
  line-height: 24px;
  color: #99a0ae;
  text-align: center;
  margin-top: 8px;
}

* {
  font-family: Helvetica, Cambria, Droid Sans, Helvetica Neue, sans-serif;
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  transition: 0.6s;
}

body {
  background: #f6f8fa;
}
button {
  outline: none;
  border: none;
}


button[type="submit"] {
  background: #67adc8;
  border-radius: 8px;
  margin-top: 48px;
  width: 100%;
  font-weight: 600;
  font-size: 16px;
  line-height: 24px;
  color: #ffffff;
  padding: 16px;
  cursor: pointer;
}

button[type="submit"]:hover {
  background: #3399c9;
}
A reusable SelectDropdown component without any library

We create the SelectDropdown component in the ...