Skip to content

Commit f157c74

Browse files
authored
fix(aria/combobox): use click instead of pointerup (angular#32324)
* fix(aria/combobox): use click instead of pointerup * fixup! fix(aria/combobox): use click instead of pointerup * fix(aria/combobox): readonly close behavior * fixup! fix(aria/combobox): readonly close behavior
1 parent a184397 commit f157c74

File tree

4 files changed

+27
-21
lines changed

4 files changed

+27
-21
lines changed

src/aria/combobox/combobox.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ describe('Combobox', () => {
3333

3434
const click = (element: HTMLElement, eventInit?: PointerEventInit) => {
3535
focus();
36-
element.dispatchEvent(new PointerEvent('pointerup', {bubbles: true, ...eventInit}));
36+
element.dispatchEvent(new PointerEvent('click', {bubbles: true, ...eventInit}));
3737
fixture.detectChanges();
3838
};
3939

@@ -584,7 +584,7 @@ describe('Combobox', () => {
584584

585585
const click = (element: HTMLElement, eventInit?: PointerEventInit) => {
586586
focus();
587-
element.dispatchEvent(new PointerEvent('pointerup', {bubbles: true, ...eventInit}));
587+
element.dispatchEvent(new PointerEvent('click', {bubbles: true, ...eventInit}));
588588
fixture.detectChanges();
589589
};
590590

src/aria/combobox/combobox.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ import {toSignal} from '@angular/core/rxjs-interop';
7474
'[attr.data-expanded]': 'expanded()',
7575
'(input)': '_pattern.onInput($event)',
7676
'(keydown)': '_pattern.onKeydown($event)',
77-
'(pointerup)': '_pattern.onPointerup($event)',
77+
'(click)': '_pattern.onClick($event)',
7878
'(focusin)': '_pattern.onFocusIn()',
7979
'(focusout)': '_pattern.onFocusOut($event)',
8080
},

src/aria/private/combobox/combobox.spec.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ describe('Combobox with Listbox Pattern', () => {
352352
it('should not expand when disabled', () => {
353353
const {combobox, inputEl} = getPatterns({disabled: true});
354354
expect(combobox.expanded()).toBe(false);
355-
combobox.onPointerup(clickInput(inputEl));
355+
combobox.onClick(clickInput(inputEl));
356356
expect(combobox.expanded()).toBe(false);
357357
});
358358
});
@@ -376,7 +376,7 @@ describe('Combobox with Listbox Pattern', () => {
376376
});
377377

378378
it('should select and commit on click', () => {
379-
combobox.onPointerup(clickOption(listbox.inputs.items(), 0));
379+
combobox.onClick(clickOption(listbox.inputs.items(), 0));
380380
expect(listbox.getSelectedItems()[0]).toBe(listbox.inputs.items()[0]);
381381
expect(listbox.inputs.values()).toEqual(['Apple']);
382382
expect(inputEl.value).toBe('Apple');
@@ -437,7 +437,7 @@ describe('Combobox with Listbox Pattern', () => {
437437
});
438438

439439
it('should select and commit on click', () => {
440-
combobox.onPointerup(clickOption(listbox.inputs.items(), 3));
440+
combobox.onClick(clickOption(listbox.inputs.items(), 3));
441441
expect(listbox.getSelectedItems()[0]).toBe(listbox.inputs.items()[3]);
442442
expect(listbox.inputs.values()).toEqual(['Blackberry']);
443443
expect(inputEl.value).toBe('Blackberry');
@@ -498,7 +498,7 @@ describe('Combobox with Listbox Pattern', () => {
498498
});
499499

500500
it('should select and commit on click', () => {
501-
combobox.onPointerup(clickOption(listbox.inputs.items(), 3));
501+
combobox.onClick(clickOption(listbox.inputs.items(), 3));
502502
expect(listbox.getSelectedItems()[0]).toBe(listbox.inputs.items()[3]);
503503
expect(listbox.inputs.values()).toEqual(['Blackberry']);
504504
expect(inputEl.value).toBe('Blackberry');
@@ -585,7 +585,7 @@ describe('Combobox with Listbox Pattern', () => {
585585
describe('with single-select', () => {
586586
it('should select and close on selection', () => {
587587
const {combobox, listbox, inputEl} = getPatterns({readonly: true});
588-
combobox.onPointerup(clickOption(listbox.inputs.items(), 2));
588+
combobox.onClick(clickOption(listbox.inputs.items(), 2));
589589
expect(listbox.getSelectedItems()[0]).toBe(listbox.inputs.items()[2]);
590590
expect(listbox.inputs.values()).toEqual(['Banana']);
591591
expect(inputEl.value).toBe('Banana');
@@ -606,8 +606,8 @@ describe('Combobox with Listbox Pattern', () => {
606606
const {combobox, listbox, inputEl} = getPatterns({readonly: true});
607607
(listbox.inputs.multi as WritableSignal<boolean>).set(true);
608608

609-
combobox.onPointerup(clickOption(listbox.inputs.items(), 1));
610-
combobox.onPointerup(clickOption(listbox.inputs.items(), 2));
609+
combobox.onClick(clickOption(listbox.inputs.items(), 1));
610+
combobox.onClick(clickOption(listbox.inputs.items(), 2));
611611

612612
expect(listbox.inputs.values()).toEqual(['Apricot', 'Banana']);
613613
expect(inputEl.value).toBe('Apricot, Banana');
@@ -741,7 +741,7 @@ describe('Combobox with Tree Pattern', () => {
741741
});
742742

743743
it('should select and commit on click', () => {
744-
combobox.onPointerup(clickTreeItem(tree.inputs.allItems(), 0));
744+
combobox.onClick(clickTreeItem(tree.inputs.allItems(), 0));
745745
expect(tree.inputs.values()).toEqual(['Fruit']);
746746
expect(inputEl.value).toBe('Fruit');
747747
});
@@ -755,7 +755,7 @@ describe('Combobox with Tree Pattern', () => {
755755
});
756756

757757
it('should select on focusout if the input text exactly matches an item', () => {
758-
combobox.onPointerup(clickInput(inputEl));
758+
combobox.onClick(clickInput(inputEl));
759759
type('Apple');
760760
combobox.onFocusOut(new FocusEvent('focusout'));
761761
expect(tree.inputs.values()).toEqual(['Apple']);
@@ -801,7 +801,7 @@ describe('Combobox with Tree Pattern', () => {
801801
});
802802

803803
it('should select and commit on click', () => {
804-
combobox.onPointerup(clickTreeItem(tree.inputs.allItems(), 2));
804+
combobox.onClick(clickTreeItem(tree.inputs.allItems(), 2));
805805
expect(tree.getSelectedItems()[0]).toBe(tree.inputs.allItems()[2]);
806806
expect(tree.inputs.values()).toEqual(['Banana']);
807807
expect(inputEl.value).toBe('Banana');
@@ -858,7 +858,7 @@ describe('Combobox with Tree Pattern', () => {
858858
});
859859

860860
it('should select and commit on click', () => {
861-
combobox.onPointerup(clickTreeItem(tree.inputs.allItems(), 2));
861+
combobox.onClick(clickTreeItem(tree.inputs.allItems(), 2));
862862
expect(tree.getSelectedItems()[0]).toBe(tree.inputs.allItems()[2]);
863863
expect(tree.inputs.values()).toEqual(['Banana']);
864864
expect(inputEl.value).toBe('Banana');
@@ -928,9 +928,9 @@ describe('Combobox with Tree Pattern', () => {
928928
describe('Readonly mode', () => {
929929
it('should select and close on selection', () => {
930930
const {combobox, tree, inputEl} = getPatterns({readonly: true});
931-
combobox.onPointerup(clickInput(inputEl));
931+
combobox.onClick(clickInput(inputEl));
932932
expect(combobox.expanded()).toBe(true);
933-
combobox.onPointerup(clickTreeItem(tree.inputs.allItems(), 0));
933+
combobox.onClick(clickTreeItem(tree.inputs.allItems(), 0));
934934
expect(tree.inputs.values()).toEqual(['Fruit']);
935935
expect(inputEl.value).toBe('Fruit');
936936
expect(combobox.expanded()).toBe(false);

src/aria/private/combobox/combobox.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,8 @@ export class ComboboxPattern<T extends ListItem<V>, V> {
282282
return manager;
283283
});
284284

285-
/** The pointerup event manager for the combobox. */
286-
pointerup = computed(() =>
285+
/** The click event manager for the combobox. */
286+
click = computed(() =>
287287
new PointerEventManager().on(e => {
288288
if (e.target === this.inputs.inputEl()) {
289289
if (this.readonly()) {
@@ -325,10 +325,10 @@ export class ComboboxPattern<T extends ListItem<V>, V> {
325325
}
326326
}
327327

328-
/** Handles pointerup events for the combobox. */
329-
onPointerup(event: PointerEvent) {
328+
/** Handles click events for the combobox. */
329+
onClick(event: MouseEvent) {
330330
if (!this.inputs.disabled()) {
331-
this.pointerup().handle(event);
331+
this.click().handle(event as PointerEvent);
332332
}
333333
}
334334

@@ -510,6 +510,12 @@ export class ComboboxPattern<T extends ListItem<V>, V> {
510510
return;
511511
}
512512

513+
if (this.readonly()) {
514+
this.expanded.set(false);
515+
popupControls?.unfocus();
516+
return;
517+
}
518+
513519
if (!opts?.reset) {
514520
if (this.inputs.filterMode() === 'manual') {
515521
if (

0 commit comments

Comments
 (0)