Skip to content
Open
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ 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.
- 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`
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -11,11 +11,52 @@ 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.
*
* @example
* ```html
* <igx-combo-add-item [customTemplate]="!!addItemTemplate"></igx-combo-add-item>
* ```
*/
@Input({ transform: booleanAttribute })
public customTemplate = false;
Comment thread
onlyexeption marked this conversation as resolved.
Resolved

@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.
*
* @returns `true` when the drop-down's active entry is the add item.
*
* @example
* ```html
* <button igxButton="flat" [class.igx-button--focused]="addItem.active || undefined"></button>
* ```
*/
public get active(): boolean {
return this.dropDown.focusedItem === this;
}

/**
* @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 && this.active;
}

public override set focused(value: boolean) {
super.focused = value;
}

public override get selected(): boolean {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ export class IgxComboDropDownComponent extends IgxDropDownComponent implements I
@ContentChildren(IgxComboItemComponent, { descendants: true })
public override children: QueryList<IgxDropDownItemBaseDirective> = 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;
Expand All @@ -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;
}

/**
Expand All @@ -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;
}

Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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();
}
Expand Down
17 changes: 10 additions & 7 deletions projects/igniteui-angular/combo/src/combo/combo.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,17 @@
</div>
}
@if (isAddButtonVisible()) {
<igx-combo-add-item [itemHeight]="itemHeight"
<igx-combo-add-item #addItem [itemHeight]="itemHeight"
[tabindex]="dropdown.collapsed ? -1 : customValueFlag ? 1 : -1" class="igx-combo__add-item" role="button"
[attr.aria-label]="resourceStrings.igx_combo_addCustomValues_placeholder" [index]="itemWindow.totalCount">
<ng-container *ngTemplateOutlet="addItemTemplate ? addItemTemplate : addItemDefault">
</ng-container>
[attr.aria-label]="resourceStrings.igx_combo_addCustomValues_placeholder" [index]="itemWindow.totalCount"
[customTemplate]="!!addItemTemplate">
@if (addItemTemplate) {
<ng-container *ngTemplateOutlet="addItemTemplate"></ng-container>
} @else {
<!-- Focus stays on the list, so the button shows the add item's focus state as its own.
When the add item is not active, `undefined` leaves the class to the button's own keyboard focus. -->
<button type="button" igxButton="flat" igxRipple [class.igx-button--focused]="addItem.active || undefined">{{ resourceStrings.igx_combo_addCustomValues_placeholder }}</button>
Comment thread
IMinchev64 marked this conversation as resolved.
Resolved
}
</igx-combo-add-item>
}
</div>
Expand All @@ -137,9 +143,6 @@
<ng-template #empty>
<span>{{resourceStrings.igx_combo_empty_message}}</span>
</ng-template>
<ng-template #addItemDefault let-control>
<button type="button" igxButton="flat" igxRipple>{{ resourceStrings.igx_combo_addCustomValues_placeholder }}</button>
</ng-template>
<ng-template #headerItemBase let-item let-key="valueKey" let-groupKey="groupKey">
{{ item[key] }}
</ng-template>
109 changes: 106 additions & 3 deletions projects/igniteui-angular/combo/src/combo/combo.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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';
Expand Down Expand Up @@ -1117,6 +1118,7 @@ describe('igxCombo', () => {
IgxComboFormComponent,
IgxComboInTemplatedFormComponent,
IgxComboWithPrefixComponent,
IgxComboCustomAddItemComponent,
]
}).compileComponents();
});
Expand Down Expand Up @@ -2876,6 +2878,89 @@ 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 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();
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');
Expand Down Expand Up @@ -4171,15 +4256,16 @@ 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();
// SPACE does not add item to collection
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}`));
Comment thread
onlyexeption marked this conversation as resolved.
Resolved
addItem.triggerEventHandler('click', UIInteractions.getMouseEvent('click'));
fixture.detectChanges();
expect(combo.collapsed).toBeFalsy();
expect(combo.displayValue).toEqual('My New Custom Item');
Expand Down Expand Up @@ -5647,6 +5733,23 @@ class IgxComboWithPrefixComponent {
public items = ['One', 'Two', 'Three'];
}

@Component({
template: `
<igx-combo #combo [data]="items" [allowCustomValues]="true">
<ng-template igxComboAddItem>
<span class="custom-add-item">Add a custom item</span>
</ng-template>
</igx-combo>
`,
imports: [IgxComboComponent, IgxComboAddItemDirective]
})
class IgxComboCustomAddItemComponent {
@ViewChild('combo', { read: IgxComboComponent, static: true })
public combo: IgxComboComponent;

public items = ['One', 'Two', 'Three'];
}

@Component({
template: `
<label id="mockID">Combo Label</label>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,15 @@
@if (isAddButtonVisible()) {
<igx-combo-add-item #addItem [itemHeight]="itemHeight"
[tabindex]="dropdown.collapsed ? -1 : customValueFlag ? 1 : -1" class="igx-combo__add-item" role="button"
[attr.aria-label]="resourceStrings.igx_combo_addCustomValues_placeholder" [index]="itemWindow.totalCount">
<ng-container *ngTemplateOutlet="addItemTemplate ? addItemTemplate : addItemDefault">
</ng-container>
[attr.aria-label]="resourceStrings.igx_combo_addCustomValues_placeholder" [index]="itemWindow.totalCount"
[customTemplate]="!!addItemTemplate">
@if (addItemTemplate) {
<ng-container *ngTemplateOutlet="addItemTemplate"></ng-container>
} @else {
<!-- Focus stays on the list, so the button shows the add item's focus state as its own.
When the add item is not active, `undefined` leaves the class to the button's own keyboard focus. -->
<button type="button" igxButton="flat" igxRipple [class.igx-button--focused]="addItem.active || undefined">{{ resourceStrings.igx_combo_addCustomValues_placeholder }}</button>
Comment thread
IMinchev64 marked this conversation as resolved.
Resolved
}
</igx-combo-add-item>
}
</div>
Expand All @@ -133,9 +139,6 @@
<ng-template #empty>
<span>{{resourceStrings.igx_combo_empty_message}}</span>
</ng-template>
<ng-template #addItemDefault let-control>
<button type="button" igxButton="flat" igxRipple>{{ resourceStrings.igx_combo_addCustomValues_placeholder }}</button>
</ng-template>
<ng-template #headerItemBase let-item let-key="valueKey" let-groupKey="groupKey">
{{ item[key] }}
</ng-template>
Loading
Loading