Skip to content

Commit 3a4e30c

Browse files
committed
[ch-combo-box-render] Don't update the current value when closing with click outside or Escape key
The ch-combo-box-render was updating its value using the active descendant when closed by clicking outside or pressing the Escape key
1 parent 106f22a commit 3a4e30c

File tree

2 files changed

+56
-2
lines changed

2 files changed

+56
-2
lines changed

src/components/combo-box/combo-box.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -686,8 +686,6 @@ export class ChComboBoxRender
686686

687687
// TODO: Add a unit test for this
688688
this.#emitChangeEvent();
689-
} else {
690-
this.#checkAndEmitValueChangeWithNoFilter();
691689
}
692690
};
693691

src/components/combo-box/tests/basic-behavior.e2e.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,62 @@ const testBehavior = (suggest: boolean, strict?: boolean) => {
260260
);
261261
});
262262

263+
// TODO: This test should also be executed with keyboard interactions to
264+
// change the active descendant and verify that the input's value is not
265+
// updated
266+
it("should not update combo-box value with the active descendant when closing with click outside", async () => {
267+
// Set value 3
268+
await comboBoxRef.setProperty("model", simpleModelComboBox1);
269+
await page.waitForChanges();
270+
await comboBoxRef.setProperty("value", "Value 3");
271+
await page.waitForChanges();
272+
273+
// Open the combo-box
274+
await page.click("ch-combo-box-render");
275+
await page.waitForChanges();
276+
277+
const inputRef = await page.find("ch-combo-box-render >>> input");
278+
expect(await inputRef.getProperty("value")).toBe(
279+
suggest ? "Value 3" : "Label for the value 3"
280+
);
281+
282+
// Hover the first value
283+
await page.hover("ch-combo-box-render >>> ch-popover button");
284+
await page.waitForChanges();
285+
286+
await page.click("form");
287+
await page.waitForChanges();
288+
expect(await comboBoxRef.getProperty("value")).toBe("Value 3");
289+
});
290+
291+
// TODO: This test should also be executed with keyboard interactions to
292+
// change the active descendant and verify that the input's value is not
293+
// updated
294+
it("should not update combo-box value with the active descendant when closing with the Escape key", async () => {
295+
// Set value 3
296+
await comboBoxRef.setProperty("model", simpleModelComboBox1);
297+
await page.waitForChanges();
298+
await comboBoxRef.setProperty("value", "Value 3");
299+
await page.waitForChanges();
300+
301+
// Open the combo-box
302+
await page.click("ch-combo-box-render");
303+
await page.waitForChanges();
304+
305+
const inputRef = await page.find("ch-combo-box-render >>> input");
306+
expect(await inputRef.getProperty("value")).toBe(
307+
suggest ? "Value 3" : "Label for the value 3"
308+
);
309+
310+
// Hover the first value
311+
await page.hover("ch-combo-box-render >>> ch-popover button");
312+
await page.waitForChanges();
313+
314+
await comboBoxRef.press("Escape");
315+
await page.waitForChanges();
316+
expect(await comboBoxRef.getProperty("value")).toBe("Value 3");
317+
});
318+
263319
it.skip("should destroy the items after the popover is closed (by clicking outside of the combo-box)", async () => {
264320
await comboBoxRef.setProperty("model", simpleModelComboBox1);
265321
await page.waitForChanges();

0 commit comments

Comments
 (0)