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

Account for box-sizing: border-box #2

Merged
merged 2 commits into from
Dec 7, 2021

Conversation

Bestra
Copy link

@Bestra Bestra commented Dec 6, 2021

Background

This is some of the upshot from the investigation in https://github.com/github/github/pull/200660
After some initial investigation I realized that I hadn't properly evaluated textarea-caret's behavior when a scrollbar was present. We use box-sizing: border-box everywhere, but the test page doesn't. I was stumped for a little while until I read through the properties carefully.

What this PR does

  1. Adds a test for a <textarea> with box-sizing: border-box. Along the way I converted the test page to properly use the new ES module -- I think it's broken in the base branch.
    Here's an example of the bad behavior in chrome. Note the cursor is off by a few lines, and you can see visible differences in the line wrapping.
chrome-before.mp4

Firefox is much better but still has small differences in width that add up (Firefox also scrolls for you when you click in the demo, forgive the jerkiness). This is especially apparent in the last few seconds of the video.

firefox-before.mp4
  1. Adds special case code for box-sizing: border-box. Webkit/Chromium and Firefox needed separate fixes. I've evaluated these through quite a bit of trial and error, and I think this makes the results pixel-perfect on all three browsers.
    Here's chrome after the fix. Note the cursor and wrapping line up perfectly now.
chrome-after.mp4

Firefox is also fixed from what I can tell, both testing here and in the other PR.

firefox-after.mp4

This needs slightly different changes for webkit/chromium and firefox.

Firefox's width is close to correct, but needs to subtract out the border width.
Chrome and Safari need to use the clientWidth property
instead of width.
Copy link
Owner

@koddsson koddsson left a comment

Choose a reason for hiding this comment

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

This looks good to me ✨

@koddsson koddsson merged commit 4cfbac4 into koddsson:es Dec 7, 2021
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.

2 participants