-
Notifications
You must be signed in to change notification settings - Fork 28
Use dom-input-range
instead of internal implementation
#55
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
Conversation
I need some time to take a look at this, but I'm curious if |
Good question, I'm not sure about this. If it needs special handling it's probably something I need to implement that wasn't present in the sources I derived from. I glanced through the code here but I don't see any special handling here either. Maybe it just works automatically? Do you have some example content I could try out? |
In chrome you can right click an input to change the writing mode. Looks like it might need to simply copy over the |
Created an issue to track the text direction work upstream: UPDATE: fixed in iansan5653/dom-input-range#3 and released as 1.1.5, so we'll get RTL support automatically by adopting |
Couldn't get an integration test PR working but I was able to test this locally (in cd /workspaces
git clone https://github.com/github/text-expander-element && cd text-expander-element
git checkout use-dom-input-range
npm run compile
cd ../github
npm link -w @npm-workspaces/primer ../text-expander-element |
We currently use an approach of cloning the
textarea
element into a hiddendiv
with all of its styles and content, because the browser allows calculating the position of contents in adiv
but not in atextarea
. This approach has been duplicated and adapted in many places:github/github
The original implementation of this approach is nearly a decade old at this point and we have better options today. Notably, this approach can be pretty inefficient due to how we create and don't clean up the clones, and due to how often we have to copy the styling. This can be as often as every keystroke. In addition this implementation is missing some bugfixes implemented in the source materials after this was derived.
A few months ago I took this approach and rewrote it with a more modern DOM-like API (inspired by
Range
). I audited all the styles we are copying, included all the bug fixes / workarounds from the various diverging implementations, and optimized performance significantly. The clone element is now reused across calls, automatically cleaned up, and only updates when and if necessary (ie, when the user types we don't need to re-clone the styles, we only need to update the text content).The result is https://github.com/iansan5653/dom-input-range, which exposes the
InputRange
API as well as the lower-levelinput-clone-element
. I've been using this for several months in https://github.com/iansan5653/github-markdown-a11y-extension and I'm confident in its reliability and accuracy. Migration is easy and comes with significant performance & code quality improvements, so why not make the switch?Additional changes
dom-input-range
usesimport type
syntax, which the version of TypeScript we are on does not support. Upgrading TypeScript also required upgradingeslint-plugin-github
(to update the parser) which required updatingeslint
.The latest version of ESLint is not compatible with Node 16.x, so I also updated the devcontainer config to move us on to 20.x. This was an oversight previously anyway since our CI is on v20.
Updating ESLint plugin enabled some rules that are violated in test files. Rather than fix these errors and expand the PR footprint, I've disabled them for now since these are only test files.