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

Material Select "offsets" text when leading or trailing whitespace is present #3249

Open
limelights opened this issue Jun 13, 2016 · 3 comments · Fixed by materializecss/materialize#100

Comments

@limelights
Copy link

limelights commented Jun 13, 2016

When creating a Select element with the following markup

<select name="language">
    <option value="EN">
                  English
    </option>
    <option value="EN">
                  Romulan
    </option>   
</select>

the JavaScript will interpret the HTML including the whitespace leading the text "English" and "Romulan" and append it to the generated span element. This causes the selected option text to be offset by X amount of whitespace producing the Codepen below

The offending JavaScript file seems to be:
https://github.com/Dogfalo/materialize/blob/f7390445388813882d3b6948b0f034dec3eb700a/js/forms.js

And offending lines: L416, L418, L425, L427

The fix "could" be a simple .trim() on the HTML to rid the leading and trailing whitespace.

Codepen for not working scenario: http://codepen.io/webhenrik/pen/mEPOwx
Codepen for working scenario: http://codepen.io/webhenrik/pen/jrqVwo

@TheRPunkt
Copy link

Same problem here... Is an official fix coming?

@dargmuesli
Copy link

dargmuesli commented Sep 27, 2018

I fixed this once for me by simply adding .trim(): https://github.com/Dargmuesli/materialize/commit/b1a32c91b14ef388397e0b4fbac1e314832ee816#diff-338f03716a63d52eee0f79b4510d617c
I guess for v1 it needs to be added (at least) here:

let text = $(el).text();

I'll have a look at it tomorrow :)

dargmuesli added a commit to dargmuesli/jonas-thelemann that referenced this issue Sep 27, 2018
@dargmuesli dargmuesli mentioned this issue Sep 28, 2018
8 tasks
richarddewit added a commit to richarddewit/materialize that referenced this issue Mar 31, 2021
A fix provided in Dogfalo#6142 to fix Dogfalo#3249
@Smankusors
Copy link

Fixed on materializecss#100

bugy pushed a commit to bugy/materialize that referenced this issue Oct 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants