Skip to content

Fix useDynamicTextareaHeight not taking into account padding #2848

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

Merged
merged 3 commits into from
Feb 6, 2023

Conversation

iansan5653
Copy link
Contributor

@iansan5653 iansan5653 commented Jan 31, 2023

The useDynamicTextareaHeight uses a utility function that calculates the number of pixels from the top edge of the component to the bottom of a given character. We then use that number of pixels to set the height of a textarea so that the height of the textarea always fits the text inside of it.

However, the utility function includes the top padding in that height. But when we set height on the underlying element, we don't want to include the top padding because when box-sizing is content-box, the height of an element is it's interior height - the height not including any padding or borders.

When I wrote the hook I intended to include a workaround for this by setting the padding to zero, calculating the height, and then resetting the padding back to what it was. But somehow the lines got switched up and I was performing the steps in the wrong order, causing the workaround to have no effect. The result of this was that MarkdownEditor always had slightly too much space below the bottom line of text.

This PR fixes the order of the steps, and also changes the hook to accept a ref instead of an element instance. This is technically a breaking change but we don't need a major bump because this is a draft hook and is not used anywhere in github/github.

Screenshots

Before

Notice how the input expands before it needs to:

Screen.Recording.2023-01-31.at.4.16.35.PM.mov

After

Now the input fits more tightly to the text:

Screen.Recording.2023-01-31.at.4.16.54.PM.mov

@iansan5653 iansan5653 requested review from a team and broccolinisoup January 31, 2023 21:18
@changeset-bot
Copy link

changeset-bot bot commented Jan 31, 2023

🦋 Changeset detected

Latest commit: 83a1df5

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@primer/react Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions
Copy link
Contributor

github-actions bot commented Jan 31, 2023

size-limit report 📦

Path Size
dist/browser.esm.js 89.59 KB (0%)
dist/browser.umd.js 90.22 KB (0%)

@github-actions github-actions bot temporarily deployed to storybook-preview-2848 January 31, 2023 21:25 Inactive
@iansan5653 iansan5653 temporarily deployed to github-pages January 31, 2023 21:26 — with GitHub Actions Inactive
@github-actions github-actions bot temporarily deployed to storybook-preview-2848 January 31, 2023 21:27 Inactive
Copy link
Member

@broccolinisoup broccolinisoup left a comment

Choose a reason for hiding this comment

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

Looks good to me 🚀

@iansan5653 iansan5653 enabled auto-merge (squash) February 3, 2023 18:37
@joshblack joshblack temporarily deployed to github-pages February 6, 2023 18:52 — with GitHub Actions Inactive
@iansan5653 iansan5653 merged commit 196a792 into main Feb 6, 2023
@iansan5653 iansan5653 deleted the fix-auto-textarea-height branch February 6, 2023 18:59
@primer-css primer-css mentioned this pull request Feb 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants