From 505a2e0b67b072d597055734c583c56c66d92dab Mon Sep 17 00:00:00 2001 From: onlyexeption Date: Thu, 19 Nov 2026 14:12:01 +0200 Subject: [PATCH 1/3] fix(combo): show flat button focus on default add item --- CHANGELOG.md | 2 + .../src/combo/combo-add-item.component.ts | 31 ++++++- .../combo/src/combo/combo.component.html | 16 ++-- .../combo/src/combo/combo.component.spec.ts | 83 ++++++++++++++++++- .../simple-combo/simple-combo.component.html | 14 ++-- .../simple-combo.component.spec.ts | 18 ++++ src/app/combo/combo.sample.html | 2 + src/styles/_variables.scss | 8 +- 8 files changed, 153 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ec9fc3f52c4..de8d33007af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -104,6 +104,8 @@ All notable changes for each version of this project will be documented in this - A slide activated through its `active` property now animates in the direction of its position, or in its own `direction` when one is set. - `IgxCircularProgressBarComponent`, `IgxLinearProgressBarComponent` - In Safari, the initial animation no longer overshoots the value and then crawls back to it. The initial fill and later value changes now use the same transition, so a value that changes while the bar is still animating goes straight to the new value in every browser. The Bootstrap circular bar now also animates its initial fill in RTL. +- `IgxComboComponent`, `IgxSimpleComboComponent` + - The default "Add item" button no longer takes the background or outline of a focused list item when it is reached with the keyboard. It shows the focus state of a flat button instead. - `IgxCsvExporterService` - Exporting a grid with summaries no longer adds an extra `GRID_LEVEL_COL` column with the nesting level of each record. Only the grid's columns are exported, as with the Excel and PDF exporters. - `IgxDatePickerComponent` diff --git a/projects/igniteui-angular/combo/src/combo/combo-add-item.component.ts b/projects/igniteui-angular/combo/src/combo/combo-add-item.component.ts index 9cc1aded856..a1fddce7cc5 100644 --- a/projects/igniteui-angular/combo/src/combo/combo-add-item.component.ts +++ b/projects/igniteui-angular/combo/src/combo/combo-add-item.component.ts @@ -1,5 +1,5 @@ import { IgxComboItemComponent } from './combo-item.component'; -import { Component, HostBinding, ChangeDetectionStrategy } from '@angular/core'; +import { Component, HostBinding, ChangeDetectionStrategy, Input, booleanAttribute } from '@angular/core'; /** * @hidden @@ -11,11 +11,40 @@ import { Component, HostBinding, ChangeDetectionStrategy } from '@angular/core'; providers: [{ provide: IgxComboItemComponent, useExisting: IgxComboAddItemComponent }], }) export class IgxComboAddItemComponent extends IgxComboItemComponent { + /** + * @hidden @internal + * Set when the add item renders a custom `igxComboAddItem` template instead of the default button. + */ + @Input({ transform: booleanAttribute }) + public customTemplate = false; + @HostBinding('class.igx-drop-down__item') public get isDropDownItem(): boolean { return false; } + /** + * @hidden @internal + * Whether the add item is the active entry of the list. The focus stays on the list, + * so the default button shows this state as its own focus state. + */ + public get active(): boolean { + return super.focused; + } + + /** + * @hidden @internal + * The default add item is a button that shows its own focus state, so it does not take + * the focus style of the list items. A custom template keeps that style. + */ + public override get focused(): boolean { + return this.customTemplate && super.focused; + } + + public override set focused(value: boolean) { + super.focused = value; + } + public override get selected(): boolean { return false; } diff --git a/projects/igniteui-angular/combo/src/combo/combo.component.html b/projects/igniteui-angular/combo/src/combo/combo.component.html index a4f06cd1db7..5703bce2793 100644 --- a/projects/igniteui-angular/combo/src/combo/combo.component.html +++ b/projects/igniteui-angular/combo/src/combo/combo.component.html @@ -115,11 +115,16 @@ } @if (isAddButtonVisible()) { - - - + [attr.aria-label]="resourceStrings.igx_combo_addCustomValues_placeholder" [index]="itemWindow.totalCount" + [customTemplate]="!!addItemTemplate"> + @if (addItemTemplate) { + + } @else { + + + } } @@ -137,9 +142,6 @@ {{resourceStrings.igx_combo_empty_message}} - - - {{ item[key] }} diff --git a/projects/igniteui-angular/combo/src/combo/combo.component.spec.ts b/projects/igniteui-angular/combo/src/combo/combo.component.spec.ts index a52c99840cd..aeb7965e813 100644 --- a/projects/igniteui-angular/combo/src/combo/combo.component.spec.ts +++ b/projects/igniteui-angular/combo/src/combo/combo.component.spec.ts @@ -22,7 +22,7 @@ import { IComboFilteringOptions, IGX_COMBO_COMPONENT } from './combo.common'; import { IComboItemAdditionEvent, IComboSearchInputEventArgs, IComboSelectionChangedEventArgs, IComboSelectionChangingEventArgs, IgxComboComponent } from './combo.component'; -import { IgxComboFooterDirective, IgxComboHeaderDirective, IgxComboItemDirective } from './combo.directives'; +import { IgxComboAddItemDirective, IgxComboFooterDirective, IgxComboHeaderDirective, IgxComboItemDirective } from './combo.directives'; import { IgxComboFilteringPipe, comboIgnoreDiacriticsFilter } from './combo.pipes'; import { IgxDropDownItemBaseDirective } from '../../../drop-down/src/drop-down/drop-down-item.base'; import { UIInteractions, wait } from 'igniteui-angular/test-utils/ui-interactions.spec'; @@ -43,6 +43,7 @@ const CSS_CLASS_CLEARBUTTON = 'igx-combo__clear-button'; const CSS_CLASS_ADDBUTTON = 'igx-combo__add-item'; const CSS_CLASS_SELECTED = 'igx-drop-down__item--selected'; const CSS_CLASS_FOCUSED = 'igx-drop-down__item--focused'; +const CSS_CLASS_BUTTON_FOCUSED = 'igx-button--focused'; const CSS_CLASS_HEADERITEM = 'igx-drop-down__header'; const CSS_CLASS_SCROLLBAR_VERTICAL = 'igx-virtual-scroll'; const CSS_CLASS_INPUTGROUP = 'igx-input-group'; @@ -1117,6 +1118,7 @@ describe('igxCombo', () => { IgxComboFormComponent, IgxComboInTemplatedFormComponent, IgxComboWithPrefixComponent, + IgxComboCustomAddItemComponent, ] }).compileComponents(); }); @@ -2876,6 +2878,63 @@ describe('igxCombo', () => { UIInteractions.triggerEventHandlerKeyDown('ArrowDown', dropdownContent); fixture.detectChanges(); expect(dropdown.focusedItem instanceof IgxComboAddItemComponent).toBe(true); + + const addItem: HTMLElement = fixture.debugElement.query(By.directive(IgxComboAddItemComponent)).nativeElement; + expect(addItem.classList.contains(CSS_CLASS_FOCUSED)).toBe(false); + expect(addItem.querySelector('button').classList.contains(CSS_CLASS_BUTTON_FOCUSED)).toBe(true); + }); + it('should show the focus state of the default add item button instead of the item focus style', async () => { + combo.allowCustomValues = true; + combo.toggle(); + await wait(); + fixture.detectChanges(); + + const searchInput = fixture.debugElement.query(By.css(CSS_CLASS_SEARCHINPUT)); + UIInteractions.triggerInputEvent(searchInput, 'My New State'); + await wait(); + fixture.detectChanges(); + expect(combo.filteredData.length).toEqual(0); + + const addItem: HTMLElement = fixture.debugElement.query(By.directive(IgxComboAddItemComponent)).nativeElement; + const button = addItem.querySelector('button'); + expect(button.classList.contains(CSS_CLASS_BUTTON_FOCUSED)).toBe(false); + + combo.handleKeyUp(UIInteractions.getKeyboardEvent('keyup', 'ArrowDown')); + fixture.detectChanges(); + expect(dropdown.focusedItem instanceof IgxComboAddItemComponent).toBe(true); + expect(addItem.classList.contains(CSS_CLASS_FOCUSED)).toBe(false); + expect(button.classList.contains(CSS_CLASS_BUTTON_FOCUSED)).toBe(true); + + // the add item is the only entry, so ArrowUp goes back to the search input + const dropdownContent = fixture.debugElement.query(By.css(`.${CSS_CLASS_CONTENT}`)); + UIInteractions.triggerEventHandlerKeyDown('ArrowUp', dropdownContent); + fixture.detectChanges(); + expect(dropdown.focusedItem).toBeNull(); + expect(button.classList.contains(CSS_CLASS_BUTTON_FOCUSED)).toBe(false); + }); + it('should keep the item focus style on the add item when it has a custom template', async () => { + fixture = TestBed.createComponent(IgxComboCustomAddItemComponent); + fixture.detectChanges(); + combo = fixture.componentInstance.combo; + dropdown = combo.dropdown; + + combo.toggle(); + await wait(); + fixture.detectChanges(); + + const searchInput = fixture.debugElement.query(By.css(CSS_CLASS_SEARCHINPUT)); + UIInteractions.triggerInputEvent(searchInput, 'Not existing'); + await wait(); + fixture.detectChanges(); + + const addItem: HTMLElement = fixture.debugElement.query(By.directive(IgxComboAddItemComponent)).nativeElement; + expect(addItem.querySelector('.custom-add-item')).not.toBeNull(); + expect(addItem.classList.contains(CSS_CLASS_FOCUSED)).toBe(false); + + combo.handleKeyUp(UIInteractions.getKeyboardEvent('keyup', 'ArrowDown')); + fixture.detectChanges(); + expect(dropdown.focusedItem instanceof IgxComboAddItemComponent).toBe(true); + expect(addItem.classList.contains(CSS_CLASS_FOCUSED)).toBe(true); }); it('should not change the selection when selectItem is called without an item', () => { const selectSpy = vi.spyOn(combo, 'select'); @@ -4178,8 +4237,8 @@ describe('igxCombo', () => { expect(combo.collapsed).toBeFalsy(); expect(combo.displayValue).toEqual(''); - const focusedItem = fixture.debugElement.query(By.css(`.${CSS_CLASS_FOCUSED}`)); - focusedItem.triggerEventHandler('click', UIInteractions.getMouseEvent('click')); + const addItem = fixture.debugElement.query(By.css(`.${CSS_CLASS_ADDBUTTON}`)); + addItem.triggerEventHandler('click', UIInteractions.getMouseEvent('click')); fixture.detectChanges(); expect(combo.collapsed).toBeFalsy(); expect(combo.displayValue).toEqual('My New Custom Item'); @@ -5647,6 +5706,24 @@ class IgxComboWithPrefixComponent { public items = ['One', 'Two', 'Three']; } +@Component({ + template: ` + + + Add a custom item + + + `, + changeDetection: ChangeDetectionStrategy.Eager, + imports: [IgxComboComponent, IgxComboAddItemDirective] +}) +class IgxComboCustomAddItemComponent { + @ViewChild('combo', { read: IgxComboComponent, static: true }) + public combo: IgxComboComponent; + + public items = ['One', 'Two', 'Three']; +} + @Component({ template: ` diff --git a/projects/igniteui-angular/simple-combo/src/simple-combo/simple-combo.component.html b/projects/igniteui-angular/simple-combo/src/simple-combo/simple-combo.component.html index a9770338b8e..be92298aa8d 100644 --- a/projects/igniteui-angular/simple-combo/src/simple-combo/simple-combo.component.html +++ b/projects/igniteui-angular/simple-combo/src/simple-combo/simple-combo.component.html @@ -113,9 +113,14 @@ @if (isAddButtonVisible()) { - - + [attr.aria-label]="resourceStrings.igx_combo_addCustomValues_placeholder" [index]="itemWindow.totalCount" + [customTemplate]="!!addItemTemplate"> + @if (addItemTemplate) { + + } @else { + + + } } @@ -133,9 +138,6 @@ {{resourceStrings.igx_combo_empty_message}} - - - {{ item[key] }} diff --git a/projects/igniteui-angular/simple-combo/src/simple-combo/simple-combo.component.spec.ts b/projects/igniteui-angular/simple-combo/src/simple-combo/simple-combo.component.spec.ts index fe6aec14711..63c5938fed4 100644 --- a/projects/igniteui-angular/simple-combo/src/simple-combo/simple-combo.component.spec.ts +++ b/projects/igniteui-angular/simple-combo/src/simple-combo/simple-combo.component.spec.ts @@ -1538,6 +1538,24 @@ describe('IgxSimpleCombo', () => { expect(document.activeElement).toEqual(addItemButton.nativeElement); }); + it('should show the focus state of the default AddItem button instead of the item focus style', async () => { + fixture.componentInstance.allowCustomValues = true; + fixture.detectChanges(); + combo.open(); + fixture.detectChanges(); + UIInteractions.setInputElementValue(input.nativeElement, 'MassachusettsL'); + fixture.detectChanges(); + expect(combo.filteredData.length).toEqual(0); + + combo.handleKeyUp(UIInteractions.getKeyboardEvent('keyup', 'ArrowDown')); + fixture.detectChanges(); + expect(combo.dropdown.focusedItem).toBe(combo.addItem); + + const addItem: HTMLElement = fixture.debugElement.query(By.css(`.${CSS_CLASS_ADDBUTTON}`)).nativeElement; + expect(addItem.classList.contains(CSS_CLASS_FOCUSED)).toBe(false); + expect(addItem.querySelector('button').classList.contains('igx-button--focused')).toBe(true); + }); + it('should close when an item is clicked on', () => { vi.spyOn(combo, 'close'); combo.open(); diff --git a/src/app/combo/combo.sample.html b/src/app/combo/combo.sample.html index a917c9399cb..ef93e2907e1 100644 --- a/src/app/combo/combo.sample.html +++ b/src/app/combo/combo.sample.html @@ -196,9 +196,11 @@

Template items

Group header for {{display[key]}}
} + home Please select the states you've visited diff --git a/src/styles/_variables.scss b/src/styles/_variables.scss index 0c47587a4b1..976329f1cb4 100644 --- a/src/styles/_variables.scss +++ b/src/styles/_variables.scss @@ -1,10 +1,10 @@ @use 'sass:map'; @use '../../projects/igniteui-angular/core/src/core/styles/themes' as *; -$palette: $light-material-palette; -$schema: $light-material-schema; -$typeface: $material-typeface; -$type-scale: $material-type-scale; +$palette: $dark-bootstrap-palette; +$schema: $dark-bootstrap-schema; +$typeface: $bootstrap-typeface; +$type-scale: $bootstrap-type-scale; $variant: map.get($schema, '_meta', 'variant'); $background-color: var(--ig-gray-900-contrast); $foreground-color: var(--ig-gray-900); From a44de03b5d668c1975ab9c195145cd1be1fc3238 Mon Sep 17 00:00:00 2001 From: onlyexeption Date: Thu, 19 Nov 2026 14:46:46 +0200 Subject: [PATCH 2/3] fix(combo): keep native focus ring on add item button --- .../combo/src/combo/combo.component.html | 5 ++-- .../combo/src/combo/combo.component.spec.ts | 26 +++++++++++++++++++ .../simple-combo/simple-combo.component.html | 5 ++-- src/app/combo/combo.sample.html | 2 -- src/styles/_variables.scss | 8 +++--- 5 files changed, 36 insertions(+), 10 deletions(-) diff --git a/projects/igniteui-angular/combo/src/combo/combo.component.html b/projects/igniteui-angular/combo/src/combo/combo.component.html index 5703bce2793..475f04f031f 100644 --- a/projects/igniteui-angular/combo/src/combo/combo.component.html +++ b/projects/igniteui-angular/combo/src/combo/combo.component.html @@ -122,8 +122,9 @@ @if (addItemTemplate) { } @else { - - + + } } diff --git a/projects/igniteui-angular/combo/src/combo/combo.component.spec.ts b/projects/igniteui-angular/combo/src/combo/combo.component.spec.ts index aeb7965e813..89f070ef100 100644 --- a/projects/igniteui-angular/combo/src/combo/combo.component.spec.ts +++ b/projects/igniteui-angular/combo/src/combo/combo.component.spec.ts @@ -2912,6 +2912,32 @@ describe('igxCombo', () => { expect(dropdown.focusedItem).toBeNull(); expect(button.classList.contains(CSS_CLASS_BUTTON_FOCUSED)).toBe(false); }); + it('should keep the keyboard focus state of the default add item button while another item is active', async () => { + combo.allowCustomValues = true; + combo.toggle(); + await wait(); + fixture.detectChanges(); + + const searchInput = fixture.debugElement.query(By.css(CSS_CLASS_SEARCHINPUT)); + // matches a single item, so the list is a group header and 'Ohio' + UIInteractions.triggerInputEvent(searchInput, 'Ohi'); + await wait(); + fixture.detectChanges(); + + const dropdownContent = fixture.debugElement.query(By.css(`.${CSS_CLASS_CONTENT}`)); + UIInteractions.triggerEventHandlerKeyDown('ArrowDown', dropdownContent); + fixture.detectChanges(); + expect(dropdown.focusedItem.itemID).toEqual('Ohio'); + + // e.g. Tab reaches the button while a consumer keeps the drop-down open by canceling `closing` + const button: HTMLElement = fixture.debugElement.query(By.directive(IgxComboAddItemComponent)) + .nativeElement.querySelector('button'); + button.focus(); + button.dispatchEvent(new KeyboardEvent('keyup', { key: 'Tab', bubbles: true })); + fixture.detectChanges(); + expect(dropdown.focusedItem.itemID).toEqual('Ohio'); + expect(button.classList.contains(CSS_CLASS_BUTTON_FOCUSED)).toBe(true); + }); it('should keep the item focus style on the add item when it has a custom template', async () => { fixture = TestBed.createComponent(IgxComboCustomAddItemComponent); fixture.detectChanges(); diff --git a/projects/igniteui-angular/simple-combo/src/simple-combo/simple-combo.component.html b/projects/igniteui-angular/simple-combo/src/simple-combo/simple-combo.component.html index be92298aa8d..9d2cc4d3dbc 100644 --- a/projects/igniteui-angular/simple-combo/src/simple-combo/simple-combo.component.html +++ b/projects/igniteui-angular/simple-combo/src/simple-combo/simple-combo.component.html @@ -118,8 +118,9 @@ @if (addItemTemplate) { } @else { - - + + } } diff --git a/src/app/combo/combo.sample.html b/src/app/combo/combo.sample.html index ef93e2907e1..a917c9399cb 100644 --- a/src/app/combo/combo.sample.html +++ b/src/app/combo/combo.sample.html @@ -196,11 +196,9 @@

