Skip to content

Commit cccb231

Browse files
committed
fix empty-field
1 parent 332a1c3 commit cccb231

File tree

10 files changed

+55
-35
lines changed

10 files changed

+55
-35
lines changed

projects/angular-keyboard/src/lib/fake-input/fake-char/fake-char.component.scss renamed to projects/angular-keyboard/src/lib/fake-input/cursor.scss

File renamed without changes.

projects/angular-keyboard/src/lib/fake-input/fake-char/fake-char.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {AngularKeyboardModuleConfig} from '../../angular-keyboard.module';
77
@Component({
88
selector: 'tb-fake-char',
99
templateUrl: './fake-char.component.html',
10-
styleUrls: ['./fake-char.component.scss'],
10+
styleUrls: ['../cursor.scss'],
1111
changeDetection: ChangeDetectionStrategy.OnPush
1212
})
1313
export class FakeCharComponent implements OnInit {

projects/angular-keyboard/src/lib/fake-input/fake-input.component.html

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,18 @@
22
[ngStyle]="config.styles?.inputField"
33
#wrapper
44
(click)="onClickInputField($event)">
5-
<ng-container *ngFor="let char of chars; let idx = index">
6-
<tb-fake-char #fakechar
5+
<ng-container *ngIf="chars.length > 0; else emptyField">
6+
<tb-fake-char *ngFor="let char of chars; let idx = index"
7+
#fakechar
78
(clickLeft)="onClickCharLeft(char, idx)"
89
(clickRight)="onClickCharRight(char, idx)"
910
[char]="char"
10-
[cursor]="getCursor(idx)"></tb-fake-char>
11+
[cursor]="getCursor(idx)">
12+
</tb-fake-char>
1113
</ng-container>
14+
<ng-template #emptyField>
15+
<span *ngIf="isFocused"
16+
class="cursor-left">
17+
</span>
18+
</ng-template>
1219
</div>

projects/angular-keyboard/src/lib/fake-input/fake-input.component.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
$cursor-width: 1px;
2+
13
.wrapper {
24
white-space: pre-wrap; // to preserve multiple sequential whitespaces
35
cursor: text;

projects/angular-keyboard/src/lib/fake-input/fake-input.component.ts

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ interface Cursor {
3434
@Component({
3535
selector: 'tb-input',
3636
templateUrl: './fake-input.component.html',
37-
styleUrls: ['./fake-input.component.scss']
37+
styleUrls: ['./fake-input.component.scss', './cursor.scss']
3838
})
3939
export class FakeInputComponent implements OnInit, OnDestroy {
4040

@@ -47,6 +47,8 @@ export class FakeInputComponent implements OnInit, OnDestroy {
4747
@ViewChild('wrapper', {static: true}) wrapper: ElementRef;
4848
@ViewChildren('fakechar', {read: ElementRef}) charElements: QueryList<ElementRef>;
4949

50+
isFocused = false;
51+
5052
chars: Char[] = [];
5153

5254
private cursorInternal: Cursor | null = null;
@@ -99,6 +101,9 @@ export class FakeInputComponent implements OnInit, OnDestroy {
99101
this.angularKeyboardService.inputFocused$.subscribe(next => {
100102
if (next !== this.wrapper.nativeElement) {
101103
this.cursor = null;
104+
this.isFocused = false;
105+
} else {
106+
this.isFocused = true;
102107
}
103108
})
104109
);
@@ -466,19 +471,26 @@ export class FakeInputComponent implements OnInit, OnDestroy {
466471

467472
onClickInputField(e) {
468473
this.focusInput();
469-
const closest = this.findClosestHorizontalChar(e);
470-
if (closest != null) {
471-
if (closest.isLeft) {
472-
this.cursor = {
473-
index: closest.idx,
474-
side: Side.LEFT
475-
};
476-
} else {
477-
this.cursor = {
478-
index: closest.idx,
479-
side: Side.RIGHT
480-
};
474+
if (this.chars.length > 0) {
475+
const closest = this.findClosestHorizontalChar(e);
476+
if (closest != null) {
477+
if (closest.isLeft) {
478+
this.cursor = {
479+
index: closest.idx,
480+
side: Side.LEFT
481+
};
482+
} else {
483+
this.cursor = {
484+
index: closest.idx,
485+
side: Side.RIGHT
486+
};
487+
}
481488
}
489+
} else {
490+
this.cursor = {
491+
index: 0,
492+
side: Side.LEFT
493+
};
482494
}
483495
}
484496

projects/angular-keyboard/src/public-api.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
* Public API Surface of angular-keyboard
33
*/
44

5-
export * from './lib/angular-keyboard.service';
6-
export * from './lib/angular-keyboard.module';
5+
export {AngularKeyboardService} from './lib/angular-keyboard.service';
6+
export {AngularKeyboardModule, AngularKeyboardModuleConfig} from './lib/angular-keyboard.module';

src/app/keyboard-demo/keyboard-demo.module.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import { NgModule } from '@angular/core';
2-
import { CommonModule } from '@angular/common';
1+
import {NgModule} from '@angular/core';
2+
import {CommonModule} from '@angular/common';
33

4-
import { KeyboardDemoRoutingModule } from './keyboard-demo-routing.module';
5-
import { KeyboardDemoComponent } from './keyboard-demo/keyboard-demo.component';
6-
import {AngularKeyboardModule} from '../../../projects/angular-keyboard/src/lib/angular-keyboard.module';
4+
import {KeyboardDemoRoutingModule} from './keyboard-demo-routing.module';
5+
import {KeyboardDemoComponent} from './keyboard-demo/keyboard-demo.component';
76
import {NavModule} from '../nav/nav.module';
8-
7+
import {AngularKeyboardModule} from '@taskbase/angular-keyboard';
98

109
@NgModule({
1110
declarations: [KeyboardDemoComponent],
@@ -35,7 +34,8 @@ import {NavModule} from '../nav/nav.module';
3534
'text-decoration': 'line-through'
3635
}
3736
}
38-
}),
37+
})
3938
]
4039
})
41-
export class KeyboardDemoModule { }
40+
export class KeyboardDemoModule {
41+
}

src/app/keyboard-demo/keyboard-demo/keyboard-demo.component.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ <h1>Keyboard Demo</h1>
66
Click into the input field to open the keyboard.
77
</p>
88
<div style="width: 500px; max-width: 100%; margin: 0 auto;">
9-
<tb-input (text)="onTextChange($event)">
9+
<tb-input (text)="onTextChange($event)"
10+
[initialText]="''">
1011
</tb-input>
1112
</div>
1213

@@ -15,7 +16,8 @@ <h1>Keyboard Demo</h1>
1516
</p>
1617
<div style="width: 400px; max-width: 100%; margin: 0 auto;">
1718
<tb-input [suggestionMode]="true"
18-
(text)="onTextChange($event)">
19+
[initialText]="'Das ist ein Text mit Felern. Korigiere die Fehler!'"
20+
(text)="onTextChange($event)">
1921
</tb-input>
2022
</div>
2123

src/app/keyboard-demo/keyboard-demo/keyboard-demo.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {Component} from '@angular/core';
2-
import {AngularKeyboardService} from '../../../../projects/angular-keyboard/src/lib/angular-keyboard.service';
2+
import {AngularKeyboardService} from '@taskbase/angular-keyboard';
33

44
@Component({
55
selector: 'app-keyboard-demo',

tsconfig.json

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,13 @@
1919
"dom"
2020
],
2121
"paths": {
22-
"angular-keyboard": [
22+
"@taskbase/angular-keyboard": [
2323
"dist/angular-keyboard"
24-
],
25-
"angular-keyboard/*": [
26-
"dist/angular-keyboard/*"
2724
]
2825
}
2926
},
3027
"angularCompilerOptions": {
3128
"fullTemplateTypeCheck": true,
3229
"strictInjectionParameters": true
3330
}
34-
}
31+
}

0 commit comments

Comments
 (0)