-
Notifications
You must be signed in to change notification settings - Fork 76
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
feat(color-picker, color-picker-hex-input): Add input auto commit, blur and auto select enhancements. #9701
Merged
aPreciado88
merged 22 commits into
dev
from
aPreciado88/9624-color-picker-component-enhancements
Jul 19, 2024
Merged
Changes from 20 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
6591424
fix(color-picker-hex-input): fix color not auto updating
aPreciado88 5043c9b
Merge branch 'dev' of github.com:Esri/calcite-design-system into aPre…
aPreciado88 54cd63e
fix(color-picker-hex-input): fix color not auto updating
aPreciado88 69b82eb
fix(color-picker-hex-input): fix color not auto updating
aPreciado88 3336d89
fix(color-picker-hex-input): fix color not auto updating
aPreciado88 d53e0b2
fix(color-picker-hex-input): fix color not auto updating
aPreciado88 2ceb323
fix(color-picker-hex-input): fix color not auto updating
aPreciado88 20d7630
feat(color-picker,color-picker-hex-input) pull dev
aPreciado88 d88d363
Merge branch 'dev' of github.com:Esri/calcite-design-system into aPre…
aPreciado88 c7e73dc
feat(color-picker,color-picker-hex-input): add component enhancements
aPreciado88 1335003
feat(color-picker,color-picker-hex-input): fix merge conflicts
aPreciado88 6b16caa
feat(color-picker,color-picker-hex-input): update click handler logic
aPreciado88 23e4bb7
feat(color-picker,color-picker-hex-input): update input blur logic
aPreciado88 a425167
feat(color-picker,color-picker-hex-input): update input blur function…
aPreciado88 70a3c0c
Merge branch 'dev' of github.com:Esri/calcite-design-system into aPre…
aPreciado88 3019101
feat(color-picker,color-picker-hex-input): update end to end tests
aPreciado88 eb646aa
Merge branch 'dev' of github.com:Esri/calcite-design-system into aPre…
aPreciado88 fcf027c
fix(tile): update input blur logic and code clean up
aPreciado88 a5a6a2a
Merge branch 'dev' of github.com:Esri/calcite-design-system into aPre…
aPreciado88 f21e7fa
Merge branch 'dev' of github.com:Esri/calcite-design-system into aPre…
aPreciado88 15f4822
feat(color-picker, color-picker-hex-input): code clean up
aPreciado88 0a9afce
Merge branch 'dev' into aPreciado88/9624-color-picker-component-enhan…
aPreciado88 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ import { | |
hexChar, | ||
hexify, | ||
isLonghandHex, | ||
isShorthandHex, | ||
isValidHex, | ||
normalizeHex, | ||
opacityToAlpha, | ||
|
@@ -146,8 +147,10 @@ export class ColorPickerHexInput implements LoadableComponent { | |
const willClearValue = allowEmpty && !inputValue; | ||
const isLonghand = isLonghandHex(hex); | ||
|
||
// ensure modified pasted hex values are committed since we prevent default to remove the # char. | ||
this.onHexInputChange(); | ||
if (isShorthandHex(hex, this.alphaChannel)) { | ||
// ensure modified pasted hex values are committed since we prevent default to remove the # char. | ||
this.onHexInputChange(); | ||
} | ||
|
||
if (willClearValue || (isValidHex(hex) && isLonghand)) { | ||
return; | ||
|
@@ -180,6 +183,14 @@ export class ColorPickerHexInput implements LoadableComponent { | |
allowEmpty && !internalColor ? "" : this.formatOpacityForInternalInput(internalColor); | ||
}; | ||
|
||
private onOpacityInputFocus = (): void => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick: selection text handlers could be merged into one and reused. |
||
this.opacityInputNode.selectText(); | ||
}; | ||
|
||
private onOpacityInputInput = (): void => { | ||
this.onOpacityInputChange(); | ||
}; | ||
|
||
private onHexInputChange = (): void => { | ||
const nodeValue = this.hexInputNode.value; | ||
let value = nodeValue; | ||
|
@@ -210,7 +221,11 @@ export class ColorPickerHexInput implements LoadableComponent { | |
this.internalSetValue(value, this.value); | ||
}; | ||
|
||
private onHexInput = (): void => { | ||
private onHexInputFocus = (): void => { | ||
this.hexInputNode.selectText(); | ||
}; | ||
|
||
private onHexInputInput = (): void => { | ||
const hexInputValue = `#${this.hexInputNode.value}`; | ||
const oldValue = this.value; | ||
|
||
|
@@ -228,7 +243,7 @@ export class ColorPickerHexInput implements LoadableComponent { | |
const { key } = event; | ||
const composedPath = event.composedPath(); | ||
|
||
if (key === "Tab" || key === "Enter") { | ||
if ((key === "Tab" && isShorthandHex(value, this.alphaChannel)) || key === "Enter") { | ||
if (composedPath.includes(hexInputNode)) { | ||
this.onHexInputChange(); | ||
} else { | ||
|
@@ -326,10 +341,11 @@ export class ColorPickerHexInput implements LoadableComponent { | |
<calcite-input-text | ||
class={CSS.hexInput} | ||
label={messages?.hex || hexLabel} | ||
maxLength={6} | ||
maxLength={this.alphaChannel ? 8 : 6} | ||
onCalciteInputTextChange={this.onHexInputChange} | ||
onCalciteInputTextInput={this.onHexInput} | ||
onCalciteInputTextInput={this.onHexInputInput} | ||
onCalciteInternalInputTextBlur={this.onHexInputBlur} | ||
onCalciteInternalInputTextFocus={this.onHexInputFocus} | ||
onKeyDown={this.onInputKeyDown} | ||
onPaste={this.onHexInputPaste} | ||
prefixText="#" | ||
|
@@ -347,8 +363,9 @@ export class ColorPickerHexInput implements LoadableComponent { | |
min={OPACITY_LIMITS.min} | ||
numberButtonType="none" | ||
numberingSystem={this.numberingSystem} | ||
onCalciteInputNumberChange={this.onOpacityInputChange} | ||
onCalciteInputNumberInput={this.onOpacityInputInput} | ||
onCalciteInternalInputNumberBlur={this.onOpacityInputBlur} | ||
onCalciteInternalInputNumberFocus={this.onOpacityInputFocus} | ||
onKeyDown={this.onInputKeyDown} | ||
ref={this.storeOpacityInputRef} | ||
scale={inputScale} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Not critical for this PR, but can you look into moving hex and hexa-specific tests under their respective describe blocks?
This test suite needs to be revisited, so we could also create a follow-up issue to restructure/simplify the suite and tackle this there.