Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<select> inside of a <label> causes incorrectly targeted click events #729

Open
AlexMax opened this issue Feb 24, 2025 · 2 comments
Open

Comments

@AlexMax
Copy link

AlexMax commented Feb 24, 2025

I have noticed a problem when clicking on an <option> inside of a <select>, if it is nested inside of a <label>. I ripped out all of my CSS and was able to repro this with only the basic rmlui.rcss.

To wit. This basic example does work - the select box result changes when you click an option:

<select name="language" data-value="language">
  <option value="en">$options:languageEnglish</option>
  <option value="fr">$options:languageFrench</option>
  <option value="de">$options:languageGerman</option>
  <option value="it">$options:languageItalian</option>
  <option value="es">$options:languageSpanish</option>
</select>

This basic example also works:

<label>$options:language</label>
<select name="language" data-value="language">
  <option value="en">$options:languageEnglish</option>
  <option value="fr">$options:languageFrench</option>
  <option value="de">$options:languageGerman</option>
  <option value="it">$options:languageItalian</option>
  <option value="es">$options:languageSpanish</option>
</select>

However, this example does not work.

<label>$options:language
<select name="language" data-value="language">
  <option value="en">$options:languageEnglish</option>
  <option value="fr">$options:languageFrench</option>
  <option value="de">$options:languageGerman</option>
  <option value="it">$options:languageItalian</option>
  <option value="es">$options:languageSpanish</option>
</select>
</label>

The reason I'm nesting the elements like this is so clicking on any part of the larger element is like clicking on the select. I attempted to do some RCA and it appears that any OnClick on an <option> element ends up targeting <select> instead.

This is on RmlUi 6.0.

@AlexMax
Copy link
Author

AlexMax commented Feb 25, 2025

I've found that using for inside the label seems to fix the issue. However, the for less label pattern is supported by browsers.

@mikke89
Copy link
Owner

mikke89 commented Mar 2, 2025

Thanks for reporting. Yeah, there are some label scenarios that can be a bit tricky. Using <label for="..."> is generally a bit more robust pattern right now, but I agree that it should work. I will take a closer look at this one once I have some more time. Thanks for reporting it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants