-
Notifications
You must be signed in to change notification settings - Fork 82
Provide an instance method to update size #114
Comments
this is weird, the textarea should detect it. It also works if you update the width of a container without resizing the browser window: @olavim how does your code differ from those two examples? can you help me reproduce it? |
@FrancescoCioria the following snippet, when pasted to https://react-components.buildo.io/#textareaautosize, works as I described: initialState = {indent: 0, value: ''};
<div style={{width: '600px'}}>
<div style={{paddingLeft: `${state.indent * 40}px`}}>
<TextareaAutosize
style={{width: '100%'}}
value={state.value}
onChange={evt => setState({value: evt.target.value})}
/>
</div>
<button onClick={() => setState({indent: state.indent - 1})}>{'<- indent'}</button>
<button onClick={() => setState({indent: state.indent + 1})}>{'indent ->'}</button>
</div> It's worth to note that the snippet worked correctly when I used an uncontrolled textarea, and when I set the initial value (in So to get what I'm getting, do the following:
|
@olavim thanks for the snippet the issue is in the as we can see we are updating the textarea only if that logic was meant to improve performance, but I can see that it can easily cause bugs... |
In my app I have a need to update the textarea's width without changing its props. Currently the textarea only resizes when its props change (or more specifically, when the
value
orrows
change).Basically, in my app, the textarea is inside a container, and users can indent this container. Since the container's position is constrained from one side, it has no option but to make the underlying text take more vertical space to fit. The textarea doesn't detect this change though.
My current workaround is to call
textareaRef.dispatchEvent('autosize:update')
. My suggestion is to add anupdateSize
(or something) instance method that does this for me, because my current solution is a bit cumbersome since it relies on underlying technicalities.The text was updated successfully, but these errors were encountered: