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

feat(color-picker-hex-input): auto apply new color after typing/pasting hex code #9561

Merged
merged 18 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
6591424
fix(color-picker-hex-input): fix color not auto updating
aPreciado88 Jun 11, 2024
5043c9b
Merge branch 'dev' of github.com:Esri/calcite-design-system into aPre…
aPreciado88 Jun 11, 2024
54cd63e
fix(color-picker-hex-input): fix color not auto updating
aPreciado88 Jun 12, 2024
69b82eb
fix(color-picker-hex-input): fix color not auto updating
aPreciado88 Jun 12, 2024
3336d89
fix(color-picker-hex-input): fix color not auto updating
aPreciado88 Jun 12, 2024
d53e0b2
fix(color-picker-hex-input): fix color not auto updating
aPreciado88 Jun 12, 2024
2ceb323
fix(color-picker-hex-input): fix color not auto updating
aPreciado88 Jun 17, 2024
1f2bb44
fix(color-picker-hex-input): fix color not auto updating
aPreciado88 Jun 17, 2024
e305eeb
Merge branch 'dev' of github.com:Esri/calcite-design-system into aPre…
aPreciado88 Jun 17, 2024
b582603
feat(color-picker-hex-input): fix color not auto updating
aPreciado88 Jun 17, 2024
1f47df2
feat(color-picker-hex-input): fix color not auto updating
aPreciado88 Jun 17, 2024
5d94a47
Merge branch 'dev' of github.com:Esri/calcite-design-system into aPre…
aPreciado88 Jun 17, 2024
551af62
Merge branch 'dev' of github.com:Esri/calcite-design-system into aPre…
aPreciado88 Jun 18, 2024
13a099a
fix(color-picker-hex-input): update unit tests
aPreciado88 Jun 18, 2024
d5977f5
fix(color-picker-hex-input): update unit tests
aPreciado88 Jun 20, 2024
98eacc9
fix(color-picker-hex-input): update unit tests
aPreciado88 Jun 20, 2024
af12d82
Merge branch 'dev' of github.com:Esri/calcite-design-system into aPre…
aPreciado88 Jun 20, 2024
f151102
Merge branch 'dev' into aPreciado88/7057-apply-entered-hex-value-imme…
benelan Jun 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,19 @@ export class ColorPickerHexInput implements LoadableComponent {
this.internalSetValue(value, this.value);
};

private onInputFocus = (): void => {
this.hexInputNode.selectText();
};

private onInputChange = (): void => {
const hexInputValue = `#${this.hexInputNode.value}`;
const oldValue = this.value;

if (isValidHex(hexInputValue) && isLonghandHex(hexInputValue)) {
this.internalSetValue(hexInputValue, oldValue);
}
};

protected onInputKeyDown = (event: KeyboardEvent): void => {
const { altKey, ctrlKey, metaKey, shiftKey } = event;
const { alphaChannel, hexInputNode, internalColor, value } = this;
Expand Down Expand Up @@ -274,6 +287,7 @@ export class ColorPickerHexInput implements LoadableComponent {
if (isValidHex(hex)) {
event.preventDefault();
this.hexInputNode.value = hex.slice(1);
this.internalSetValue(hex, this.value);
}
};

Expand Down Expand Up @@ -316,6 +330,8 @@ export class ColorPickerHexInput implements LoadableComponent {
maxLength={6}
onCalciteInputTextChange={this.onHexInputChange}
onCalciteInternalInputTextBlur={this.onHexInputBlur}
onFocus={this.onInputFocus}
onInput={this.onInputChange}
onKeyDown={this.onInputKeyDown}
onPaste={this.onHexInputPaste}
prefixText="#"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1034,6 +1034,8 @@ export class ColorPicker
numberingSystem={this.numberingSystem}
onCalciteInputNumberChange={this.handleChannelChange}
onCalciteInputNumberInput={this.handleChannelInput}
onFocus={this.handleInputFocus}
onInput={this.handleChannelInputChange}
Copy link
Member

Choose a reason for hiding this comment

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

For consistency, can you use the calcite-specific events? Also, the event name doesn't match the event (e.g., named after the change event, but it's listening to input). Applies to the hex-input changes.

onKeyDown={this.handleKeyDown}
scale={this.scale === "l" ? "m" : "s"}
// workaround to ensure input borders overlap as desired
Expand All @@ -1055,12 +1057,22 @@ export class ColorPicker
//
//--------------------------------------------------------------------------

handleChannelInputChange = (event: Event): void => {
const customEvent = event as CustomEvent;
this.handleChannelChange(customEvent);
};

handleKeyDown(event: KeyboardEvent): void {
if (event.key === "Enter") {
event.preventDefault();
}
}

handleInputFocus = (event: Event): void => {
Copy link
Member

Choose a reason for hiding this comment

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

Selecting text is a great enhancement, but it does seem unrelated to committing on paste/input. Could we submit this separately?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll create a separate issue for this.

const input = event.currentTarget as HTMLCalciteInputNumberElement;
input.selectText();
};

private showIncompatibleColorWarning(value: ColorValue, format: Format): void {
console.warn(
`ignoring color value (${value}) as it is not compatible with the current format (${format})`,
Expand Down
Loading