Skip to content

Commit 7bc1345

Browse files
committed
#22 Textarea element implemented to the app with autofocus option
1 parent d3c64f2 commit 7bc1345

7 files changed

Lines changed: 66 additions & 1 deletion

File tree

src/app/app-routing.module.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import { NgModule } from '@angular/core';
22
import { Routes, RouterModule } from '@angular/router';
3+
34
import { NotFoundComponent } from './core/not-found/not-found.component';
5+
import { TextAreaComponent } from './components/text-area/text-area.component';
46

57
const routes: Routes = [
68
{
79
path: '',
810
redirectTo: '/',
911
pathMatch: 'full',
1012
},
13+
{ path: '', component: TextAreaComponent },
1114
{ path: 'not-found', component: NotFoundComponent },
1215
{ path: '**', redirectTo: 'not-found' },
1316
];

src/app/app.module.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ import { NgModule } from '@angular/core';
55
import { AppRoutingModule } from './app-routing.module';
66
import { ServiceWorkerModule } from '@angular/service-worker';
77
import { environment } from '../environments/environment';
8+
89
import { AppComponent } from './app.component';
10+
import { TextAreaComponent } from './components/text-area/text-area.component';
911

1012
@NgModule({
11-
declarations: [AppComponent],
13+
declarations: [AppComponent, TextAreaComponent],
1214
imports: [
1315
BrowserModule,
1416
AppRoutingModule,
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<textarea #saveTheText
2+
name="saveTheText"
3+
id="saveTheText"
4+
data-text-area
5+
autofocus></textarea>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[data-text-area] {
2+
display: flex;
3+
height: 100vh;
4+
width: 100%;
5+
border: 0;
6+
padding: 1rem;
7+
font-size: 1.2rem;
8+
resize: none;
9+
box-sizing: border-box;
10+
background-color: transparent;
11+
outline: none;
12+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { ComponentFixture, TestBed } from '@angular/core/testing';
2+
3+
import { TextAreaComponent } from './text-area.component';
4+
5+
describe('TextAreaComponent', () => {
6+
let component: TextAreaComponent;
7+
let fixture: ComponentFixture<TextAreaComponent>;
8+
9+
beforeEach(async () => {
10+
await TestBed.configureTestingModule({
11+
declarations: [TextAreaComponent],
12+
}).compileComponents();
13+
});
14+
15+
beforeEach(() => {
16+
fixture = TestBed.createComponent(TextAreaComponent);
17+
component = fixture.componentInstance;
18+
fixture.detectChanges();
19+
});
20+
21+
it('should create', () => {
22+
expect(component).toBeTruthy();
23+
});
24+
});
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { AfterViewInit, Component, OnInit, ViewChild } from '@angular/core';
2+
3+
@Component({
4+
selector: 'app-text-area',
5+
templateUrl: './text-area.component.html',
6+
styleUrls: ['./text-area.component.scss'],
7+
})
8+
export class TextAreaComponent implements OnInit, AfterViewInit {
9+
@ViewChild('saveTheText') saveTheText: any;
10+
11+
constructor() {}
12+
13+
ngOnInit(): void {}
14+
15+
ngAfterViewInit(): void {
16+
this.saveTheText.nativeElement.focus();
17+
}
18+
}

src/styles.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ body {
1111
height: 100vh;
1212
width: 100%;
1313
display: flex;
14+
position: fixed;
1415
background-image: url('assets/img/logo/square-opaque.svg');
1516
background-repeat: no-repeat;
1617
background-color: #fbfbfb;

0 commit comments

Comments
 (0)