Skip to content
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

Fix rowsMax bug #1369

Merged
merged 8 commits into from
May 25, 2021
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const StyledTextarea = styled.textarea<StyledProps>`
border: none;
appearance: none;
background: ${input.background};

height: auto;
${({ spacings }) => spacingsTemplate(spacings)}
${typographyTemplate(input.typography)}

Expand Down
9 changes: 9 additions & 0 deletions libraries/core-react/src/hooks/useAutoResize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,22 @@ export const useAutoResize = (
newHeight = Math.max(targetEl.scrollHeight, newHeight)
if (maxHeight) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this check necessary as you are already checking it on line 13?

Copy link
Contributor Author

@pomfrida pomfrida May 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

targetEl.style.height = 'auto' is needed here too, for it to autoresize correctly when user deletes text. It's to rewrite the height when it's set before.

The nested maxHeight check is also needed, as you can see its if parent is !maxHeight || maxHeight > newHeight, this logic is needed for whenever maxHeight > newHeight only

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Improvements fixed and tested so ready again for review @mimarz

newHeight = Math.min(maxHeight, newHeight)
if (targetEl.scrollHeight > maxHeight) {
targetEl.style.overflow = 'auto'
} else {
targetEl.style.overflow = 'hidden'
}
}
if (newHeight > targetEl.clientHeight) {
targetEl.style.height = `${newHeight}px`
}
}
}

if (targetEl) {
handleResize()
}

targetEl?.addEventListener('keyup', handleResize, true)

return () => {
Expand Down