Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd61b048

Browse files
committed
feat(Dropdown): add DropdownCloseDirective
1 parent17cc20e commitd61b048

File tree

5 files changed

+72
-3
lines changed

5 files changed

+72
-3
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import{DropdownService}from'../dropdown.service';
2+
import{DropdownCloseDirective}from'./dropdown-close.directive';
3+
4+
describe('DropdownCloseDirective',()=>{
5+
it('should create an instance',()=>{
6+
constdropdownService=newDropdownService();
7+
constdirective=newDropdownCloseDirective(dropdownService);
8+
expect(directive).toBeTruthy();
9+
});
10+
});
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import{Directive,HostBinding,HostListener,Input,Optional}from'@angular/core';
2+
import{DropdownService}from'../dropdown.service';
3+
import{DropdownComponent}from'../dropdown/dropdown.component';
4+
5+
@Directive({
6+
selector:'[cDropdownClose]',
7+
exportAs:'cDropdownClose'
8+
})
9+
exportclassDropdownCloseDirective{
10+
11+
/**
12+
* Disables a dropdown-close directive.
13+
*@type boolean
14+
*@default undefined
15+
*/
16+
@Input()disabled?:boolean;
17+
18+
constructor(
19+
privatedropdownService:DropdownService,
20+
@Optional()publicdropdown?:DropdownComponent
21+
){}
22+
23+
@HostBinding('class')
24+
gethostClasses():any{
25+
return{
26+
disabled:this.disabled
27+
};
28+
}
29+
30+
@HostBinding('attr.tabindex')
31+
@Input()
32+
settabIndex(value:string|number|null){
33+
this._tabIndex=value;
34+
}
35+
gettabIndex(){
36+
returnthis.disabled ?'-1' :this._tabIndex;
37+
}
38+
private_tabIndex:string|number|null=null;
39+
40+
@HostBinding('attr.aria-disabled')
41+
getisDisabled():boolean|null{
42+
returnthis.disabled||null;
43+
}
44+
45+
@HostListener('click',['$event'])
46+
privateonClick($event:MouseEvent):void{
47+
this.dropdownService.toggle({visible:false,dropdown:this.dropdown});
48+
}
49+
50+
@HostListener('keyup',['$event'])
51+
privateonKeyUp($event:KeyboardEvent):void{
52+
if($event.key==='Enter'){
53+
this.dropdownService.toggle({visible:false,dropdown:this.dropdown});
54+
}
55+
}
56+
}

‎projects/coreui-angular/src/lib/dropdown/dropdown-menu/dropdown-menu.directive.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ export class DropdownMenuDirective implements OnInit, OnDestroy {
3333
getdark():boolean{
3434
returnthis._dark;
3535
}
36-
3736
setdark(value:boolean){
3837
this._dark=coerceBooleanProperty(value);
3938
}

‎projects/coreui-angular/src/lib/dropdown/dropdown.module.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { DropdownItemDirective } from './dropdown-item/dropdown-item.directive';
77
import{DropdownItemPlainDirective}from'./dropdown-item/dropdown-item-plain.directive';
88
import{DropdownMenuDirective}from'./dropdown-menu/dropdown-menu.directive';
99
import{DropdownService}from'./dropdown.service';
10+
import{DropdownCloseDirective}from'./dropdown-close/dropdown-close.directive';
1011

1112
@NgModule({
1213
declarations:[
@@ -16,7 +17,8 @@ import { DropdownService } from './dropdown.service';
1617
DropdownItemDirective,
1718
DropdownItemPlainDirective,
1819
DropdownToggleDirective,
19-
DropdownMenuDirective
20+
DropdownMenuDirective,
21+
DropdownCloseDirective
2022
],
2123
imports:[
2224
CommonModule,
@@ -28,7 +30,8 @@ import { DropdownService } from './dropdown.service';
2830
DropdownItemDirective,
2931
DropdownItemPlainDirective,
3032
DropdownToggleDirective,
31-
DropdownMenuDirective
33+
DropdownMenuDirective,
34+
DropdownCloseDirective
3235
],
3336
providers:[
3437
DropdownService,

‎projects/coreui-angular/src/lib/dropdown/public_api.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export { DropdownHeaderDirective } from './dropdown-header/dropdown-header.direc
33
export{DropdownItemDirective}from'./dropdown-item/dropdown-item.directive';
44
export{DropdownItemPlainDirective}from'./dropdown-item/dropdown-item-plain.directive';
55
export{DropdownMenuDirective}from'./dropdown-menu/dropdown-menu.directive';
6+
export{DropdownCloseDirective}from'./dropdown-close/dropdown-close.directive';
67
export{DropdownComponent,DropdownToggleDirective}from'./dropdown/dropdown.component';
78
export{DropdownService}from'./dropdown.service';
89
export{DropdownModule}from'./dropdown.module';

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp