-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TextareaAutosize] Sync height when the width of the textarea changes #27840
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- I think that we can keep the window resize handler, for when ResizeObserver is not defined
- I'm no longer sure we need a
useResizeObserver
abstraction. The usage of the native API seems simple enough. If we need to debounce, the story will be different.
try { | ||
resizeObserverRef.current = new ResizeObserver(handleResize); | ||
} catch (err) { | ||
resizeObserverRef.current = MockResizeObserver(); // Prevent crash for old browsers | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to try catch nor to create a MockResizeObserve. We can test if ResizeObserver is defined and do nothing if it's not defined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also prevents test failure, so I think we still need to include it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can't be merged at the moment. We need to wait for the next major version to communicate new browser support.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Way simpler, looks great!
The legacy bundle would've no longer worked in IE11. |
Closes #23641
Problem: as mentioned in the issue, change in the width of a textarea currently does not update the height. Hence, unwanted whitespace ends up existing in multi-line textarea.
Solution: use ResizeObserver API to observe the textarea and update the height in response to the textarea's resizing.
Consider the following textarea:
![Screenshot 2021-08-19 at 08 45 54](https://user-images.githubusercontent.com/32841130/130030570-3c4e9caf-282f-43f6-80d8-ff16f8d86313.png)
Without the implementation of this pull request (when there is change in the width of the textarea):
![Screenshot 2021-08-19 at 08 46 01](https://user-images.githubusercontent.com/32841130/130030595-51131022-5411-4564-a92c-7d27e1e19863.png)
With the implementation of this pull request (when there is change in the width of the textarea):
![Screenshot 2021-08-19 at 08 51 06](https://user-images.githubusercontent.com/32841130/130030613-44e3407b-809d-41c9-8471-c1cd8698d185.png)