Skip to content

Commit 9c6dbb6

Browse files
authored
[archives/fast-element-1] fix(cherry-pick): close combobox even if no selection (#6942)
* close combobox if indicator is clicked and no selection is made * Change files --------- Co-authored-by: Christopher Holt <=>
1 parent 2968428 commit 9c6dbb6

File tree

3 files changed

+35
-10
lines changed

3 files changed

+35
-10
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "minor",
3+
"comment": "feat: close combobox if indicator is clicked and no selection is made",
4+
"packageName": "@microsoft/fast-foundation",
5+
"email": "=",
6+
"dependentChangeType": "patch"
7+
}

packages/web-components/fast-foundation/src/combobox/combobox.spec.ts

+16
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,22 @@ describe("Combobox", () => {
207207
});
208208
});
209209

210+
it.only("should close the listbox if the indicator is clicked without making a selection", async () => {
211+
const { element, connect, disconnect } = await setup();
212+
213+
await connect();
214+
215+
element.click(); // open dropdown
216+
217+
expect(element.open).to.be.true;
218+
219+
element.click();
220+
221+
expect(element.open).to.be.false;
222+
223+
await disconnect();
224+
});
225+
210226
it("should emit a 'change' event when the user clicks away after selecting option in dropdown", async () => {
211227
const { element, connect, disconnect } = await setup();
212228

packages/web-components/fast-foundation/src/combobox/combobox.ts

+12-10
Original file line numberDiff line numberDiff line change
@@ -274,23 +274,25 @@ export class Combobox extends FormAssociatedCombobox {
274274
* @internal
275275
*/
276276
public clickHandler(e: MouseEvent): boolean | void {
277-
if (this.disabled) {
277+
const captured = (e.target as HTMLElement).closest(
278+
`option,[role=option]`
279+
) as ListboxOption | null;
280+
281+
if (this.disabled || captured?.disabled) {
278282
return;
279283
}
280284

281285
if (this.open) {
282-
const captured = (e.target as HTMLElement).closest(
283-
`option,[role=option]`
284-
) as ListboxOption | null;
285-
286-
if (!captured || captured.disabled) {
286+
if (e.composedPath()[0] === this.control) {
287287
return;
288288
}
289289

290-
this.selectedOptions = [captured];
291-
this.control.value = captured.text;
292-
this.clearSelectionRange();
293-
this.updateValue(true);
290+
if (captured) {
291+
this.selectedOptions = [captured];
292+
this.control.value = captured.text;
293+
this.clearSelectionRange();
294+
this.updateValue(true);
295+
}
294296
}
295297

296298
this.open = !this.open;

0 commit comments

Comments
 (0)