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(module:dropdown): allow backdrop to be disabled #3769

Merged
merged 1 commit into from
Jul 15, 2019
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
1 change: 1 addition & 0 deletions components/dropdown/doc/index.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { NzDropDownModule } from 'ng-zorro-antd/dropdown';
| `[nzTrigger]` | the trigger mode which executes the drop-down action | `'click' \| 'hover'` | `'hover'` |
| `[nzClickHide]` | whether hide menu when click | `boolean` | `true` |
| `[nzVisible]` | whether the dropdown menu is visible, double binding | `boolean` | - |
| `[nzBackdrop]` | whether the dropdown has a backdrop when `nzTrigger` is `click` | `boolean` | `true` |
| `[nzOverlayClassName]` | Class name of the dropdown root element | `string` | - |
| `[nzOverlayStyle]` | Style of the dropdown root element | `object` | - |
| `(nzVisibleChange)` | a callback function takes an argument: `nzVisible`, is executed when the visible state is changed | `EventEmitter<boolean>` | - |
Expand Down
1 change: 1 addition & 0 deletions components/dropdown/doc/index.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { NzDropDownModule } from 'ng-zorro-antd/dropdown';
| `[nzTrigger]` | 触发下拉的行为 | `'click' \| 'hover'` | `'hover'` |
| `[nzClickHide]` | 点击后是否隐藏菜单 | `boolean` | `true` |
| `[nzVisible]` | 菜单是否显示,可双向绑定 | `boolean` | - |
| `[nzBackdrop]` | 是否在 `nzTrigger` 为 `click`时增加背景蒙版 | `boolean` | `true` |
| `[nzOverlayClassName]` | 下拉根元素的类名称 | `string` | - |
| `[nzOverlayStyle]` | 下拉根元素的样式 | `object` | - |
| `(nzVisibleChange)` | 菜单显示状态改变时调用,参数为 nzVisible | `EventEmitter<boolean>` | - |
Expand Down
19 changes: 19 additions & 0 deletions components/dropdown/nz-dropdown.directive.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,23 @@ describe('dropdown', () => {
);
}).not.toThrowError();
}));
it('should backdrop be disabled', fakeAsync(() => {
const fixture = createComponent(NzTestDropdownComponent, [], []);
fixture.componentInstance.trigger = 'click';
fixture.componentInstance.backdrop = false;
fixture.detectChanges();

expect(() => {
const dropdownElement = fixture.debugElement.query(By.directive(NzDropDownDirective)).nativeElement;
dispatchFakeEvent(dropdownElement, 'mouseenter');
fixture.detectChanges();
tick(1000);
fixture.detectChanges();

const backdrop = overlayContainerElement.querySelector('.cdk-overlay-backdrop');
expect(backdrop).toBeNull();
}).not.toThrowError();
}));
it('should nzOverlayClassName and nzOverlayStyle work', fakeAsync(() => {
const fixture = createComponent(NzTestDropdownComponent, [], []);
fixture.detectChanges();
Expand Down Expand Up @@ -152,6 +169,7 @@ describe('dropdown', () => {
[nzTrigger]="trigger"
[nzDisabled]="disabled"
[nzPlacement]="placement"
[nzBackdrop]="backdrop"
[nzOverlayClassName]="className"
[nzOverlayStyle]="overlayStyle"
>Trigger
Expand All @@ -166,6 +184,7 @@ describe('dropdown', () => {
`
})
export class NzTestDropdownComponent {
backdrop = true;
trigger = 'hover';
placement = 'bottomLeft';
disabled = false;
Expand Down
3 changes: 2 additions & 1 deletion components/dropdown/nz-dropdown.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export class NzDropDownDirective implements AfterViewInit, OnDestroy, OnChanges
@Input() nzDropdownMenu: NzDropdownMenuComponent;
@Input() nzTrigger: 'click' | 'hover' = 'hover';
@Input() nzMatchWidthElement: ElementRef;
@Input() @InputBoolean() nzBackdrop = true;
@Input() @InputBoolean() nzClickHide = true;
@Input() @InputBoolean() nzDisabled = false;
@Input() @InputBoolean() nzVisible = false;
Expand Down Expand Up @@ -89,7 +90,7 @@ export class NzDropDownDirective implements AfterViewInit, OnDestroy, OnChanges
.flexibleConnectedTo(this.el)
.withLockedPosition(),
minWidth: this.triggerWidth,
hasBackdrop: this.nzTrigger === 'click',
hasBackdrop: this.nzBackdrop && this.nzTrigger === 'click',
scrollStrategy: this.overlay.scrollStrategies.reposition()
});
}
Expand Down