Skip to content

Commit 6c46f95

Browse files
committed
fix(aria/combobox): several small fixes (#32202)
* fix(aria/combobox): do not open on click * fix(aria/combobox): handle unselectable tree items * fix(aria/combobox): multi selection * docs(aria/combobox): multi select examples (cherry picked from commit c345614)
1 parent caa2b3b commit 6c46f95

File tree

19 files changed

+358
-185
lines changed

19 files changed

+358
-185
lines changed

src/aria/combobox/combobox.spec.ts

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,6 @@ describe('Combobox', () => {
211211
describe('Expansion', () => {
212212
beforeEach(() => setupCombobox());
213213

214-
it('should open on click', () => {
215-
focus();
216-
click(inputElement);
217-
expect(inputElement.getAttribute('aria-expanded')).toBe('true');
218-
});
219-
220214
it('should open on ArrowDown', () => {
221215
focus();
222216
keydown('ArrowDown');
@@ -545,15 +539,6 @@ describe('Combobox', () => {
545539
escape();
546540
expect(inputElement.getAttribute('aria-expanded')).toBe('false');
547541
});
548-
549-
it('should clear selection on escape when closed', () => {
550-
focus();
551-
down();
552-
enter();
553-
expect(inputElement.value).toBe('Alabama');
554-
escape();
555-
expect(inputElement.value).toBe('');
556-
});
557542
});
558543

559544
// describe('with programmatic value changes', () => {
@@ -956,12 +941,6 @@ describe('Combobox', () => {
956941
describe('Expansion', () => {
957942
beforeEach(() => setupCombobox());
958943

959-
it('should open on click', () => {
960-
focus();
961-
click(inputElement);
962-
expect(inputElement.getAttribute('aria-expanded')).toBe('true');
963-
});
964-
965944
it('should open on ArrowDown', () => {
966945
focus();
967946
keydown('ArrowDown');
@@ -1108,18 +1087,6 @@ describe('Combobox', () => {
11081087
escape();
11091088
expect(inputElement.getAttribute('aria-expanded')).toBe('false');
11101089
});
1111-
1112-
it('should clear selection on escape when closed', () => {
1113-
focus();
1114-
down();
1115-
right();
1116-
right();
1117-
enter();
1118-
expect(inputElement.value).toBe('December');
1119-
expect(inputElement.getAttribute('aria-expanded')).toBe('false');
1120-
escape();
1121-
expect(inputElement.value).toBe('');
1122-
});
11231090
});
11241091
});
11251092
});

src/aria/combobox/combobox.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export class Combobox<V> {
7171
/** Whether the combobox is focused. */
7272
readonly isFocused = signal(false);
7373

74-
/** Whether the listbox has received focus yet. */
74+
/** Whether the combobox has received focus yet. */
7575
private _hasBeenFocused = signal(false);
7676

7777
/** Whether the combobox is disabled. */

src/aria/private/behaviors/list-selection/list-selection.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export class ListSelection<T extends ListSelectionItem<V>, V> {
7171
}
7272

7373
/** Deselects the item at the current active index. */
74-
deselect(item?: T | null) {
74+
deselect(item?: ListSelectionItem<V>) {
7575
item = item ?? this.inputs.focusManager.inputs.activeItem();
7676

7777
if (item && !item.disabled() && item.selectable()) {
@@ -80,10 +80,10 @@ export class ListSelection<T extends ListSelectionItem<V>, V> {
8080
}
8181

8282
/** Toggles the item at the current active index. */
83-
toggle() {
84-
const item = this.inputs.focusManager.inputs.activeItem();
83+
toggle(item?: ListSelectionItem<V>) {
84+
item = item ?? this.inputs.focusManager.inputs.activeItem();
8585
if (item) {
86-
this.inputs.value().includes(item.value()) ? this.deselect() : this.select();
86+
this.inputs.value().includes(item.value()) ? this.deselect(item) : this.select(item);
8787
}
8888
}
8989

src/aria/private/behaviors/list/list.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@ export class List<T extends ListItem<V>, V> {
171171
}
172172

173173
/** Toggles the currently active item in the list. */
174-
toggle() {
175-
this.selectionBehavior.toggle();
174+
toggle(item?: T) {
175+
this.selectionBehavior.toggle(item);
176176
}
177177

178178
/** Toggles the currently active item in the list, deselecting all other items. */

0 commit comments

Comments
 (0)