Skip to content

Commit

Permalink
fix: fixed defaulting rows and columns to 1 causing layout issue
Browse files Browse the repository at this point in the history
demo: added custom template demo, closes #1
  • Loading branch information
trickeyone committed Apr 27, 2019
1 parent cc1d653 commit 3b74f98
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class NthdMentionsBasic {
disabled: boolean = false;
required: boolean = false;
rows: number = 5;
cols: number;
cols: number = 15;
dropUp: boolean = false;

model: any = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
[mentions]="model.mentions"
formClass="form-control"
rows="5"
cols="35"
[(ngModel)]="model.value"
placeholder="Type text here..."
(search)="onSearch($event)"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<div class="basic-example">
<ng-mentions
[mentions]="model.mentions"
formClass="form-control"
rows="5"
cols="35"
[(ngModel)]="model.value"
placeholder="Type text here..."
>
<ng-template let-item="item">
<span>{{item.id}}: {{item.display}} ({{item.type}})</span>
</ng-template>
</ng-mentions>
</div>
<pre class="my-2">{{model | json}}</pre>
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import {Component} from '@angular/core';

@Component({
selector: 'nthd-mentions-custom-template',
templateUrl: './mentions-custom-template.html'
})
export class NthdMentionsCustomTemplate {
model: any = {
value: '',
mentions: [
{
display: 'Dave',
id: 1,
type: 'contact'
},
{
display: 'Bob Ross',
id: 2,
type: 'contact'
},
{
display: 'Carl',
id: 3,
type: 'contact'
},
{
display: 'Sue',
id: 4,
type: 'contact'
},
]
};
}
13 changes: 12 additions & 1 deletion demo/src/app/components/mentions/demos/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@ import {NthdMentionsBasic} from './basic/mentions-basic';
import {NthdMentionsCustomSearch} from './custom-search/mentions-custom-search';
import {NthdMentionsStringValues} from './string-values/mentions-string-values';
import {NthdMentionsValidation} from './validation/mentions-validation';
import {NthdMentionsCustomTemplate} from './custom-template/mentions-custom-template';

export const DEMO_DIRECTIVES = [NthdMentionsBasic, NthdMentionsCustomSearch, NthdMentionsStringValues, NthdMentionsValidation];
export const DEMO_DIRECTIVES = [
NthdMentionsBasic,
NthdMentionsCustomSearch,
NthdMentionsStringValues,
NthdMentionsValidation,
NthdMentionsCustomTemplate,
];

export const DEMO_SNIPPETS = {
'basic': {
Expand All @@ -21,5 +28,9 @@ export const DEMO_SNIPPETS = {
'validation': {
'code': require('!!raw-loader!./validation/mentions-validation'),
'markup': require('!!raw-loader!./validation/mentions-validation.html')
},
'custom-template': {
'code': require('!!raw-loader!./custom-template/mentions-custom-template'),
'markup': require('!!raw-loader!./custom-template/mentions-custom-template.html')
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
[markup]="model.markup"
formClass="form-control"
rows="5"
cols="35"
[(ngModel)]="model.value"
placeholder="Type text here..."
></ng-mentions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
[mentions]="model.mentions"
formClass="form-control"
rows="5"
cols="35"
[(ngModel)]="model.value"
[required]="required"
#validation="ngModel"
Expand Down
4 changes: 4 additions & 0 deletions demo/src/app/components/mentions/mention.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ import {DEMO_SNIPPETS} from './demos';
<nthd-example-box title="String Values" [snippets]="snippets" component="mentions" demo="string-values" id="values">
<nthd-mentions-string-values></nthd-mentions-string-values>
</nthd-example-box>
<nthd-example-box title="Custom Mentions List Template" [snippets]="snippets" component="mentions" demo="custom-template"
id="template">
<nthd-mentions-custom-template></nthd-mentions-custom-template>
</nthd-example-box>
</nthd-component-wrapper>
`
})
Expand Down
4 changes: 2 additions & 2 deletions src/mentions-input.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ export class NgMentionsAccessorDirective implements OnInit, OnDestroy, ControlVa
}
}

onChange(value: any) {
if (this._onChange) {
onChange(value: string) {
if (this._onChange && typeof value === 'string') {
this._onChange(value);
}
}
Expand Down
16 changes: 10 additions & 6 deletions src/mentions.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,10 @@ export class NgMentionsComponent implements OnChanges, OnInit, AfterViewInit, Af
}

set rows(value: number|string) {
this._rows = Math.max(1, <number>value);
this.refreshStyles();
if (value !== null && typeof value !== 'undefined') {
this._rows = Math.max(1, <number>value);
this.refreshStyles();
}
}

@Input('cols')
Expand All @@ -184,8 +186,10 @@ export class NgMentionsComponent implements OnChanges, OnInit, AfterViewInit, Af
}

set columns(value: number|string) {
this._columns = Math.max(1, <number>value);
this.refreshStyles();
if (value !== null && typeof value !== 'undefined') {
this._columns = Math.max(1, <number>value);
this.refreshStyles();
}
}

/**
Expand Down Expand Up @@ -229,8 +233,8 @@ export class NgMentionsComponent implements OnChanges, OnInit, AfterViewInit, Af
private _value: string = '';
private _required: boolean;
private _disabled: boolean;
private _rows: number = 1;
private _columns: number = 1;
private _rows: number = null;
private _columns: number = null;
private searchString: string;
private startPos: number;
private startNode;
Expand Down

0 comments on commit 3b74f98

Please sign in to comment.