Width problem for placeholder
See original GitHub issueI’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:
- Created 7 years ago
- Comments:6 (1 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@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.
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.