Skip to content

Commit 1d7888d

Browse files
committed
fix(aria/combobox): highlighting edge cases
1 parent e76e267 commit 1d7888d

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

src/aria/combobox/combobox.spec.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,28 @@ describe('Combobox', () => {
424424
expect(inputElement.selectionEnd).toBe(7);
425425
}));
426426

427+
it('should not insert a completion string on backspace', fakeAsync(() => {
428+
focus();
429+
input('New');
430+
tick();
431+
432+
expect(inputElement.value).toBe('New Hampshire');
433+
expect(inputElement.selectionStart).toBe(3);
434+
expect(inputElement.selectionEnd).toBe(13);
435+
}));
436+
437+
it('should insert a completion string even if the items are not changed', fakeAsync(() => {
438+
focus();
439+
input('New');
440+
tick();
441+
442+
input('New ');
443+
tick();
444+
expect(inputElement.value).toBe('New Hampshire');
445+
expect(inputElement.selectionStart).toBe(4);
446+
expect(inputElement.selectionEnd).toBe(13);
447+
}));
448+
427449
it('should commit the selected option on focusout', () => {
428450
focus();
429451
input('Cali');

src/aria/combobox/combobox.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ export class ComboboxInput {
139139

140140
/** Focuses & selects the first item in the combobox if the user changes the input value. */
141141
afterRenderEffect(() => {
142-
this.combobox.popup()?.controls()?.items();
142+
this.value();
143143
untracked(() => this.combobox.pattern.onFilter());
144144
});
145145
}

src/aria/ui-patterns/combobox/combobox.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,10 @@ export class ComboboxPattern<T extends ListItem<V>, V> {
239239
this.inputs.popupControls()?.clearSelection();
240240
}
241241
}
242+
243+
if (this.inputs.filterMode() === 'highlight' && !this.isDeleting) {
244+
this.highlight();
245+
}
242246
}
243247

244248
/** Handles focus in events for the combobox. */
@@ -335,10 +339,14 @@ export class ComboboxPattern<T extends ListItem<V>, V> {
335339
const inputEl = this.inputs.inputEl();
336340
const item = this.inputs.popupControls()?.getSelectedItem();
337341

342+
console.log('Highlighting item called with:', item?.searchTerm());
343+
338344
if (!inputEl || !item) {
339345
return;
340346
}
341347

348+
console.log('Highlighting item:', item.searchTerm());
349+
342350
const isHighlightable = item
343351
.searchTerm()
344352
.toLowerCase()

0 commit comments

Comments
 (0)