Comments (6)
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.
from react-input-autosize.
@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.
from react-input-autosize.
I'm seeing this issue as well, both when a parent is initially rendered with display: none
and when props change that should affect the input size. Even when forcing a prop change to the input, however, I'm not seeing it update as I would expect.
from react-input-autosize.
If someone can provide a link (e.g. to codesandbox) or adds an example that reproduces this I'd be happy to take a look at it
from react-input-autosize.
Hello @JedWatson I have the same problem. Here you can find some of my implementation.
It's a really wierd behavior.
I have 2 lists that used the same method to render a input. They Both called renderColumn
First list is ok, second list isn't. I use a tab to switch between first list (password) and second (licence).
All state is in redux as i use redux-form.
const renderColumn = props => {
const {
index,
renderToaster,
input: { name, onChange, value },
placeholder,
...restProps
} = props;
return (
<Column
onChange={onChange}
renderToaster={renderToaster}
text={value}
maxLength={50}
name={name}
placeholder={placeholder}
restProps={restProps}
/>
);
};
<MDBTableBody>
{fields.map((data, index) => {
return (
<tr key={"key_" + index}>
<DeleteRow deleteARow={() => fields.remove(index)} />
<Field
name={`${data}.login`}
component={renderColumn}
renderToaster={renderToaster}
placeholder={LOGIN}
/>
<Field
name={`${data}.password`}
component={renderColumn}
renderToaster={renderToaster}
placeholder={PASSWORD}
/>
<Field
name={`${data}.account`}
component={renderColumn}
renderToaster={renderToaster}
placeholder={ACCOUNT}
/>
</tr>
);
})}
</MDBTableBody>
<MDBTableBody>
{fields.map((data, index) => {
return (
<tr key={"key_" + index}>
<DeleteRow deleteARow={() => fields.remove(index)} />
<Field
name={`${data}.buyDate`}
component={renderColumn}
renderToaster={renderToaster}
placeholder={BUYDATE}
/>
<Field
name={`${data}.key`}
component={renderColumn}
renderToaster={renderToaster}
placeholder={KEY}
/>
<Field
name={`${data}.program`}
component={renderColumn}
renderToaster={renderToaster}
placeholder={PROGRAM}
/>
<Field
name={`${data}.computer`}
component={renderColumn}
renderToaster={renderToaster}
placeholder={COMPUTER}
/>
</tr>
);
})}
</MDBTableBody>
//render method of the Column Component
render() {
const {
text,
indexPath,
status,
name,
index,
maxLength,
onClick,
placeholder
} = this.props;
return (
<td className='align-vertical'>
<AutosizeInput
className='list_input'
disabled={status}
onClick={onClick}
value={text}
name={name}
onChange={e => {
this.props.onChange(e, indexPath);
}}
index={index}
maxLength={maxLength}
placeholder={placeholder}
/>
<MDBIcon
far
icon='clone'
className={
this.state.isHovered ? "icon_clone_hover" : "icon_clone text-muted"
}
onClick={() => this.copyText(text)}
onMouseEnter={this.handleHover}
onMouseLeave={this.handleHover}
/>
</td>
);
}
}
Here you can see, first line is not ok, but when i click on "Nouveau" button, the new line is ok.
Don't know if this can help you. But when i move my mouse hover the copy icon, then the autosize input take the good size. (my hover method only change the cursor of the mouse to display a hand cursor)
Hope it will help.
Edit:
Here is a picture of the state of the component:
from react-input-autosize.
I just created a new NPM module please check it out:
- 252 byte size only 10% of
react-input-autosize
(2.3KB)
https://github.com/ozluy/calculate-text-width
from react-input-autosize.
Related Issues (20)
- add ref for sizer div for width queries HOT 1
- MinWidth is set to 1 even placeholder is passed down
- Modify styling for :focus and ::placeholder HOT 2
- Update width on viewport resize HOT 1
- Input auto focus property not working
- npm error
- componentWillReceiveProps is deprecated HOT 2
- Failed to load config "keystone-react" to extend from* HOT 2
- How do you style the inner input? HOT 2
- Old prop-types version references bad node-fetch version
- React 17 support HOT 3
- Size isn't computed properly with custom fonts
- Does not update when input element is hidden on first render
- Width is not calculated correctly on font-size change HOT 2
- package-lock.json in repo is not in sync with package.json HOT 1
- Error: Cannot find module 'babel-preset-env' HOT 4
- [bug] input autosize not working with decimals and comma HOT 1
- [bug] css variables
- Passing ref to AutoSizeInput Component HOT 2
- Update for React 18 support HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-input-autosize.