Skip to content

Commit

Permalink
feat: allow two-way binding on isOpen
Browse files Browse the repository at this point in the history
- Implement the canonical `isOpenChange` event to allow two-way binding
- Update documentation example to use the new two-way binding

This allows bindings like `<… dropdown [(isOpen)]="my.isOpen">` to prevent the internal and external flags from going out-of-sync whenever the dropdown is closed automatically.

From the angular2 documentation:
> […] Angular matches [(x)] to an x input property for property binding and an xChange output property for event binding.
  • Loading branch information
rluba committed Feb 10, 2016
1 parent eec3cb4 commit 674fcb7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 2 additions & 0 deletions components/dropdown/dropdown.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export class Dropdown implements OnInit, OnDestroy {
@Input() public appendToBody:boolean;

@Output() public onToggle:EventEmitter<boolean> = new EventEmitter();
@Output() public isOpenChange:EventEmitter<boolean> = new EventEmitter();
@HostBinding('class.dropdown') private addClass = true;

private _isOpen:boolean;
Expand Down Expand Up @@ -52,6 +53,7 @@ export class Dropdown implements OnInit, OnDestroy {
this.selectedOption = null;
}
this.onToggle.emit(this.isOpen);
this.isOpenChange.emit(this.isOpen);
// todo: implement call to setIsOpen if set and function
}

Expand Down
2 changes: 1 addition & 1 deletion demo/components/dropdown/dropdown-demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</span>

<!-- Single button -->
<div class="btn-group" dropdown [isOpen]="status.isopen">
<div class="btn-group" dropdown [(isOpen)]="status.isopen">
<button id="single-button" type="button" class="btn btn-primary" dropdownToggle [disabled]="disabled">
Button dropdown <span class="caret"></span>
</button>
Expand Down

0 comments on commit 674fcb7

Please sign in to comment.