From 52055b6d65986b7ca6d6d31a388b7a84607870d1 Mon Sep 17 00:00:00 2001 From: Christopher Holt <=> Date: Tue, 23 Apr 2024 21:35:51 -0700 Subject: [PATCH 1/2] close combobox if indicator is clicked and no selection is made --- .../src/combobox/combobox.spec.ts | 16 ++++++++++++++ .../fast-foundation/src/combobox/combobox.ts | 22 ++++++++++--------- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/packages/web-components/fast-foundation/src/combobox/combobox.spec.ts b/packages/web-components/fast-foundation/src/combobox/combobox.spec.ts index 1666c93ae9b..2bece35a385 100644 --- a/packages/web-components/fast-foundation/src/combobox/combobox.spec.ts +++ b/packages/web-components/fast-foundation/src/combobox/combobox.spec.ts @@ -207,6 +207,22 @@ describe("Combobox", () => { }); }); + it.only("should close the listbox if the indicator is clicked without making a selection", async () => { + const { element, connect, disconnect } = await setup(); + + await connect(); + + element.click(); // open dropdown + + expect(element.open).to.be.true; + + element.click(); + + expect(element.open).to.be.false; + + await disconnect(); + }); + it("should emit a 'change' event when the user clicks away after selecting option in dropdown", async () => { const { element, connect, disconnect } = await setup(); diff --git a/packages/web-components/fast-foundation/src/combobox/combobox.ts b/packages/web-components/fast-foundation/src/combobox/combobox.ts index d4f71f8ac81..66cef8fbe6f 100644 --- a/packages/web-components/fast-foundation/src/combobox/combobox.ts +++ b/packages/web-components/fast-foundation/src/combobox/combobox.ts @@ -274,23 +274,25 @@ export class Combobox extends FormAssociatedCombobox { * @internal */ public clickHandler(e: MouseEvent): boolean | void { - if (this.disabled) { + const captured = (e.target as HTMLElement).closest( + `option,[role=option]` + ) as ListboxOption | null; + + if (this.disabled || captured?.disabled) { return; } if (this.open) { - const captured = (e.target as HTMLElement).closest( - `option,[role=option]` - ) as ListboxOption | null; - - if (!captured || captured.disabled) { + if (e.composedPath()[0] === this.control) { 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 35a7ddb910fb6bf373ec3518e224dc3a93a5daf8 Mon Sep 17 00:00:00 2001 From: Christopher Holt <=> Date: Tue, 23 Apr 2024 21:36:29 -0700 Subject: [PATCH 2/2] Change files --- ...st-foundation-c128481d-c811-401e-9be7-71f80b0350a1.json | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 change/@microsoft-fast-foundation-c128481d-c811-401e-9be7-71f80b0350a1.json diff --git a/change/@microsoft-fast-foundation-c128481d-c811-401e-9be7-71f80b0350a1.json b/change/@microsoft-fast-foundation-c128481d-c811-401e-9be7-71f80b0350a1.json new file mode 100644 index 00000000000..26630d78aba --- /dev/null +++ b/change/@microsoft-fast-foundation-c128481d-c811-401e-9be7-71f80b0350a1.json @@ -0,0 +1,7 @@ +{ + "type": "minor", + "comment": "feat: close combobox if indicator is clicked and no selection is made", + "packageName": "@microsoft/fast-foundation", + "email": "=", + "dependentChangeType": "patch" +}