question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Select Input label causing error with certain IDs

See original GitHub issue

A recent change introduced in pull request 20833 is failing on certain ids.

  • The issue is present in the latest release.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 😯

This pull request makes naive use of querySelector() (simply prepending “#” to the id name verbatim).

Because querySelector() uses CSS selectors, and because CSS selectors have slightly different rules to HTML element ids, this is causing ids with certain symbols to fail.

In the worst case, material ui crashes entirely. In other cases, it just causes the functionality itself to fail.

Expected Behavior 🤔

This code should be able to handle symbols in ids, as they are valid in html ids, and as worked in previous versions.

For example, is there any reason for using querySelector() over getElementById(), considering what the code has is an id and what it wants to get is an element?

If there’s some reason for using querySelector(), it should sanitize the input it passes by escaping any special characters.

Steps to Reproduce 🕹

I’ve created three examples on codesandbox:

  • First example: This exhibits an actual crash using <Select> and <InputLabel> with a failing labelId.
  • Second example: This exhibits how it can fail using <TextField>.
  • Third example: This exhibits an id which fails but does not cause an outright crash. Here, one label fails because it has a special character, another works as-is.

All of these examples should work as-is in the previous version.

Steps:

  1. Use a select-style <TextField> with a special character in its id property.

OR

  1. Use a <Select> with a special character in its labelId property.

Context 🔦

We currently use some of these special characters in auto-generated ids.

Your Environment 🌎

It happens with @material-ui/core 4.9.14. It did not happen prior to this version.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:4
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
oliviertassinaricommented, May 15, 2020

@gpietro Yes, this weekend.

1reaction
hadasmaimoncommented, May 24, 2020

Thanks for fixing it! now it works on "@material-ui/core": "4.10.0",

Read more comments on GitHub >

github_iconTop Results From Across the Web

Select Input label causing error with certain IDs #21045 - GitHub
A recent change introduced in pull request 20833 is failing on certain ids. The issue is present in the latest release.
Read more >
html - Why am I getting this error The value of the for attribute ...
Your label has a for attribute with value title but there is no input element with an id of title. Maybe you are...
Read more >
Trello Label ID Error - Power Platform Community - Microsoft
I have narrowed down the cause to the Label-ID field I have tried everything in this field putting text, 1 but it comes...
Read more >
The Label element - HTML: HyperText Markup Language | MDN
To explicitly associate a <label> element with an <input> element, you first need to add the id attribute to the <input> element.
Read more >
Creating Accessible Forms - Accessible Form Controls - WebAIM
You can also create the association by placing the label text and the input within the <label> element (and not using for and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found