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
4 changes: 2 additions & 2 deletions src/aria/combobox/combobox.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('Combobox', () => {

const click = (element: HTMLElement, eventInit?: PointerEventInit) => {
focus();
element.dispatchEvent(new PointerEvent('pointerup', {bubbles: true, ...eventInit}));
element.dispatchEvent(new PointerEvent('click', {bubbles: true, ...eventInit}));
fixture.detectChanges();
};

Expand Down Expand Up @@ -584,7 +584,7 @@ describe('Combobox', () => {

const click = (element: HTMLElement, eventInit?: PointerEventInit) => {
focus();
element.dispatchEvent(new PointerEvent('pointerup', {bubbles: true, ...eventInit}));
element.dispatchEvent(new PointerEvent('click', {bubbles: true, ...eventInit}));
fixture.detectChanges();
};

Expand Down
2 changes: 1 addition & 1 deletion src/aria/combobox/combobox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ import {toSignal} from '@angular/core/rxjs-interop';
'[attr.data-expanded]': 'expanded()',
'(input)': '_pattern.onInput($event)',
'(keydown)': '_pattern.onKeydown($event)',
'(pointerup)': '_pattern.onPointerup($event)',
'(click)': '_pattern.onClick($event)',
'(focusin)': '_pattern.onFocusIn()',
'(focusout)': '_pattern.onFocusOut($event)',
},
Expand Down
26 changes: 13 additions & 13 deletions src/aria/private/combobox/combobox.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ describe('Combobox with Listbox Pattern', () => {
it('should not expand when disabled', () => {
const {combobox, inputEl} = getPatterns({disabled: true});
expect(combobox.expanded()).toBe(false);
combobox.onPointerup(clickInput(inputEl));
combobox.onClick(clickInput(inputEl));
expect(combobox.expanded()).toBe(false);
});
});
Expand All @@ -376,7 +376,7 @@ describe('Combobox with Listbox Pattern', () => {
});

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

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

it('should select and commit on click', () => {
combobox.onPointerup(clickOption(listbox.inputs.items(), 3));
combobox.onClick(clickOption(listbox.inputs.items(), 3));
expect(listbox.getSelectedItems()[0]).toBe(listbox.inputs.items()[3]);
expect(listbox.inputs.values()).toEqual(['Blackberry']);
expect(inputEl.value).toBe('Blackberry');
Expand Down Expand Up @@ -585,7 +585,7 @@ describe('Combobox with Listbox Pattern', () => {
describe('with single-select', () => {
it('should select and close on selection', () => {
const {combobox, listbox, inputEl} = getPatterns({readonly: true});
combobox.onPointerup(clickOption(listbox.inputs.items(), 2));
combobox.onClick(clickOption(listbox.inputs.items(), 2));
expect(listbox.getSelectedItems()[0]).toBe(listbox.inputs.items()[2]);
expect(listbox.inputs.values()).toEqual(['Banana']);
expect(inputEl.value).toBe('Banana');
Expand All @@ -606,8 +606,8 @@ describe('Combobox with Listbox Pattern', () => {
const {combobox, listbox, inputEl} = getPatterns({readonly: true});
(listbox.inputs.multi as WritableSignal<boolean>).set(true);

combobox.onPointerup(clickOption(listbox.inputs.items(), 1));
combobox.onPointerup(clickOption(listbox.inputs.items(), 2));
combobox.onClick(clickOption(listbox.inputs.items(), 1));
combobox.onClick(clickOption(listbox.inputs.items(), 2));

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

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

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

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

it('should select and commit on click', () => {
combobox.onPointerup(clickTreeItem(tree.inputs.allItems(), 2));
combobox.onClick(clickTreeItem(tree.inputs.allItems(), 2));
expect(tree.getSelectedItems()[0]).toBe(tree.inputs.allItems()[2]);
expect(tree.inputs.values()).toEqual(['Banana']);
expect(inputEl.value).toBe('Banana');
Expand Down Expand Up @@ -928,9 +928,9 @@ describe('Combobox with Tree Pattern', () => {
describe('Readonly mode', () => {
it('should select and close on selection', () => {
const {combobox, tree, inputEl} = getPatterns({readonly: true});
combobox.onPointerup(clickInput(inputEl));
combobox.onClick(clickInput(inputEl));
expect(combobox.expanded()).toBe(true);
combobox.onPointerup(clickTreeItem(tree.inputs.allItems(), 0));
combobox.onClick(clickTreeItem(tree.inputs.allItems(), 0));
expect(tree.inputs.values()).toEqual(['Fruit']);
expect(inputEl.value).toBe('Fruit');
expect(combobox.expanded()).toBe(false);
Expand Down
16 changes: 11 additions & 5 deletions src/aria/private/combobox/combobox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,8 @@ export class ComboboxPattern<T extends ListItem<V>, V> {
return manager;
});

/** The pointerup event manager for the combobox. */
pointerup = computed(() =>
/** The click event manager for the combobox. */
click = computed(() =>
new PointerEventManager().on(e => {
if (e.target === this.inputs.inputEl()) {
if (this.readonly()) {
Expand Down Expand Up @@ -325,10 +325,10 @@ export class ComboboxPattern<T extends ListItem<V>, V> {
}
}

/** Handles pointerup events for the combobox. */
onPointerup(event: PointerEvent) {
/** Handles click events for the combobox. */
onClick(event: MouseEvent) {
if (!this.inputs.disabled()) {
this.pointerup().handle(event);
this.click().handle(event as PointerEvent);
}
}

Expand Down Expand Up @@ -510,6 +510,12 @@ export class ComboboxPattern<T extends ListItem<V>, V> {
return;
}

if (this.readonly()) {
this.expanded.set(false);
popupControls?.unfocus();
return;
}

if (!opts?.reset) {
if (this.inputs.filterMode() === 'manual') {
if (
Expand Down
Loading