Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(banner): add expanded input property to the banner #14935

Merged
merged 18 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
0ba8fe3
feat(banner): add collapsed input property to the banner
georgianastasov Oct 22, 2024
60e09aa
Merge branch 'master' into ganastasov/feat-14890-master
georgianastasov Oct 24, 2024
70681b9
Merge branch 'master' into ganastasov/feat-14890-master
georgianastasov Nov 20, 2024
a3b67cb
feat(banner): implement expanded property to the banner
georgianastasov Nov 26, 2024
c205fc7
Merge branch 'master' into ganastasov/feat-14890-master
georgianastasov Nov 26, 2024
d751021
Merge branch 'master' into ganastasov/feat-14890-master
georgianastasov Jan 13, 2025
6161f39
Merge branch 'master' into ganastasov/feat-14890-master
georgianastasov Jan 13, 2025
6f170da
fix(banner): handle expanded=true correctly during close animation
georgianastasov Jan 14, 2025
5b81b97
Merge branch 'master' into ganastasov/feat-14890-master
georgianastasov Jan 14, 2025
bd6b68e
Merge branch 'master' into ganastasov/feat-14890-master
georgianastasov Jan 16, 2025
505c45d
fix(changelog): update description to actual behavior of expanded pro…
georgianastasov Jan 16, 2025
f62423b
Merge branch 'master' into ganastasov/feat-14890-master
simeonoff Jan 17, 2025
223f5e0
Merge branch 'master' into ganastasov/feat-14890-master
georgianastasov Jan 17, 2025
170ede4
Merge branch 'master' into ganastasov/feat-14890-master
simeonoff Jan 20, 2025
96caacd
Merge branch 'master' into ganastasov/feat-14890-master
georgianastasov Jan 20, 2025
38fedd5
Merge branch 'master' into ganastasov/feat-14890-master
georgianastasov Jan 21, 2025
c750fd9
Merge branch 'master' into ganastasov/feat-14890-master
kacheshmarova Jan 21, 2025
954e229
Merge branch 'master' into ganastasov/feat-14890-master
georgianastasov Jan 23, 2025
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Ignite UI for Angular Change Log

All notable changes for each version of this project will be documented in this file.
## 19.1.0
### New Features
- `IgxBanner`
- Introduced a new `expanded` input property, enabling dynamic control over the banner's state. This property allows the banner to be programmatically set as expanded (visible) or collapsed (hidden) both initially and during runtime.
georgianastasov marked this conversation as resolved.
Show resolved Hide resolved

## 19.0.0
### General
Expand Down Expand Up @@ -50,6 +54,7 @@ All notable changes for each version of this project will be documented in this
- `IgxGridState`
- When possible the state directive nows reuses the column that already exists on the grid when restoring the state, instead of creating new column instances every time. This removes the need to set any complex objects manually back on the column on `columnInit`. The only instance where this is still necessary is when the column (or its children in case of column groups) have no `field` property so there's no way to uniquely identify the matching column.
- Added support for persisting Multi-Row Layout.

### Themes
- **Breaking Change** `Palettes`
- All palette colors have been migrated to the [CSS relative colors syntax](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_colors/Relative_colors). This means that color consumed as CSS variables no longer need to be wrapped in an `hsl` function.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ describe('igxBanner', () => {
IgxBannerOneButtonComponent,
IgxBannerSampleComponent,
IgxBannerCustomTemplateComponent,
SimpleBannerEventsComponent
SimpleBannerEventsComponent,
IgxBannerInitializedOpenComponent
]
}).compileComponents();
}));
Expand Down Expand Up @@ -395,6 +396,36 @@ describe('igxBanner', () => {
expect(banner.closing.emit).toHaveBeenCalledTimes(2);
expect(banner.closed.emit).toHaveBeenCalledTimes(1);
}));

it('Should toggle banner state when expanded property changes', fakeAsync(() => {
const fixture = TestBed.createComponent(IgxBannerInitializedOpenComponent);
fixture.detectChanges();
const banner = fixture.componentInstance.banner;

banner.expanded = false;
tick();
fixture.detectChanges();

expect(banner.expanded).toBeFalse();

banner.expanded = true;
tick();
fixture.detectChanges();
expect(banner.expanded).toBeTrue();
expect(banner.elementRef.nativeElement.style.display).toEqual('block');

banner.expanded = false;
tick();
fixture.detectChanges();
expect(banner.expanded).toBeFalse();
expect(banner.elementRef.nativeElement.style.display).toEqual('');

banner.expanded = true;
tick();
fixture.detectChanges();
expect(banner.expanded).toBeTrue();
expect(banner.elementRef.nativeElement.style.display).toEqual('block');
}));
});

