-
Notifications
You must be signed in to change notification settings - Fork 127
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(circuit-ui): ColorInput paste and change events #2687
Conversation
🦋 Changeset detectedLatest commit: db0b401 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2687 +/- ##
==========================================
+ Coverage 86.63% 86.74% +0.11%
==========================================
Files 210 210
Lines 12000 12043 +43
Branches 1507 1520 +13
==========================================
+ Hits 10396 10447 +51
+ Misses 1551 1543 -8
Partials 53 53
|
08457d2
to
cbe2b7f
Compare
cbe2b7f
to
16ceaee
Compare
expect(colorPicker.value).toBe('#000000'); | ||
expect(colorInput.value).toBe(''); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are the values different here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#000000 is the default for color picker, to my understanding it can never not have a value whereas the color input can be empty - meaning no color submitted.
|
||
const pastedText = e.clipboardData.getData('text/plain').trim(); | ||
|
||
if (!pastedText || !/^#[0-9A-F]{6}$/i.test(pastedText)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (!pastedText || !/^#[0-9A-F]{6}$/i.test(pastedText)) { | |
if (!pastedText || !/^#?[0-9A-F]{3,6}$/i.test(pastedText)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the #
should be optional, but then you also need to add it when setting the value of the color picker input.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adjusted for pasting without #
. Allowing 3-char colors is a little bit more tricky because html color input only support 7-character strings (6 for color + #
)1.
Footnotes
const onPickerColorChange: ChangeEventHandler<InputElement> = (e) => { | ||
setCurrentColor(e.target.value); | ||
if (colorInputRef.current) { | ||
colorInputRef.current.value = e.target.value.replace('#', ''); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be worth to extract the formatting logic for the color input and color picker values into reusable functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tried and honestly didn't find it more readable. I think with just #
even these inline calls should be understandable as long as all of them happen inside ColorInput
. Happy to adjust though if you have specific suggestion how.
Improve ColorInput, specifically: - handle default value and value props properly - ensure color picker and hex color input are always synchronized - handle properly paste events with hex color
d8364e0
to
2a58c47
Compare
2a58c47
to
2f4973e
Compare
2f4973e
to
5ecbb4f
Compare
121a167
to
c678dc4
Compare
c678dc4
to
db0b401
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, thank you! 🙌
@connor-baer can I merge? Or anything left? 🙈 |
@matoous Feel free to merge |
Improve ColorInput, specifically: