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..20547c3ba93
--- /dev/null
+++ b/change/@microsoft-fast-foundation-47afe4a7-9451-4c4c-beba-70305e6b600e.json
@@ -0,0 +1,7 @@
+{
+ "type": "prerelease",
+ "comment": "fix(combobox): close the combobox even if there's no selection",
+ "packageName": "@microsoft/fast-foundation",
+ "email": "zoepeterson@microsoft.com",
+ "dependentChangeType": "prerelease"
+}
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 dd037883a64..eb9ae7275ac 100644
--- a/packages/web-components/fast-foundation/src/combobox/combobox.ts
+++ b/packages/web-components/fast-foundation/src/combobox/combobox.ts
@@ -248,23 +248,25 @@ 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) {
+ 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;