Skip to content

Commit 16c5828

Browse files
fix: use mat-label and bg-surface-container in TodoForm
- Restore mat-label inside mat-form-field for proper validation display - Wrap form in rounded-2xl bg-surface-container card to match other pages - Keep subscriptSizing=dynamic and sm:flex-row layout Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 3c98bbf commit 16c5828

1 file changed

Lines changed: 41 additions & 53 deletions

File tree

libs/todo/src/lib/components/todo-form/todo-form.ts

Lines changed: 41 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
FormGroup,
66
Validators,
77
} from '@angular/forms';
8-
import { MatFormField, MatError } from '@angular/material/form-field';
8+
import { MatFormField, MatLabel, MatError } from '@angular/material/form-field';
99
import { MatInput } from '@angular/material/input';
1010
import { MatButton } from '@angular/material/button';
1111
import { MatIcon } from '@angular/material/icon';
@@ -17,68 +17,56 @@ import { CreateTodoRequest } from '../../models/todo';
1717
imports: [
1818
ReactiveFormsModule,
1919
MatFormField,
20+
MatLabel,
2021
MatError,
2122
MatInput,
2223
MatButton,
2324
MatIcon,
2425
],
2526
template: `
2627
<form
27-
class="flex flex-col gap-4 sm:flex-row sm:items-end"
28+
class="flex flex-col gap-4 rounded-2xl bg-surface-container p-4 sm:flex-row sm:items-start"
2829
[formGroup]="form"
2930
(ngSubmit)="submit()"
3031
>
31-
<div class="flex flex-1 flex-col gap-4 sm:flex-row sm:items-end">
32-
<div class="flex flex-1 flex-col gap-1.5">
33-
<label
34-
class="text-xs font-semibold text-on-surface-variant"
35-
for="todo-title"
36-
>
37-
Title
38-
</label>
39-
<mat-form-field
40-
appearance="outline"
41-
subscriptSizing="dynamic"
42-
class="w-full"
43-
>
44-
<input
45-
matInput
46-
id="todo-title"
47-
formControlName="title"
48-
placeholder="What needs to be done?"
49-
autocomplete="off"
50-
/>
51-
@if (
52-
form.controls.title.hasError('required') &&
53-
form.controls.title.touched
54-
) {
55-
<mat-error>Title is required</mat-error>
56-
}
57-
</mat-form-field>
58-
</div>
59-
<div class="flex flex-1 flex-col gap-1.5">
60-
<label
61-
class="text-xs font-semibold text-on-surface-variant"
62-
for="todo-description"
63-
>
64-
Description
65-
</label>
66-
<mat-form-field
67-
appearance="outline"
68-
subscriptSizing="dynamic"
69-
class="w-full"
70-
>
71-
<input
72-
matInput
73-
id="todo-description"
74-
formControlName="description"
75-
placeholder="Optional details…"
76-
autocomplete="off"
77-
/>
78-
</mat-form-field>
79-
</div>
80-
</div>
81-
<button mat-flat-button type="submit" [disabled]="form.invalid">
32+
<mat-form-field
33+
appearance="outline"
34+
subscriptSizing="dynamic"
35+
class="flex-1"
36+
>
37+
<mat-label>Title</mat-label>
38+
<input
39+
matInput
40+
formControlName="title"
41+
placeholder="What needs to be done?"
42+
autocomplete="off"
43+
/>
44+
@if (
45+
form.controls.title.hasError('required') &&
46+
form.controls.title.touched
47+
) {
48+
<mat-error>Title is required</mat-error>
49+
}
50+
</mat-form-field>
51+
<mat-form-field
52+
appearance="outline"
53+
subscriptSizing="dynamic"
54+
class="flex-1"
55+
>
56+
<mat-label>Description</mat-label>
57+
<input
58+
matInput
59+
formControlName="description"
60+
placeholder="Optional details…"
61+
autocomplete="off"
62+
/>
63+
</mat-form-field>
64+
<button
65+
mat-flat-button
66+
type="submit"
67+
class="h-14 shrink-0"
68+
[disabled]="form.invalid"
69+
>
8270
<mat-icon>add</mat-icon>
8371
Add
8472
</button>

0 commit comments

Comments
 (0)