-
Notifications
You must be signed in to change notification settings - Fork 85
onChange not invoked when textarea resizes if state
is updated in onResize callback
#109
Comments
Hi @vlazh ,
The callback called when on autoresizing is |
Just try type 'enter' or some letter when textarea is full and then textarea resized ( onResize invoked) but 'new line' or typed letter will not be present in controlled value, because onChange not invoked. |
I'm sorry but I cannot reproduce it: You can test it yourself here: https://react-components.buildo.io/#textareaautosize What are you doing in the |
Try this code: initialState = { value: '', height: 30 };
<TextareaAutosize
value={state.value}
onChange={e => { setState({value:e.target.value}); }}
onResize={e => { setState({height:e.target.clientHeight}); }}
placeholder='try writing some lines'
/> |
Thanks for the code, I finally managed to reproduce it :) The reason your code isn't working is quite complicated:
Put those three together and: To make your code work you could defer the initialState = {
value: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
height: 30
};
<TextareaAutosize
value={state.value}
onChange={e => {
setState({ value: e.target.value });
}}
onResize={e => {
const height = e.target.clientHeight
setTimeout(() => setState({ height }))
}}
/>; (I have to analyse the issue further to understand if it's a good idea to defer that event directly in textarea's code) |
Ok, thanx! |
state
is updated in onResize callback
On controlled component onChange not invoked on autoresizing.
The text was updated successfully, but these errors were encountered: