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.

Width problem for placeholder

See original GitHub issue

I’m using AutosizeInput with TagsInput and these inputProps:

inputProps={{
  className: 'react-tagsinput-input',
   placeholder: 'Add a theme',
}}

The props that are actually passed to AutosizeInput are:

type='text'
onChange={onChange}
value={value}
className : "react-tagsinput-input"
onBlur: ()
onFocus: ()
onKeyDown: ()
onPaste: ()
placeholder: "Add a theme"
ref: "input"

My problem: on initial render, when ‘value’ is empty, the input box is only a couple of pixels wide. I believe this is because the computation of ‘sizerValue’ in the AutosizeInput render function does not consider the placeholder.

As a temporary fix, I added the following. But it’s a hack because (a) it does not consider that the font could be wider or narrower, and (b) it defeats the autosizing function for tags that are shorter than 90 px.

minWidth: 90

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
ericgiocommented, Nov 28, 2017

@JedWatson: From what I can tell, the issue is due to input styles only being set in componentDidMount. Moving that line here seems to solve the problem.

Happy to submit a PR for this, just wasn’t sure if there was a specific reason you were only setting the styles once.

1reaction
cgatcommented, Oct 2, 2017

I noticed this happening when my element was originally being rendered with display: none. In this case, the placeholder does not have a length and the element length fails to get set properly.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to set an input width to match the placeholder text width
This can be done only via javascript by setting the size = placeholder length: input.setAttribute('size',input.
Read more >
placeholder - CSS: Cascading Style Sheets - MDN Web Docs
Placeholder text with sufficient color contrast may be interpreted as entered input. Placeholder text will also disappear when a person enters ...
Read more >
Don't Use The Placeholder Attribute
If the placeholder content has a contrast ratio that is too low to be perceived, it means that information critical to filling out...
Read more >
CSS : How to set an input width to match the placeholder text ...
CSS : How to set an input width to match the placeholder text width [ Beautify Your Computer : https://www.hows.tech/p/recommended.html ] ...
Read more >
Placeholders
Create placeholders with the .placeholder class and a grid column class (e.g., .col-6 ) to set the width . They can replace the...
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