Skip to content

Commit

Permalink
feat(dropdown): add isOpenChange output (#2006)
Browse files Browse the repository at this point in the history
  • Loading branch information
IlyaSurmay authored and valorkin committed May 30, 2017
1 parent 1a516a6 commit 1c9f767
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
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

0 comments on commit 1c9f767

Please sign in to comment.