-
Notifications
You must be signed in to change notification settings - Fork 308
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(textarea): autoresize textarea resets when value is empty (#6031)
- Loading branch information
1 parent
34f8d2d
commit 2e3a051
Showing
3 changed files
with
49 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"@aws-amplify/ui-react": patch | ||
--- | ||
|
||
fix(textarea): autoresize textarea resets when value is empty | ||
|
||
There was a bug with the autoresize text area where it would not reset the size when a value was cleared. This fixes that bug |
41 changes: 41 additions & 0 deletions
41
packages/react/src/primitives/TextArea/__tests__/useAutoresizeTextarea.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { renderHook } from '@testing-library/react-hooks'; | ||
import { useAutoresizeTextArea } from '../useAutoresizeTextarea'; | ||
|
||
describe('useAutoresizeTextArea', () => { | ||
let textAreaRef: HTMLTextAreaElement; | ||
|
||
beforeEach(() => { | ||
textAreaRef = document.createElement('textarea'); | ||
jest.spyOn(window, 'addEventListener'); | ||
jest.spyOn(window, 'removeEventListener'); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.restoreAllMocks(); | ||
}); | ||
|
||
it('should set the height of the textarea', () => { | ||
renderHook(() => useAutoresizeTextArea(textAreaRef, 'initial value')); | ||
expect(textAreaRef.style.height).toBe('0px'); | ||
}); | ||
|
||
it('should add and remove event listener for window resize', () => { | ||
const { unmount } = renderHook(() => useAutoresizeTextArea(textAreaRef)); | ||
expect(window.addEventListener).toHaveBeenCalledWith( | ||
'resize', | ||
expect.any(Function) | ||
); | ||
|
||
unmount(); | ||
expect(window.removeEventListener).toHaveBeenCalledWith( | ||
'resize', | ||
expect.any(Function) | ||
); | ||
}); | ||
|
||
it('should not throw error when textAreaRef is null', () => { | ||
expect(() => { | ||
renderHook(() => useAutoresizeTextArea(null)); | ||
}).not.toThrow(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters