Skip to content

Commit

Permalink
feat(module:popover): feat add autoClose to set click popover item to…
Browse files Browse the repository at this point in the history
… close popvoer (#130)
  • Loading branch information
Guoyuanqiang authored and 3fuyu committed Dec 3, 2018
1 parent 26bbe53 commit 71ea780
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions components/popover/doc/index.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Properties | Descrition | Type | Default
| overlay | Popup layer content | TemplateRef | - |
| onSelect | when an option is selected | (node: any, index?: number): void | - |
| className | Custom popover class, e.g. "am-popover-${your className}" | string | am-popover |
| autoClose | set click popover item to close popvoer | Boolean | true |

### Popover.Item

Expand Down
1 change: 1 addition & 0 deletions components/popover/doc/index.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ subtitle: 气泡
| overlay | 弹出层内容 | TemplateRef | - |
| onSelect | 选中某选项时的回调函数 | (node: any, index?: number): void | - |
| className | 传入自定义class, e.g. "am-popover-${your className}" | string | am-popover |
| autoClose | 是否使用点击popover元素关闭popover | Boolean | true |

### Popover.Item

Expand Down
2 changes: 2 additions & 0 deletions components/popover/popover-options.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export interface PopoverOptionsInterface {
placement?: string;
appendToBody?: boolean;
className?: string;
autoClose?: boolean;
}

export class PopoverOptions implements PopoverOptionsInterface {
Expand All @@ -12,4 +13,5 @@ export class PopoverOptions implements PopoverOptionsInterface {
placement: string = 'bottom';
appendToBody: boolean = false;
className: string = '';
autoClose: boolean = true;
}
9 changes: 7 additions & 2 deletions components/popover/popover.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ export class PopoverDirective implements OnInit, OnChanges, OnDestroy {
appendToBody: boolean;
@Input()
className: string;
@Input()
autoClose: boolean;

@HostListener('click')
togglePopover(): void {
Expand Down Expand Up @@ -149,7 +151,9 @@ export class PopoverDirective implements OnInit, OnChanges, OnDestroy {
() => {
if (this.onSelect) {
this.onSelect.emit(children[i]);
this.hidePopover();
if (options.autoClose) {
this.hidePopover();
}
}
},
false
Expand All @@ -165,7 +169,8 @@ export class PopoverDirective implements OnInit, OnChanges, OnDestroy {
'placement',
'appendToBody',
'overlay',
'className'
'className',
'autoClose'
];
optionalParams.forEach(param => {
if (typeof this[param] !== 'undefined') {
Expand Down

0 comments on commit 71ea780

Please sign in to comment.