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(dropdown): add isOpenChange output #2006

Merged
Merged
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<span dropdown (onShown)="onShown()" (onHidden)="onHidden()">
<span dropdown (onShown)="onShown()" (onHidden)="onHidden()" (isOpenChange)="isOpenChange()">
<a href dropdownToggle (click)="false">Click me for a dropdown, yo!</a>
<ul *dropdownMenu class="dropdown-menu">
<li *ngFor="let choice of items">
Expand Down
3 changes: 3 additions & 0 deletions demo/src/app/components/+dropdown/demos/basic/basic-link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ export class DemoDropdownBasicLinkComponent {
public onShown(): void {
console.log('Dropdown is shown');
}
public isOpenChange(): void {
console.log('Dropdown state is changed');
}
}
8 changes: 6 additions & 2 deletions demo/src/ng-api-doc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -841,11 +841,15 @@ export const ngdoc: any = {
"outputs": [
{
"name": "onHidden",
"description": "<p>Emits an event when the popover is hidden</p>\n"
"description": "<p>Emits an event when the dropdown is hidden</p>\n"
},
{
"name": "onShown",
"description": "<p>Emits an event when the popover is shown</p>\n"
"description": "<p>Emits an event when the dropdown is shown</p>\n"
},
{
"name": "isOpenChange",
"description": "<p>Emits an event when the dropdown is shown or hidden</p>\n"
}
],
"properties": [
Expand Down
16 changes: 11 additions & 5 deletions src/dropdown/bs-dropdown.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ export class BsDropdownDirective implements OnInit, OnDestroy {
}
}

/**
* Emits an event when isOpen change
*/
@Output() isOpenChange: EventEmitter<any>;

/**
* Emits an event when the popover is shown
*/
Expand All @@ -113,18 +118,19 @@ export class BsDropdownDirective implements OnInit, OnDestroy {
private _isInited = false;

constructor(private _elementRef: ElementRef,
private _renderer: Renderer,
private _viewContainerRef: ViewContainerRef,
private _cis: ComponentLoaderFactory,
private _config: BsDropdownConfig,
private _state: BsDropdownState) {
private _renderer: Renderer,
private _viewContainerRef: ViewContainerRef,
private _cis: ComponentLoaderFactory,
private _config: BsDropdownConfig,
private _state: BsDropdownState) {
// create dropdown component loader
this._dropdown = this._cis
.createLoader<BsDropdownContainerComponent>(this._elementRef, this._viewContainerRef, this._renderer)
.provide({ provide: BsDropdownState, useValue: this._state });

this.onShown = this._dropdown.onShown;
this.onHidden = this._dropdown.onHidden;
this.isOpenChange = this._state.isOpenChange;

// set initial dropdown state from config
this._state.autoClose = this._config.autoClose;
Expand Down