I'm building a form that contains a select but it's not rendering as a dropdown. It's rendering with a scrollbar and a dropdown down arrow

enter image description here

$form['my_select'] = [
  '#type' => 'select',
  '#empty_option' => '- None -',
  '#title' => $this->t('My Select'),
  '#options' => ['Option1', 'Option2'],
  '#size' => 6,
  '#weight' => '0',

What am I doing wrong?

  • 1
    If you switch to the default, Bartik theme, does it look how you expect?
    – No Sssweat
    Mar 24 '20 at 21:42

It's rendering as a list because you have set #size to 6, which means 6 rows will be visible. Either remove the #size property completely, or set it to 1 to display a normal dropdown.

From the documentation:

#size: The number of rows in the list that should be visible at one time.

  • 1
    That fixed it! Thank you!
    – Vecta
    Mar 25 '20 at 14:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.