Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 */ `
<fast-combobox>
<fast-option>Option 1</fast-option>
<fast-option>Option 2</fast-option>
<fast-option>Option 3</fast-option>
</fast-combobox>
`;
});

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 */ `
<fast-combobox>
<fast-option>Option 1</fast-option>
<fast-option disabled>Option 2</fast-option>
<fast-option>Option 3</fast-option>
</fast-combobox>
`;
});

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");
});
});
22 changes: 12 additions & 10 deletions packages/web-components/fast-foundation/src/combobox/combobox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down