Skip to content

Commit dc7a0ef

Browse files
authored
fix(color-picker): ensure shorthand hex is expanded regardless of alpha channel presence (#11188)
**Related Issue:** #11187 ## Summary Fixes a regression from #9701, where only RGBA shorthand hex values would be accepted by `calcite-color-picker-hex-input`.
1 parent 4b63087 commit dc7a0ef

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

packages/calcite-components/src/components/color-picker-hex-input/color-picker-hex-input.e2e.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ describe("calcite-color-picker-hex-input", () => {
112112

113113
it("commits shorthand hex on blur", async () => {
114114
const defaultHex = "#b33f33";
115-
const editedHex = "#aabbcc";
115+
const expandedHex = "#aabbcc";
116116
const page = await newE2EPage();
117117
await page.setContent(`<calcite-color-picker-hex-input value='${defaultHex}'></calcite-color-picker-hex-input>`);
118118

@@ -129,45 +129,53 @@ describe("calcite-color-picker-hex-input", () => {
129129
await page.keyboard.press("Tab");
130130
await page.waitForChanges();
131131

132-
expect(await input.getProperty("value")).toBe(editedHex);
132+
expect(await input.getProperty("value")).toBe(expandedHex);
133133

134134
await selectText(input);
135135
await page.keyboard.type("abcd");
136136
await page.keyboard.press("Tab");
137137
await page.waitForChanges();
138138

139-
expect(await input.getProperty("value")).toBe(editedHex);
139+
expect(await input.getProperty("value")).toBe(expandedHex);
140140
});
141141

142-
it("commits shorthand hexa on blur", async () => {
142+
it("commits shorthand hex and hexa on blur", async () => {
143143
const defaultHexa = "#b33f33ff";
144-
const editedHexa = "#aabbccdd";
144+
const expandedHexa = "#aabbccdd";
145+
const expandedHex = "#aabbccff";
145146
const page = await newE2EPage();
146147
await page.setContent(
147148
`<calcite-color-picker-hex-input alpha-channel value='${defaultHexa}'></calcite-color-picker-hex-input>`,
148149
);
149150

150151
const input = await page.find(`calcite-color-picker-hex-input`);
151152
await selectText(input);
152-
await page.keyboard.type("abc");
153+
await page.keyboard.type("ab");
153154
await page.keyboard.press("Tab");
154155
await page.waitForChanges();
155156

156157
expect(await input.getProperty("value")).toBe(defaultHexa);
157158

159+
await selectText(input);
160+
await page.keyboard.type("abc");
161+
await page.keyboard.press("Tab");
162+
await page.waitForChanges();
163+
164+
expect(await input.getProperty("value")).toBe(expandedHex);
165+
158166
await selectText(input);
159167
await page.keyboard.type("abcd");
160168
await page.keyboard.press("Tab");
161169
await page.waitForChanges();
162170

163-
expect(await input.getProperty("value")).toBe(editedHexa);
171+
expect(await input.getProperty("value")).toBe(expandedHexa);
164172

165173
await selectText(input);
166174
await page.keyboard.type("abcde");
167175
await page.keyboard.press("Tab");
168176
await page.waitForChanges();
169177

170-
expect(await input.getProperty("value")).toBe(editedHexa);
178+
expect(await input.getProperty("value")).toBe(expandedHexa);
171179
});
172180

173181
it("normalizes value when initialized", async () => {

packages/calcite-components/src/components/color-picker-hex-input/color-picker-hex-input.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,9 @@ export class ColorPickerHexInput extends LitElement implements LoadableComponent
176176
const { allowEmpty, internalColor } = this;
177177
const willClearValue = allowEmpty && !inputValue;
178178
const isLonghand = isLonghandHex(hex);
179+
const anyShorthand = isShorthandHex(hex, true) || isShorthandHex(hex, false);
179180

180-
if (isShorthandHex(hex, this.alphaChannel)) {
181+
if (anyShorthand) {
181182
// ensure modified pasted hex values are committed since we prevent default to remove the # char.
182183
this.onHexInputChange();
183184
}

0 commit comments

Comments
 (0)