selectize.js icon indicating copy to clipboard operation
selectize.js copied to clipboard

Placeholder text is clipped on Firefox

Open philostler opened this issue 11 years ago • 13 comments

On Firefox 39 OS X (not tested on earlier versions of FF) the placeholder text is initially rendered too small and clips trailing characters. This only happens on FF, Chrome and Safari work as expected.

After selecting the control and deselecting, the placeholder expands and is no longer clipped.

before interaction after interaction

philostler avatar Jul 16 '15 17:07 philostler

My experience is the opposite, I see the problem in Chrome, not in Firefox. Perhaps it depends on the chosen theme (Bootstrap 3 in my case) or the used font. As a ( bad) workaround, we add spaces at the end of the placeholder. I think the main issue is in the computation of the width of the text, done in the measureString function. Perhaps some CSS properties are missing (I wonder already at the missing fontStyle, although that's not the issue here).

PhiLhoSoft avatar Jul 17 '15 11:07 PhiLhoSoft

@PhiLhoSoft I'm using the Bootstrap 3 theme as a base as well so we have cross over there. Nice thought on the workaround, I'll go with that until there's a fix. cheers!

philostler avatar Jul 17 '15 13:07 philostler

This bug is reproducible on IE 11 also. This fixed it for me:

.selectize-input > input[placeholder] {
  width: 100% !important;
}

karan-kang avatar Aug 18 '15 20:08 karan-kang

In the measureString function I changed the width value from 'auto' to '100%' and that worked.

addzies avatar Nov 05 '15 16:11 addzies

+1 ditto happening in ie11.

@addzies Adding 100% solves the problem only if your selectize is well placed in proper columns (bootstrap grid etc.). With 100% width when the <test> is added to the <body> may result into the full viewport width.

The problems seems to be +4 in the call after measureString(val) + 4

4 pixels are not nearly enough after the initial space that browsers add to the placeholders in the input.

bhantol avatar Jan 15 '16 16:01 bhantol

Looks like we'd need something more reliable for autogrow than "oh, let's add N pixels here"

joallard avatar Jan 21 '16 15:01 joallard

Was running into this issue and it was related to the styles on the input inside selectize:

.selectize-input {
  input[type="text"] {
    padding: 0 20px 0 0;
  }
}

The above resulted in clipping 20px.

The padding isn't needed and when it's added on render throws off the width of the input depending on your box model.

landondurnan avatar May 05 '16 20:05 landondurnan

Same issue but resolved it by setting the box-sizing instead of border-box i've put it on initial and now its showing it proper while using padding.

This fixed it for me:

.selectize-input {
    input[placeholder] {
        box-sizing: initial;
    }
}

Because the width calculator is not keeping track of already existing paddings and/or detecting the border-sizing settings. If I would set the width to width: 100% !important it would give me not the effect of an labeled input field.

yoramdelangen avatar Jun 16 '16 14:06 yoramdelangen

Some problem here. MacOS + Google Chrome 55.0.2883. Using Bootstrap 3 and these styles for placeholders in inputs:

::-moz-placeholder {
    color: #aaa;
    opacity: 1; // Override Firefox's unusual default opacity; see https://github.com/twbs/bootstrap/pull/11526
    font-family: 'WorkSans Light', sans-serif;
    text-align: center;
    text-transform: uppercase;
}
:-ms-input-placeholder {
    color: #aaa;
    font-family: 'WorkSans Light', sans-serif;
    text-align: center;
    text-transform: uppercase;
}
::-webkit-input-placeholder {
    color: #aaa;
    font-family: 'WorkSans Light', sans-serif;
    text-align: center;
    text-transform: uppercase;
}

Solution

.selectize-input:not(.has-items) input {
    text-align: center;
    width: 100% !important;
}

Before

before

After

after

kniziol avatar Dec 12 '16 15:12 kniziol

Thank you @kniziol! I used your solution but changed the placeholder colors to #b1b7ba, which seems to be the correct color to match the selectize placeholder in BS3.

ghost avatar Apr 18 '17 19:04 ghost

width: auto !important; or width: 100% !important; might fix it, but it will break other cases. This is bug while calculating input width within selectize library (https://github.com/selectize/selectize.js/blob/master/src/selectize.js#L151) and needs to have better calculation.

shobhitsharma avatar Jul 19 '17 22:07 shobhitsharma

Hello,

Do check the blog post for supported CSS properties on placeholders.

https://blog.ajcw.com/2011/02/styling-the-html5-placeholder/

doushan avatar Jul 04 '18 08:07 doushan

I my case, I use Turbolinks, which replaces body tag content on every request, removing the span used to calculate text input width. So I had to "reset" selectize on every page load using the following code:

(window as any).Selectize.$testInput = undefined;

to make it add the span again.

xhafan avatar Nov 02 '20 16:11 xhafan