describe('Rendering tests: ', () => {
Expand Down Expand Up @@ -485,6 +516,16 @@ describe('igxBanner', () => {
expect(panel.attributes.getNamedItem('role').nodeValue).toEqual('status');
expect(panel.attributes.getNamedItem('aria-live').nodeValue).toEqual('polite');
}));

it('Should initialize banner as open when expanded is set to true', fakeAsync(() => {
const fixture = TestBed.createComponent(IgxBannerInitializedOpenComponent);
fixture.detectChanges();
const banner = fixture.componentInstance.banner;

expect(banner.expanded).toBeTrue();
expect(banner.elementRef.nativeElement.style.display).toEqual('block');
expect(banner.elementRef.nativeElement.querySelector('.' + CSS_CLASS_BANNER)).not.toBeNull();
}));
});

const getBaseClassElements = <T>(fixture: ComponentFixture<T>) => {
Expand Down Expand Up @@ -601,3 +642,19 @@ export class SimpleBannerEventsComponent {
event.cancel = this.cancelFlag;
}
}

@Component({
template: `
<div>
<igx-banner [expanded]="true">
Banner initialized as open.
</igx-banner>
</div>
`,
standalone: true,
imports: [IgxBannerComponent]
})
export class IgxBannerInitializedOpenComponent {
@ViewChild(IgxBannerComponent, { static: true })
public banner: IgxBannerComponent;
}
58 changes: 54 additions & 4 deletions projects/igniteui-angular/src/lib/banner/banner.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,52 @@ export class IgxBannerComponent implements IToggleView {
public get resourceStrings(): IBannerResourceStrings {
return this._resourceStrings;
}

/**
* Gets whether banner is collapsed
* Gets/Sets whether the banner is expanded (visible) or collapsed (hidden).
* Defaults to `false`.
* Setting to `true` opens the banner, while `false` closes it.
*
* @example
* // Expand the banner
* banner.expanded = true;
*
* @example
* // Collapse the banner
* banner.expanded = false;
*
* @example
* // Check if the banner is expanded
* const isExpanded = banner.expanded;
*/
@Input()
public get expanded(): boolean {
return this._expanded;
}

public set expanded(value: boolean) {
if (value === this._expanded) {
return;
}

this._expanded = value;
this._isProgrammaticExpanded = true;

if (value) {
this._expansionPanel.open();
} else {
this._expansionPanel.close();
}
}

/**
* Gets whether the banner is collapsed.
*
* ```typescript
* const isCollapsed: boolean = banner.collapsed;
* ```
*/
public get collapsed() {
*/
public get collapsed(): boolean {
return this._expansionPanel.collapsed;
}

Expand Down Expand Up @@ -195,6 +233,8 @@ export class IgxBannerComponent implements IToggleView {
@ContentChild(IgxBannerActionsDirective)
private _bannerActionTemplate: IgxBannerActionsDirective;

private _expanded: boolean = false;
private _isProgrammaticExpanded = false;
georgianastasov marked this conversation as resolved.
Show resolved Hide resolved
private _bannerEvent: BannerEventArgs;
private _animationSettings: ToggleAnimationSettings;
private _resourceStrings = getCurrentResourceStrings(BannerResourceStringsEN);
Expand All @@ -216,7 +256,7 @@ export class IgxBannerComponent implements IToggleView {
* ```
*/
public open(event?: Event) {
this._bannerEvent = { owner: this, event};
this._bannerEvent = { owner: this, event };
const openingArgs: BannerCancelEventArgs = {
owner: this,
event,
Expand All @@ -227,6 +267,8 @@ export class IgxBannerComponent implements IToggleView {
return;
}
this._expansionPanel.open(event);
this._expanded = true;
this._isProgrammaticExpanded = false;
}

/**
Expand Down Expand Up @@ -255,6 +297,8 @@ export class IgxBannerComponent implements IToggleView {
return;
}
this._expansionPanel.close(event);
this._expanded = false;
this._isProgrammaticExpanded = false;
}

/**
Expand All @@ -281,11 +325,17 @@ export class IgxBannerComponent implements IToggleView {

/** @hidden */
public onExpansionPanelOpen() {
if (this._isProgrammaticExpanded) {
return;
}
this.opened.emit(this._bannerEvent);
}

/** @hidden */
public onExpansionPanelClose() {
if (this._isProgrammaticExpanded) {
return;
}
this.closed.emit(this._bannerEvent);
}
}
Loading