Skip to content

Commit

Permalink
feat(dropdown): added config
Browse files Browse the repository at this point in the history
* feat(karma config for saucelabs testing)

* revert changes

* feat(dropdown): add config for dropdown component
  • Loading branch information
musienkoyuriy authored and valorkin committed Dec 14, 2016
1 parent 8137030 commit cf8b1be
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 17 deletions.
8 changes: 8 additions & 0 deletions src/dropdown/dropdown.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { NONINPUT } from './dropdown.service';
import { Injectable } from '@angular/core';

@Injectable()
export class DropdownConfig {
public autoClose: string = NONINPUT;
public keyboardNav: Boolean = false;
}
7 changes: 4 additions & 3 deletions src/dropdown/dropdown.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import {
ChangeDetectorRef, Directive, ElementRef, EventEmitter, HostBinding, Input, OnDestroy, OnInit, Output
} from '@angular/core';

import { dropdownService, NONINPUT } from './dropdown.service';
import { dropdownService } from './dropdown.service';
import { DropdownConfig } from './dropdown.config';

@Directive({
selector: '[dropdown]',
Expand Down Expand Up @@ -60,16 +61,16 @@ export class DropdownDirective implements OnInit, OnDestroy {

protected _changeDetector:ChangeDetectorRef;

public constructor(el:ElementRef, ref:ChangeDetectorRef) {
public constructor(el:ElementRef, ref:ChangeDetectorRef, config: DropdownConfig) {
// @Query('dropdownMenu', {descendants: false})
// dropdownMenuList:QueryList<ElementRef>) {
this.el = el;
this._changeDetector = ref;
Object.assign(this, config);
// todo: bind to route change event
}

public ngOnInit():void {
this.autoClose = this.autoClose || NONINPUT;
if (this.isOpen) {
// todo: watch for event get-isOpen?
}
Expand Down
3 changes: 2 additions & 1 deletion src/dropdown/dropdown.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import { NgModule, ModuleWithProviders } from '@angular/core';
import { DropdownMenuDirective } from './dropdown-menu.directive';
import { DropdownToggleDirective } from './dropdown-toggle.directive';
import { DropdownDirective } from './dropdown.directive';
import { DropdownConfig } from './dropdown.config';

@NgModule({
declarations: [DropdownDirective, DropdownMenuDirective, DropdownToggleDirective],
exports: [DropdownDirective, DropdownMenuDirective, DropdownToggleDirective]
})
export class DropdownModule {
public static forRoot(): ModuleWithProviders {
return {ngModule: DropdownModule, providers: []};
return {ngModule: DropdownModule, providers: [DropdownConfig]};
}
}
1 change: 1 addition & 0 deletions src/dropdown/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export { DropdownToggleDirective } from './dropdown-toggle.directive';
export { DropdownDirective } from './dropdown.directive';
export { DropdownService } from './dropdown.service'
export { DropdownModule } from './dropdown.module';
export { DropdownConfig } from './dropdown.config';
30 changes: 17 additions & 13 deletions src/spec/dropdown.directive.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Component } from '@angular/core';
import { TestBed } from '@angular/core/testing';

import { DropdownModule } from '../dropdown/dropdown.module';
import { DropdownConfig } from '../dropdown/dropdown.config';

const defaultHtml = `
<div dropdown>
Expand All @@ -19,7 +20,7 @@ describe('Directive: Dropdown', () => {
it('should be closed by default', () => {
TestBed.configureTestingModule({
declarations: [TestDropdownComponent],
imports: [DropdownModule]
imports: [DropdownModule.forRoot()]
});
TestBed.overrideComponent(TestDropdownComponent, {set: {template: defaultHtml}});
let fixture = TestBed.createComponent(TestDropdownComponent);
Expand All @@ -40,7 +41,7 @@ describe('Directive: Dropdown', () => {
`;
TestBed.configureTestingModule({
declarations: [TestDropdownComponent],
imports: [DropdownModule]
imports: [DropdownModule.forRoot()]
});
TestBed.overrideComponent(TestDropdownComponent, {set: {template: html}});
let fixture = TestBed.createComponent(TestDropdownComponent);
Expand All @@ -61,7 +62,7 @@ describe('Directive: Dropdown', () => {
it('should toggle by click', () => {
TestBed.configureTestingModule({
declarations: [TestDropdownComponent],
imports: [DropdownModule]
imports: [DropdownModule.forRoot()]
});
TestBed.overrideComponent(TestDropdownComponent, {set: {template: defaultHtml}});
let fixture = TestBed.createComponent(TestDropdownComponent);
Expand All @@ -88,7 +89,7 @@ describe('Directive: Dropdown', () => {
`;
TestBed.configureTestingModule({
declarations: [TestDropdownComponent],
imports: [DropdownModule]
imports: [DropdownModule.forRoot()]
});
TestBed.overrideComponent(TestDropdownComponent, {set: {template: html}});
let fixture = TestBed.createComponent(TestDropdownComponent);
Expand Down Expand Up @@ -117,7 +118,7 @@ describe('Directive: Dropdown', () => {
`;
TestBed.configureTestingModule({
declarations: [TestDropdownComponent],
imports: [DropdownModule]
imports: [DropdownModule.forRoot()]
});
TestBed.overrideComponent(TestDropdownComponent, {set: {template: html}});
let fixture = TestBed.createComponent(TestDropdownComponent);
Expand Down Expand Up @@ -147,7 +148,7 @@ describe('Directive: Dropdown', () => {
`;
TestBed.configureTestingModule({
declarations: [TestDropdownComponent],
imports: [DropdownModule]
imports: [DropdownModule.forRoot()]
});
TestBed.overrideComponent(TestDropdownComponent, {set: {template: html}});
let fixture = TestBed.createComponent(TestDropdownComponent);
Expand Down Expand Up @@ -176,7 +177,7 @@ describe('Directive: Dropdown', () => {
`;
TestBed.configureTestingModule({
declarations: [TestDropdownComponent],
imports: [DropdownModule]
imports: [DropdownModule.forRoot()]
});
TestBed.overrideComponent(TestDropdownComponent, {set: {template: html}});
let fixture = TestBed.createComponent(TestDropdownComponent);
Expand Down Expand Up @@ -206,7 +207,7 @@ describe('Directive: Dropdown', () => {
`;
TestBed.configureTestingModule({
declarations: [TestDropdownComponent],
imports: [DropdownModule]
imports: [DropdownModule.forRoot()]
});
TestBed.overrideComponent(TestDropdownComponent, {set: {template: html}});
let fixture = TestBed.createComponent(TestDropdownComponent);
Expand Down Expand Up @@ -238,7 +239,7 @@ describe('Directive: Dropdown', () => {
`;
TestBed.configureTestingModule({
declarations: [TestDropdownComponent],
imports: [DropdownModule]
imports: [DropdownModule.forRoot()]
});
TestBed.overrideComponent(TestDropdownComponent, {set: {template: html}});
let fixture = TestBed.createComponent(TestDropdownComponent);
Expand Down Expand Up @@ -266,7 +267,7 @@ describe('Directive: Dropdown', () => {
`;
TestBed.configureTestingModule({
declarations: [TestDropdownComponent],
imports: [DropdownModule]
imports: [DropdownModule.forRoot()]
});
TestBed.overrideComponent(TestDropdownComponent, {set: {template: html}});
let fixture = TestBed.createComponent(TestDropdownComponent);
Expand Down Expand Up @@ -298,7 +299,7 @@ describe('Directive: Dropdown', () => {
`;
TestBed.configureTestingModule({
declarations: [TestDropdownComponent],
imports: [DropdownModule]
imports: [DropdownModule.forRoot()]
});
TestBed.overrideComponent(TestDropdownComponent, {set: {template: html}});
let fixture = TestBed.createComponent(TestDropdownComponent);
Expand All @@ -319,7 +320,7 @@ describe('Directive: Dropdown', () => {
`;
TestBed.configureTestingModule({
declarations: [TestDropdownComponent],
imports: [DropdownModule]
imports: [DropdownModule.forRoot()]
});
TestBed.overrideComponent(TestDropdownComponent, {set: {template: html}});
let fixture = TestBed.createComponent(TestDropdownComponent);
Expand All @@ -339,6 +340,9 @@ class TestDropdownComponent {
public isOpen: Boolean = false;
public isDisabled: Boolean = false;
public addToggleClass: Boolean = false;
public autoClose: String = 'nonInput';
public autoClose: string = 'nonInput';
public keyboardNav: Boolean = false;
public constructor(config: DropdownConfig) {
Object.assign(this, config);
}
}

0 comments on commit cf8b1be

Please sign in to comment.