Template items

Group header for {{display[key]}}
} - home Please select the states you've visited diff --git a/src/styles/_variables.scss b/src/styles/_variables.scss index 976329f1cb4..0c47587a4b1 100644 --- a/src/styles/_variables.scss +++ b/src/styles/_variables.scss @@ -1,10 +1,10 @@ @use 'sass:map'; @use '../../projects/igniteui-angular/core/src/core/styles/themes' as *; -$palette: $dark-bootstrap-palette; -$schema: $dark-bootstrap-schema; -$typeface: $bootstrap-typeface; -$type-scale: $bootstrap-type-scale; +$palette: $light-material-palette; +$schema: $light-material-schema; +$typeface: $material-typeface; +$type-scale: $material-type-scale; $variant: map.get($schema, '_meta', 'variant'); $background-color: var(--ig-gray-900-contrast); $foreground-color: var(--ig-gray-900); From dea291b54622f7d7853835c9ff7b6d2e405a13bf Mon Sep 17 00:00:00 2001 From: onlyexeption Date: Fri, 20 Nov 2026 14:09:03 +0200 Subject: [PATCH 3/3] fix(combo): keep add item inactive until it is reached --- CHANGELOG.md | 1 + .../src/combo/combo-add-item.component.ts | 16 ++++- .../src/combo/combo-dropdown.component.ts | 33 ++++++--- .../combo/src/combo/combo.component.spec.ts | 2 +- .../simple-combo.component.spec.ts | 69 ++++++++++++++++++- 5 files changed, 109 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index de8d33007af..12829ce313e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -106,6 +106,7 @@ All notable changes for each version of this project will be documented in this - In Safari, the initial animation no longer overshoots the value and then crawls back to it. The initial fill and later value changes now use the same transition, so a value that changes while the bar is still animating goes straight to the new value in every browser. The Bootstrap circular bar now also animates its initial fill in RTL. - `IgxComboComponent`, `IgxSimpleComboComponent` - The default "Add item" button no longer takes the background or outline of a focused list item when it is reached with the keyboard. It shows the focus state of a flat button instead. + - In `IgxSimpleComboComponent`, "Add item" no longer appears focused before it is reached with the keyboard, for example right after typing text that matches no item or when the list reopens. - `IgxCsvExporterService` - Exporting a grid with summaries no longer adds an extra `GRID_LEVEL_COL` column with the nesting level of each record. Only the grid's columns are exported, as with the Excel and PDF exporters. - `IgxDatePickerComponent` diff --git a/projects/igniteui-angular/combo/src/combo/combo-add-item.component.ts b/projects/igniteui-angular/combo/src/combo/combo-add-item.component.ts index a1fddce7cc5..ca533775615 100644 --- a/projects/igniteui-angular/combo/src/combo/combo-add-item.component.ts +++ b/projects/igniteui-angular/combo/src/combo/combo-add-item.component.ts @@ -14,6 +14,11 @@ export class IgxComboAddItemComponent extends IgxComboItemComponent { /** * @hidden @internal * Set when the add item renders a custom `igxComboAddItem` template instead of the default button. + * + * @example + * ```html + * + * ``` */ @Input({ transform: booleanAttribute }) public customTemplate = false; @@ -27,9 +32,16 @@ export class IgxComboAddItemComponent extends IgxComboItemComponent { * @hidden @internal * Whether the add item is the active entry of the list. The focus stays on the list, * so the default button shows this state as its own focus state. + * + * @returns `true` when the drop-down's active entry is the add item. + * + * @example + * ```html + * + * ``` */ public get active(): boolean { - return super.focused; + return this.dropDown.focusedItem === this; } /** @@ -38,7 +50,7 @@ export class IgxComboAddItemComponent extends IgxComboItemComponent { * the focus style of the list items. A custom template keeps that style. */ public override get focused(): boolean { - return this.customTemplate && super.focused; + return this.customTemplate && this.active; } public override set focused(value: boolean) { diff --git a/projects/igniteui-angular/combo/src/combo/combo-dropdown.component.ts b/projects/igniteui-angular/combo/src/combo/combo-dropdown.component.ts index 0bc6540e009..1261c743300 100644 --- a/projects/igniteui-angular/combo/src/combo/combo-dropdown.component.ts +++ b/projects/igniteui-angular/combo/src/combo/combo-dropdown.component.ts @@ -31,6 +31,9 @@ export class IgxComboDropDownComponent extends IgxDropDownComponent implements I @ContentChildren(IgxComboItemComponent, { descendants: true }) public override children: QueryList = null!; + /** Whether the add item was the entry made active, as opposed to an index left over from a longer list. */ + private _addItemActive = false; + /** @hidden @internal */ public override get scrollContainer(): HTMLElement { return this.virtualization!.scrollElement; @@ -48,7 +51,10 @@ export class IgxComboDropDownComponent extends IgxDropDownComponent implements I * @hidden @internal */ public override get focusedItem(): IgxDropDownItemBaseDirective | null { - return super.focusedItem; + const item = super.focusedItem; + // The add item takes the index right after the rows, so an index kept from a longer list + // can point at it after filtering. It is active only when it was the entry made active. + return item instanceof IgxComboAddItemComponent && !this._addItemActive ? null : item; } /** @@ -64,15 +70,13 @@ export class IgxComboDropDownComponent extends IgxDropDownComponent implements I /** @hidden @internal */ public override set focusedItem(item: IgxDropDownItemBaseDirective | null) { - if (!item) { - this._activeDescendantId = null; - } else if (item.id !== undefined) { - this._activeDescendantId = item.id; - } else { + let entry = item; + if (item && item.id === undefined) { // Virtual { value, index } object passed by navigateItem() under virtual scrolling. - const resolved = this.children?.find(e => e.index === item.index); - this._activeDescendantId = resolved?.id ?? null; + entry = this.children?.find(e => e.index === item.index) ?? null; } + this._activeDescendantId = entry?.id ?? null; + this._addItemActive = entry instanceof IgxComboAddItemComponent; super.focusedItem = item; } @@ -120,6 +124,18 @@ export class IgxComboDropDownComponent extends IgxDropDownComponent implements I this.opened.emit(); } + /** + * @hidden @internal + */ + public override onToggleClosed() { + // The add item belongs to the search that showed it, so it is not active again on reopen. + if (this._addItemActive) { + this.focusedItem = null; + this.combo.setActiveDescendant(); + } + super.onToggleClosed(); + } + /** * @hidden */ @@ -168,6 +184,7 @@ export class IgxComboDropDownComponent extends IgxDropDownComponent implements I } this.comboAPI.set_selected_item(item.itemID); this._activeDescendantId = item.id ?? null; + this._addItemActive = false; this._focusedItem = item; this.combo.setActiveDescendant(); } diff --git a/projects/igniteui-angular/combo/src/combo/combo.component.spec.ts b/projects/igniteui-angular/combo/src/combo/combo.component.spec.ts index 89f070ef100..c6e428331f0 100644 --- a/projects/igniteui-angular/combo/src/combo/combo.component.spec.ts +++ b/projects/igniteui-angular/combo/src/combo/combo.component.spec.ts @@ -4256,6 +4256,7 @@ describe('igxCombo', () => { combo.handleKeyUp(UIInteractions.getKeyboardEvent('keyup', 'ArrowDown')); fixture.detectChanges(); + expect(combo.dropdown.focusedItem instanceof IgxComboAddItemComponent).toBe(true); const dropdownContent = fixture.debugElement.query(By.css(`.${CSS_CLASS_CONTENT}`)); UIInteractions.triggerEventHandlerKeyDown('Space', dropdownContent); fixture.detectChanges(); @@ -5740,7 +5741,6 @@ class IgxComboWithPrefixComponent { `, - changeDetection: ChangeDetectionStrategy.Eager, imports: [IgxComboComponent, IgxComboAddItemDirective] }) class IgxComboCustomAddItemComponent { diff --git a/projects/igniteui-angular/simple-combo/src/simple-combo/simple-combo.component.spec.ts b/projects/igniteui-angular/simple-combo/src/simple-combo/simple-combo.component.spec.ts index 63c5938fed4..e4b05b2762e 100644 --- a/projects/igniteui-angular/simple-combo/src/simple-combo/simple-combo.component.spec.ts +++ b/projects/igniteui-angular/simple-combo/src/simple-combo/simple-combo.component.spec.ts @@ -30,6 +30,7 @@ const CSS_CLASS_TOGGLEBUTTON = 'igx-combo__toggle-button'; const CSS_CLASS_CLEARBUTTON = 'igx-combo__clear-button'; const CSS_CLASS_ADDBUTTON = 'igx-combo__add-item'; const CSS_CLASS_FOCUSED = 'igx-drop-down__item--focused'; +const CSS_CLASS_BUTTON_FOCUSED = 'igx-button--focused'; const CSS_CLASS_INPUTGROUP = 'igx-input-group'; const CSS_CLASS_COMBO_INPUTGROUP = 'igx-input-group__input'; const CSS_CLASS_INPUTGROUP_REQUIRED = 'igx-input-group--required'; @@ -1553,7 +1554,73 @@ describe('IgxSimpleCombo', () => { const addItem: HTMLElement = fixture.debugElement.query(By.css(`.${CSS_CLASS_ADDBUTTON}`)).nativeElement; expect(addItem.classList.contains(CSS_CLASS_FOCUSED)).toBe(false); - expect(addItem.querySelector('button').classList.contains('igx-button--focused')).toBe(true); + expect(addItem.querySelector('button').classList.contains(CSS_CLASS_BUTTON_FOCUSED)).toBe(true); + }); + + it('should not make the AddItem active when the typed text matches no item', async () => { + // without grouping the first match is at index 0, the same index the AddItem takes when nothing matches + combo.groupKey = undefined; + fixture.componentInstance.allowCustomValues = true; + fixture.detectChanges(); + // typing in the input opens the list, and the focus stays in the input + input.nativeElement.focus(); + UIInteractions.setInputElementValue(input.nativeElement, 'Massachusetts'); + fixture.detectChanges(); + await fixture.whenStable(); + fixture.detectChanges(); + expect(combo.collapsed).toBe(false); + expect(combo.filteredData.length).toBeGreaterThan(0); + + UIInteractions.setInputElementValue(input.nativeElement, 'MassachusettsL'); + fixture.detectChanges(); + await fixture.whenStable(); + fixture.detectChanges(); + expect(combo.filteredData.length).toEqual(0); + + const button: HTMLElement = fixture.debugElement.query(By.css(`.${CSS_CLASS_ADDBUTTON}`)) + .nativeElement.querySelector('button'); + expect(combo.dropdown.focusedItem).toBeNull(); + expect(button.classList.contains(CSS_CLASS_BUTTON_FOCUSED)).toBe(false); + + combo.handleKeyUp(UIInteractions.getKeyboardEvent('keyup', 'ArrowDown')); + fixture.detectChanges(); + expect(combo.dropdown.focusedItem).toBe(combo.addItem); + expect(button.classList.contains(CSS_CLASS_BUTTON_FOCUSED)).toBe(true); + }); + + it('should not keep the AddItem active after the list closes', async () => { + fixture.componentInstance.allowCustomValues = true; + fixture.detectChanges(); + input.nativeElement.focus(); + UIInteractions.setInputElementValue(input.nativeElement, 'MassachusettsL'); + fixture.detectChanges(); + await fixture.whenStable(); + fixture.detectChanges(); + expect(combo.collapsed).toBe(false); + + combo.handleKeyUp(UIInteractions.getKeyboardEvent('keyup', 'ArrowDown')); + fixture.detectChanges(); + expect(combo.dropdown.focusedItem).toBe(combo.addItem); + + combo.close(); + fixture.detectChanges(); + await fixture.whenStable(); + fixture.detectChanges(); + expect(combo.collapsed).toBe(true); + + // typing again reopens the list with no matches + input.nativeElement.focus(); + UIInteractions.setInputElementValue(input.nativeElement, 'MassachusettsLL'); + fixture.detectChanges(); + await fixture.whenStable(); + fixture.detectChanges(); + expect(combo.collapsed).toBe(false); + expect(combo.filteredData.length).toEqual(0); + + const button: HTMLElement = fixture.debugElement.query(By.css(`.${CSS_CLASS_ADDBUTTON}`)) + .nativeElement.querySelector('button'); + expect(combo.dropdown.focusedItem).toBeNull(); + expect(button.classList.contains(CSS_CLASS_BUTTON_FOCUSED)).toBe(false); }); it('should close when an item is clicked on', () => {