From 4632b43b05b9e42a6b0ba133f625e5f3b04ac506 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zo=C3=AB=20Peterson?= Date: Mon, 11 Mar 2024 16:43:27 -0500 Subject: [PATCH 1/5] fix(combobox): close the combobox even if there's no selection --- packages/web-components/fast-foundation/src/combobox/combobox.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/web-components/fast-foundation/src/combobox/combobox.ts b/packages/web-components/fast-foundation/src/combobox/combobox.ts index dd037883a64..fa53764d0b5 100644 --- a/packages/web-components/fast-foundation/src/combobox/combobox.ts +++ b/packages/web-components/fast-foundation/src/combobox/combobox.ts @@ -258,6 +258,7 @@ export class FASTCombobox extends FormAssociatedCombobox { ) as FASTListboxOption | null; if (!captured || captured.disabled) { + this.open = !this.open; return; } From 7cf01c87db32cfbb4bd58550ecb5019b883350b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zo=C3=AB=20Peterson?= Date: Mon, 11 Mar 2024 16:49:46 -0500 Subject: [PATCH 2/5] Change files --- ...st-foundation-47afe4a7-9451-4c4c-beba-70305e6b600e.json | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 change/@microsoft-fast-foundation-47afe4a7-9451-4c4c-beba-70305e6b600e.json diff --git a/change/@microsoft-fast-foundation-47afe4a7-9451-4c4c-beba-70305e6b600e.json b/change/@microsoft-fast-foundation-47afe4a7-9451-4c4c-beba-70305e6b600e.json new file mode 100644 index 00000000000..f008758786c --- /dev/null +++ b/change/@microsoft-fast-foundation-47afe4a7-9451-4c4c-beba-70305e6b600e.json @@ -0,0 +1,7 @@ +{ + "type": "patch", + "comment": "fix(combobox): close the combobox even if there's no selection", + "packageName": "@microsoft/fast-foundation", + "email": "zoepeterson@microsoft.com", + "dependentChangeType": "patch" +} From 464bb505ae68ca4e9bffe2853b7e50f09571f632 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zo=C3=AB=20Peterson?= Date: Mon, 11 Mar 2024 20:44:50 -0500 Subject: [PATCH 3/5] pr feedback --- ...-fast-foundation-47afe4a7-9451-4c4c-beba-70305e6b600e.json | 4 ++-- .../web-components/fast-foundation/src/combobox/combobox.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/change/@microsoft-fast-foundation-47afe4a7-9451-4c4c-beba-70305e6b600e.json b/change/@microsoft-fast-foundation-47afe4a7-9451-4c4c-beba-70305e6b600e.json index f008758786c..20547c3ba93 100644 --- a/change/@microsoft-fast-foundation-47afe4a7-9451-4c4c-beba-70305e6b600e.json +++ b/change/@microsoft-fast-foundation-47afe4a7-9451-4c4c-beba-70305e6b600e.json @@ -1,7 +1,7 @@ { - "type": "patch", + "type": "prerelease", "comment": "fix(combobox): close the combobox even if there's no selection", "packageName": "@microsoft/fast-foundation", "email": "zoepeterson@microsoft.com", - "dependentChangeType": "patch" + "dependentChangeType": "prerelease" } diff --git a/packages/web-components/fast-foundation/src/combobox/combobox.ts b/packages/web-components/fast-foundation/src/combobox/combobox.ts index fa53764d0b5..d62b253a677 100644 --- a/packages/web-components/fast-foundation/src/combobox/combobox.ts +++ b/packages/web-components/fast-foundation/src/combobox/combobox.ts @@ -258,7 +258,7 @@ export class FASTCombobox extends FormAssociatedCombobox { ) as FASTListboxOption | null; if (!captured || captured.disabled) { - this.open = !this.open; + this.open = false; return; } From ed5923bdc947f70361b331f88ebf2c5c9c8e8252 Mon Sep 17 00:00:00 2001 From: John Kreitlow <863023+radium-v@users.noreply.github.com> Date: Thu, 21 Mar 2024 11:30:26 -0700 Subject: [PATCH 4/5] Bypass clicks on combobox input to allow indicator clicks (#1) --- .../src/combobox/combobox.pw.spec.ts | 54 +++++++++++++++++++ .../fast-foundation/src/combobox/combobox.ts | 24 +++++---- 2 files changed, 67 insertions(+), 11 deletions(-) diff --git a/packages/web-components/fast-foundation/src/combobox/combobox.pw.spec.ts b/packages/web-components/fast-foundation/src/combobox/combobox.pw.spec.ts index ff488599bdd..3b890c35cd9 100644 --- a/packages/web-components/fast-foundation/src/combobox/combobox.pw.spec.ts +++ b/packages/web-components/fast-foundation/src/combobox/combobox.pw.spec.ts @@ -466,4 +466,58 @@ test.describe("Combobox", () => { await expect(element).toBeFocused(); }); + + test("should close the listbox when the indicator is clicked", async () => { + await root.evaluate(node => { + node.innerHTML = /* html */ ` + + Option 1 + Option 2 + Option 3 + + `; + }); + + const indicator = element.locator(".indicator"); + + await element.evaluate((node: FASTCombobox) => { + node.open = true; + }); + + await expect(element).toHaveAttribute("open"); + + await indicator.click(); + + await expect(element).not.toHaveAttribute("open"); + }); + + test("should not close the listbox when a disabled option is clicked", async () => { + await root.evaluate(node => { + node.innerHTML = /* html */ ` + + Option 1 + Option 2 + Option 3 + + `; + }); + + const options = element.locator("fast-option"); + + await element.evaluate((node: FASTCombobox) => { + node.open = true; + }); + + await expect(element).toHaveAttribute("open"); + + await options.nth(1).click({ + force: true, + }); + + await expect(element).toHaveAttribute("open"); + + await options.nth(2).click(); + + await expect(element).not.toHaveAttribute("open"); + }); }); diff --git a/packages/web-components/fast-foundation/src/combobox/combobox.ts b/packages/web-components/fast-foundation/src/combobox/combobox.ts index d62b253a677..33e6b677b97 100644 --- a/packages/web-components/fast-foundation/src/combobox/combobox.ts +++ b/packages/web-components/fast-foundation/src/combobox/combobox.ts @@ -248,24 +248,26 @@ export class FASTCombobox extends FormAssociatedCombobox { * @internal */ public clickHandler(e: MouseEvent): boolean | void { - if (this.disabled) { + const captured = (e.target as HTMLElement).closest( + `option,[role=option]` + ) as FASTListboxOption | null; + + if (this.disabled || captured?.disabled) { return; } if (this.open) { - const captured = (e.target as HTMLElement).closest( - `option,[role=option]` - ) as FASTListboxOption | null; - - if (!captured || captured.disabled) { - this.open = false; + if (e.composedPath()[0] === this.control) { + this.open = true; return; } - this.selectedOptions = [captured]; - this.control.value = captured.text; - this.clearSelectionRange(); - this.updateValue(true); + if (captured) { + this.selectedOptions = [captured]; + this.control.value = captured.text; + this.clearSelectionRange(); + this.updateValue(true); + } } this.open = !this.open; From 7aa143d7a609f445338e1c433c6a6ce65ae028d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zo=C3=AB=20Peterson?= Date: Wed, 10 Apr 2024 11:09:01 -0500 Subject: [PATCH 5/5] remove redundant line --- packages/web-components/fast-foundation/src/combobox/combobox.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/web-components/fast-foundation/src/combobox/combobox.ts b/packages/web-components/fast-foundation/src/combobox/combobox.ts index 33e6b677b97..eb9ae7275ac 100644 --- a/packages/web-components/fast-foundation/src/combobox/combobox.ts +++ b/packages/web-components/fast-foundation/src/combobox/combobox.ts @@ -258,7 +258,6 @@ export class FASTCombobox extends FormAssociatedCombobox { if (this.open) { if (e.composedPath()[0] === this.control) { - this.open = true; return; }