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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ All notable changes for each version of this project will be documented in this
- Replacing the data and the columns of a percentage-height grid no longer runs a redundant sizing pass (#17792).
- `IgxHierarchicalGridComponent`
- Replacing the root columns with the same number of columns no longer leaves the old headers and column widths on screen when `summaryCalculationMode` is `childLevelsOnly`.
- `IgxInputGroupComponent`
- After a runtime theme change through `THEME_TOKEN`, an input group in an OnPush view, such as a grid cell editor or a combo in an OnPush component, updates its theme classes with its template. Previously it kept the classes of the theme it was first rendered in (#17991).

## 22.3.0

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, ViewChild, ElementRef, inject, ChangeDetectionStrategy, createComponent, EnvironmentInjector } from '@angular/core';
import { Component, ViewChild, ElementRef, inject, ChangeDetectionStrategy, createComponent, EnvironmentInjector, AfterViewInit } from '@angular/core';
import { NgTemplateOutlet } from '@angular/common';
import { TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
Expand All @@ -7,14 +7,15 @@ import { UIInteractions } from '../../../test-utils/ui-interactions.spec';
import { IgxHintDirective, IgxInputDirective, IgxLabelDirective, IgxPrefixDirective, IgxSuffixDirective } from '../public_api';
import { IgxCardComponent, IgxCardContentDirective } from 'igniteui-angular/card';
import { IGX_INPUT_GROUP_TYPE, IgxInputGroupType } from './inputGroupType';
import { InputResourceStringsEN, changei18n, THEME_TOKEN } from 'igniteui-angular/core';
import { InputResourceStringsEN, changei18n, IgxTheme, THEME_TOKEN, ThemeToken } from 'igniteui-angular/core';
import { config } from 'rxjs';
import { describe, it, expect, beforeEach, vi } from 'vitest';

const INPUT_GROUP_CSS_CLASS = 'igx-input-group';
const INPUT_GROUP_BOX_CSS_CLASS = 'igx-input-group--box';
const INPUT_GROUP_BORDER_CSS_CLASS = 'igx-input-group--border';
const INPUT_GROUP_SEARCH_CSS_CLASS = 'igx-input-group--search';
const INPUT_GROUP_BOOTSTRAP_CSS_CLASS = 'igx-input-group--bootstrap';

describe('IgxInputGroup', () => {
beforeEach(async () => {
Expand All @@ -29,7 +30,8 @@ describe('IgxInputGroup', () => {
InputGroupDisabledByDefaultComponent,
InputGroupDisabledWithoutValueComponent,
InputGroupNestedThemeScopeComponent,
InputGroupFormRowComponent
InputGroupFormRowComponent,
InputGroupOnPushThemeComponent
]
}).compileComponents();
});
Expand Down Expand Up @@ -281,6 +283,40 @@ describe('IgxInputGroup', () => {
}
});

describe('IgxInputGroup runtime theme change in an OnPush view (#17991)', () => {
// The theme classes are on the host and the notch is in the template, both must show the material theme
const expectMaterialBorder = (fixture) => {
const inputGroupElement = fixture.debugElement.query(By.css('igx-input-group')).nativeElement;
expect(inputGroupElement.classList.contains(INPUT_GROUP_BOOTSTRAP_CSS_CLASS)).toBe(false);
expect(inputGroupElement.classList.contains(INPUT_GROUP_BORDER_CSS_CLASS)).toBe(true);
expect(inputGroupElement.querySelector('.igx-input-group__notch')).not.toBeNull();
};

it('should update its theme classes when THEME_TOKEN changes', async () => {
const fixture = TestBed.createComponent(InputGroupOnPushThemeComponent);
fixture.detectChanges();
await fixture.whenStable();

const inputGroupElement = fixture.debugElement.query(By.css('igx-input-group')).nativeElement;
expect(inputGroupElement.classList.contains(INPUT_GROUP_BOOTSTRAP_CSS_CLASS)).toBe(true);

fixture.componentInstance.themeToken.set('material');
fixture.detectChanges();
await fixture.whenStable();

expectMaterialBorder(fixture);
});

it('should apply a theme that an OnPush parent sets in ngAfterViewInit', async () => {
const fixture = TestBed.createComponent(InputGroupOnPushThemeComponent);
fixture.componentInstance.savedTheme = 'material';
fixture.detectChanges();
await fixture.whenStable();

expectMaterialBorder(fixture);
});
});

describe('Resource Strings', () => {
it('should return full resource strings when partial resourceStrings are set', () => {
const fix = TestBed.createComponent(InputGroupComponent);
Expand Down Expand Up @@ -386,6 +422,24 @@ class InputGroupNestedThemeScopeComponent {
@ViewChild('materialGroup', { static: true }) public materialGroup: IgxInputGroupComponent;
}

@Component({
template: `<igx-input-group type="border"><input igxInput /></igx-input-group>`,
providers: [{ provide: THEME_TOKEN, useFactory: () => new ThemeToken('bootstrap') }],
changeDetection: ChangeDetectionStrategy.OnPush,
imports: [IgxInputGroupComponent, IgxInputDirective]
})
class InputGroupOnPushThemeComponent implements AfterViewInit {
public themeToken = inject(THEME_TOKEN);
/** A theme to restore after the first render, e.g. one the user saved */
public savedTheme?: IgxTheme;

public ngAfterViewInit() {
if (this.savedTheme) {
this.themeToken.set(this.savedTheme);
}
}
}

@Component({
template: `<igx-input-group #igxInputGroup [suppressInputAutofocus]="suppressInputAutofocus">
<igx-prefix>PREFIX</igx-prefix>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
AfterContentChecked,
ChangeDetectionStrategy,
ViewEncapsulation,
signal,
} from '@angular/core';
import { IInputResourceStrings, InputResourceStringsEN } from 'igniteui-angular/core';
import { getComponentTheme } from 'igniteui-angular/core';
Expand Down Expand Up @@ -148,7 +149,7 @@ export class IgxInputGroupComponent implements IgxInputGroupBase, AfterContentCh
private _destroyRef = inject(DestroyRef);
private _type: IgxInputGroupType | null = null;
private _filled = false;
private _theme: IgxTheme;
private readonly _theme = signal<IgxTheme>(this.themeToken.theme);
private _resourceStrings: IInputResourceStrings | null = null;
private _customResourceStrings: IInputResourceStrings = null!;
private _defaultResourceStrings = getCurrentResourceStrings(InputResourceStringsEN);
Expand Down Expand Up @@ -228,7 +229,7 @@ export class IgxInputGroupComponent implements IgxInputGroupBase, AfterContentCh
*/
@Input()
public set theme(value: IgxTheme) {
this._theme = value;
this._theme.set(value);
}

/**
Expand All @@ -242,14 +243,13 @@ export class IgxInputGroupComponent implements IgxInputGroupBase, AfterContentCh
* }
*/
public get theme(): IgxTheme {
return this._theme;
return this._theme();
}

constructor() {
this._theme = this.themeToken.theme;
const themeChange = this.themeToken.onChange((theme) => {
if (this._theme !== theme) {
this._theme = theme;
if (this._theme() !== theme) {
this._theme.set(theme);
this.cdr.detectChanges();
}
});
Expand Down Expand Up @@ -342,7 +342,7 @@ export class IgxInputGroupComponent implements IgxInputGroupBase, AfterContentCh
public get hasBorder() {
return (
(this.type === 'line' || this.type === 'box') &&
this._theme === 'material'
this._theme() === 'material'
);
}

Expand All @@ -358,13 +358,13 @@ export class IgxInputGroupComponent implements IgxInputGroupBase, AfterContentCh
*/
@HostBinding('class.igx-input-group--line')
public get isTypeLine(): boolean {
return this.type === 'line' && this._theme === 'material';
return this.type === 'line' && this._theme() === 'material';
}

/** @hidden @internal */
@HostBinding('class.igx-input-group--base')
public get isNotBorder(): boolean {
return this.type !== 'border' && this._theme === 'material';
return this.type !== 'border' && this._theme() === 'material';
}

/**
Expand All @@ -379,7 +379,7 @@ export class IgxInputGroupComponent implements IgxInputGroupBase, AfterContentCh
*/
@HostBinding('class.igx-input-group--box')
public get isTypeBox() {
return this.type === 'box' && this._theme === 'material';
return this.type === 'box' && this._theme() === 'material';
}

/** @hidden @internal */
Expand Down Expand Up @@ -434,7 +434,7 @@ export class IgxInputGroupComponent implements IgxInputGroupBase, AfterContentCh
*/
@HostBinding('class.igx-input-group--border')
public get isTypeBorder() {
return this.type === 'border' && this._theme === 'material';
return this.type === 'border' && this._theme() === 'material';
}

/**
Expand All @@ -449,7 +449,7 @@ export class IgxInputGroupComponent implements IgxInputGroupBase, AfterContentCh
*/
@HostBinding('class.igx-input-group--fluent')
public get isTypeFluent() {
return this._theme === 'fluent';
return this._theme() === 'fluent';
}

/**
Expand All @@ -464,7 +464,7 @@ export class IgxInputGroupComponent implements IgxInputGroupBase, AfterContentCh
*/
@HostBinding('class.igx-input-group--bootstrap')
public get isTypeBootstrap() {
return this._theme === 'bootstrap';
return this._theme() === 'bootstrap';
}

/**
Expand All @@ -479,7 +479,7 @@ export class IgxInputGroupComponent implements IgxInputGroupBase, AfterContentCh
*/
@HostBinding('class.igx-input-group--indigo')
public get isTypeIndigo() {
return this._theme === 'indigo';
return this._theme() === 'indigo';
}

/**
Expand Down Expand Up @@ -513,7 +513,7 @@ export class IgxInputGroupComponent implements IgxInputGroupBase, AfterContentCh
if (!this.themeToken.preferToken) {
const theme = getComponentTheme(this.element.nativeElement);

if (theme && theme !== this._theme) {
if (theme && theme !== this._theme()) {
this.theme = theme;
this.cdr.markForCheck();
}
Expand Down
Loading