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 all 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 @@ -348,6 +348,19 @@ describe("calcite-color-picker-hex-input", () => {
await assertTabAndEnterBehavior("", startingHex);
});

it("commits longhand hex chars when typing", async () => {
await selectText(input);
await page.keyboard.type("abc");
await page.waitForChanges();

expect(await input.getProperty("value")).toBe(startingHex);

await page.keyboard.type("def");
await page.waitForChanges();

expect(await input.getProperty("value")).toBe("#abcdef");
});

it("prevents committing invalid hex values", async () => {
await assertTabAndEnterBehavior("aabbc", startingHex);
await assertTabAndEnterBehavior("aabb", startingHex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,18 @@ export class ColorPickerHexInput implements LoadableComponent {
this.internalSetValue(value, this.value);
};

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

if (
isValidHex(hexInputValue, this.alphaChannel) &&
isLonghandHex(hexInputValue, this.alphaChannel)
) {
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 @@ -271,9 +283,10 @@ export class ColorPickerHexInput implements LoadableComponent {
private onHexInputPaste = (event: ClipboardEvent): void => {
const hex = event.clipboardData.getData("text");

if (isValidHex(hex)) {
if (isValidHex(hex, this.alphaChannel) && isLonghandHex(hex, this.alphaChannel)) {
event.preventDefault();
this.hexInputNode.value = hex.slice(1);
this.internalSetValue(hex, this.value);
}
};

Expand Down Expand Up @@ -315,6 +328,7 @@ export class ColorPickerHexInput implements LoadableComponent {
label={messages?.hex || hexLabel}
maxLength={6}
onCalciteInputTextChange={this.onHexInputChange}
onCalciteInputTextInput={this.onHexInput}
onCalciteInternalInputTextBlur={this.onHexInputBlur}
onKeyDown={this.onInputKeyDown}
onPaste={this.onHexInputPaste}
Expand Down
Loading