React-select: [v2] Bug - Label with htmlFor not triggering focus

Created on 1 Jul 2018  路  3Comments  路  Source: JedWatson/react-select

When using label with htmlFor, its referenced element is not triggering focus. Here is a sandbox with an example:

https://codesandbox.io/s/3r4l5o2qwp

React: 16.3.2
React-Select: 2.0.0-beta.6

Test case steps

  • Clicking "first" triggers focus on the first select, which is the default html select behavior.
  • Clicking "second" does nothing

This prevents us from advanced styling with label, such as this case:

image
image

The text element in the first image is a label on top of react-select, and clicking on it does not open/focus the select. I can only start typing clicking outside the label.

Most helpful comment

Use inputId instead id

<label htmlFor="second">second</label>
<Select options={options} name="second" inputId="second" />

All 3 comments

Use inputId instead id

<label htmlFor="second">second</label>
<Select options={options} name="second" inputId="second" />

@someden awesome, that did the work. Thanks

You can add openMenuOnFocus to open the menu on label click.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ericj17 picture ericj17  路  3Comments

geraldfullam picture geraldfullam  路  3Comments

steida picture steida  路  3Comments

juliensnz picture juliensnz  路  3Comments

pashap picture pashap  路  3Comments