AAE-34482 Fixing label and alignment issues in forms (#10898)

* AAE-34482 fixing label and alignment issues in forms

* AAE-34482 fixing margin issues

* AAE-34482 adding span inside mat-label

* AAE-34482 fixing units

* AAE-34482 removing unwanted unit

* AAE-34482 fixing unit

* AAE-34482 fixing native element class in unit tests
This commit is contained in:
Soumyajit Chakraborty
2025-05-28 23:20:17 +05:30
committed by GitHub
parent 5bbb5c5716
commit 79163cbae0
19 changed files with 50 additions and 42 deletions

View File

@@ -16,6 +16,10 @@
.alfresco-tabs-widget { .alfresco-tabs-widget {
width: 100%; width: 100%;
.adf-form-tab-content {
margin-top: 1em;
}
.adf-form-tab-group { .adf-form-tab-group {
width: 100%; width: 100%;
} }

View File

@@ -10,9 +10,9 @@
> >
</div> </div>
<div> <div>
<mat-form-field class="adf-amount-widget__input" [hideRequiredMarker]="true"> <mat-form-field class="adf-amount-widget__input" [hideRequiredMarker]="true" [floatLabel]="placeholder ? 'always' : 'auto'">
<label class="adf-label" *ngIf="!field.leftLabels" [attr.for]="field.id" <mat-label class="adf-label" *ngIf="!field.leftLabels" [attr.for]="field.id"
>{{field.name | translate }}<span class="adf-asterisk" [style.visibility]="isRequired() ? 'visible' : 'hidden'">*</span></label >{{field.name | translate }}<span class="adf-asterisk" [style.visibility]="isRequired() ? 'visible' : 'hidden'">*</span></mat-label
> >
<span matTextPrefix class="adf-amount-widget__prefix-spacing">{{ currency }}&nbsp;</span> <span matTextPrefix class="adf-amount-widget__prefix-spacing">{{ currency }}&nbsp;</span>
<input <input

View File

@@ -24,6 +24,10 @@
align-self: flex-end; align-self: flex-end;
} }
.adf-input {
margin-top: 3px;
}
&:not(#{ms.$mat-focused}):not(#{ms.$mat-form-field-invalid}) { &:not(#{ms.$mat-focused}):not(#{ms.$mat-form-field-invalid}) {
.adf-amount-widget__prefix-spacing { .adf-amount-widget__prefix-spacing {
color: var(--adf-theme-foreground-secondary-text-color); color: var(--adf-theme-foreground-secondary-text-color);

View File

@@ -192,7 +192,7 @@ describe('AmountWidgetComponent - rendering', () => {
expect(inputField).toBeTruthy(); expect(inputField).toBeTruthy();
expect(await field.getPrefixText()).toBe('$'); expect(await field.getPrefixText()).toBe('$');
const widgetLabel = testingUtils.getByCSS('label.adf-label').nativeElement; const widgetLabel = testingUtils.getByCSS('.adf-label').nativeElement;
expect(widgetLabel.textContent.trim()).toBe('Test Amount*'); expect(widgetLabel.textContent.trim()).toBe('Test Amount*');
expect(widget.field.isValid).toBe(false); expect(widget.field.isValid).toBe(false);
@@ -228,7 +228,7 @@ describe('AmountWidgetComponent - rendering', () => {
fixture.detectChanges(); fixture.detectChanges();
await fixture.whenStable(); await fixture.whenStable();
const widgetLabel = testingUtils.getByCSS('label.adf-label').nativeElement; const widgetLabel = testingUtils.getByCSS('.adf-label').nativeElement;
expect(widgetLabel.textContent.trim()).toBe('Test Amount*'); expect(widgetLabel.textContent.trim()).toBe('Test Amount*');
const field = await testingUtils.getMatFormField(); const field = await testingUtils.getMatFormField();

View File

@@ -11,9 +11,9 @@
<mat-form-field class="adf-date-time-widget" <mat-form-field class="adf-date-time-widget"
[class.adf-left-label-input-datepicker]="field.leftLabels" [class.adf-left-label-input-datepicker]="field.leftLabels"
[hideRequiredMarker]="true"> [hideRequiredMarker]="true">
<label class="adf-label" *ngIf="!field.leftLabels" [attr.for]="field.id"> <mat-label class="adf-label" *ngIf="!field.leftLabels" [attr.for]="field.id">
{{ field.name | translate }} ({{ field.dateDisplayFormat }})<span class="adf-asterisk" [style.visibility]="isRequired() ? 'visible' : 'hidden'">*</span> {{ field.name | translate }} ({{ field.dateDisplayFormat }})<span class="adf-asterisk" [style.visibility]="isRequired() ? 'visible' : 'hidden'">*</span>
</label> </mat-label>
<input matInput <input matInput
[matDatetimepicker]="datetimePicker" [matDatetimepicker]="datetimePicker"
[id]="field.id" [id]="field.id"

View File

@@ -10,9 +10,9 @@
<div> <div>
<mat-form-field [hideRequiredMarker]="true"> <mat-form-field [hideRequiredMarker]="true">
<label class="adf-label" *ngIf="!field.leftLabels" [attr.for]="field.id"> <mat-label class="adf-label" *ngIf="!field.leftLabels" [attr.for]="field.id">
{{ field.name | translate }}<span class="adf-asterisk" [style.visibility]="isRequired() ? 'visible' : 'hidden'">*</span> {{ field.name | translate }}<span class="adf-asterisk" [style.visibility]="isRequired() ? 'visible' : 'hidden'">*</span>
</label> </mat-label>
<input matInput <input matInput
class="adf-input" class="adf-input"

View File

@@ -2,9 +2,9 @@
[class.adf-invalid]="!field.isValid && isTouched()" [class.adf-invalid]="!field.isValid && isTouched()"
[class.adf-readonly]="field.readOnly"> [class.adf-readonly]="field.readOnly">
<mat-form-field floatPlaceholder="never" [hideRequiredMarker]="true"> <mat-form-field floatPlaceholder="never" [hideRequiredMarker]="true">
<label class="adf-label" [attr.for]="field.id"> <mat-label class="adf-label" [attr.for]="field.id">
{{ field.name | translate }}<span class="adf-asterisk" [style.visibility]="isRequired() ? 'visible' : 'hidden'">*</span> {{ field.name | translate }}<span class="adf-asterisk" [style.visibility]="isRequired() ? 'visible' : 'hidden'">*</span>
</label> </mat-label>
<textarea matInput <textarea matInput
class="adf-input" class="adf-input"
[cdkTextareaAutosize]="true" [cdkTextareaAutosize]="true"

View File

@@ -10,9 +10,9 @@
</div> </div>
<div> <div>
<mat-form-field [hideRequiredMarker]="true"> <mat-form-field [hideRequiredMarker]="true">
<label class="adf-label" *ngIf="!field.leftLabels" [attr.for]="field.id"> <mat-label class="adf-label" *ngIf="!field.leftLabels" [attr.for]="field.id">
{{ field.name | translate }}<span class="adf-asterisk" [style.visibility]="isRequired() ? 'visible' : 'hidden'">*</span> {{ field.name | translate }}<span class="adf-asterisk" [style.visibility]="isRequired() ? 'visible' : 'hidden'">*</span>
</label> </mat-label>
<input matInput <input matInput
class="adf-input" class="adf-input"
type="text" type="text"

View File

@@ -9,9 +9,9 @@
</div> </div>
<div> <div>
<mat-form-field [hideRequiredMarker]="true"> <mat-form-field [hideRequiredMarker]="true">
<label *ngIf="!field.leftLabels" class="adf-label" [attr.for]="field.id"> <mat-label *ngIf="!field.leftLabels" class="adf-label" [attr.for]="field.id">
{{ field.name | translate }}<span class="adf-asterisk" [style.visibility]="isRequired() ? 'visible' : 'hidden'">*</span> {{ field.name | translate }}<span class="adf-asterisk" [style.visibility]="isRequired() ? 'visible' : 'hidden'">*</span>
</label> </mat-label>
<input matInput <input matInput
class="adf-input" class="adf-input"
type="text" type="text"

View File

@@ -15,13 +15,12 @@
</div> </div>
<div> <div>
<mat-form-field class="adf-date-widget" [class.adf-left-label-input-datepicker]="field.leftLabels" [hideRequiredMarker]="true"> <mat-form-field class="adf-date-widget" [class.adf-left-label-input-datepicker]="field.leftLabels" [hideRequiredMarker]="true">
<label class="adf-label" *ngIf="!field.leftLabels" [attr.for]="field.id" <mat-label class="adf-label" *ngIf="!field.leftLabels" [attr.for]="field.id"
>{{field.name | translate }} ({{field.dateDisplayFormat}})<span >{{field.name | translate }} ({{field.dateDisplayFormat}})<span
class="adf-asterisk" class="adf-asterisk"
[style.visibility]="isRequired() ? 'visible' : 'hidden'" [style.visibility]="isRequired() ? 'visible' : 'hidden'"
>*</span >*</span
></label ></mat-label>
>
<input <input
matInput matInput
[matDatepicker]="datePicker" [matDatepicker]="datePicker"

View File

@@ -11,9 +11,9 @@
</div> </div>
<div> <div>
<mat-form-field> <mat-form-field>
<label *ngIf="!field.leftLabels" class="adf-label" [attr.for]="field.id"> <mat-label *ngIf="!field.leftLabels" class="adf-label" [attr.for]="field.id">
{{ field.name | translate }}<span class="adf-asterisk" [style.visibility]="isRequired() ? 'visible' : 'hidden'">*</span> {{ field.name | translate }}<span class="adf-asterisk" [style.visibility]="isRequired() ? 'visible' : 'hidden'">*</span>
</label> </mat-label>
<mat-select <mat-select
class="adf-select" class="adf-select"
[formControl]="dropdownControl" [formControl]="dropdownControl"

View File

@@ -22,11 +22,8 @@
[preSelectGroups]="preSelectGroup" [preSelectGroups]="preSelectGroup"
(blur)="markAsTouched()" (blur)="markAsTouched()"
[attr.title]="field.tooltip" [attr.title]="field.tooltip"
> [label] = "field.name | translate"
<label class="adf-label" *ngIf="!field.leftLabels" [attr.for]="field.id" label />
>{{field.name | translate }}<span class="adf-asterisk" [style.visibility]="isRequired() ? 'visible' : 'hidden'">*</span></label
>
</adf-cloud-group>
<error-widget [error]="field.validationSummary" /> <error-widget [error]="field.validationSummary" />
<error-widget <error-widget
class="adf-dropdown-required-message" class="adf-dropdown-required-message"

View File

@@ -19,12 +19,8 @@
[groupsRestriction]="groupsRestriction" [groupsRestriction]="groupsRestriction"
(blur)="markAsTouched()" (blur)="markAsTouched()"
[attr.title]="field.tooltip" [attr.title]="field.tooltip"
> [label]="field.name | translate"
<label class="adf-label" />
*ngIf="!field.leftLabels"
[attr.for]="field.id" label
>{{field.name | translate }}<span class="adf-asterisk" [style.visibility]="isRequired() ? 'visible' : 'hidden'">*</span></label>
</adf-cloud-people>
<error-widget [error]="field.validationSummary" /> <error-widget [error]="field.validationSummary" />
<error-widget <error-widget
class="adf-dropdown-required-message" class="adf-dropdown-required-message"

View File

@@ -26,13 +26,14 @@ import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { CommonModule } from '@angular/common'; import { CommonModule } from '@angular/common';
import { TranslateModule } from '@ngx-translate/core'; import { TranslateModule } from '@ngx-translate/core';
import { PeopleCloudComponent } from '../../../../people/components/people-cloud.component'; import { PeopleCloudComponent } from '../../../../people/components/people-cloud.component';
import { MatFormFieldModule } from '@angular/material/form-field';
/* eslint-disable @angular-eslint/component-selector */ /* eslint-disable @angular-eslint/component-selector */
@Component({ @Component({
selector: 'people-cloud-widget', selector: 'people-cloud-widget',
standalone: true, standalone: true,
imports: [CommonModule, TranslateModule, ErrorWidgetComponent, PeopleCloudComponent], imports: [CommonModule, TranslateModule, ErrorWidgetComponent, PeopleCloudComponent, MatFormFieldModule],
templateUrl: './people-cloud.widget.html', templateUrl: './people-cloud.widget.html',
host: { host: {
'(click)': 'event($event)', '(click)': 'event($event)',

View File

@@ -1,6 +1,9 @@
<form> <form>
<mat-form-field class="adf-cloud-group" [class.adf-invalid]="hasError() && isDirty()"> <mat-form-field class="adf-cloud-group" [class.adf-invalid]="hasError() && isDirty()">
<ng-content select="[label]" /> <mat-label>
<span>{{label}}</span>
<span class="adf-asterisk" [style.visibility]="required ? 'visible' : 'hidden'">*</span>
</mat-label>
<mat-chip-grid #groupChipList data-automation-id="adf-cloud-group-chip-list"> <mat-chip-grid #groupChipList data-automation-id="adf-cloud-group-chip-list">
<mat-chip-row <mat-chip-row
*ngFor="let group of selectedGroups" *ngFor="let group of selectedGroups"

View File

@@ -75,6 +75,10 @@ import { IdentityGroupService } from '../services/identity-group.service';
encapsulation: ViewEncapsulation.None encapsulation: ViewEncapsulation.None
}) })
export class GroupCloudComponent implements OnInit, OnChanges { export class GroupCloudComponent implements OnInit, OnChanges {
/** Label for the user selection component. */
@Input()
label: string;
/** Name of the application. If specified this shows the groups who have access to the app. */ /** Name of the application. If specified this shows the groups who have access to the app. */
@Input() @Input()
appName: string; appName: string;

View File

@@ -5,8 +5,12 @@
class="adf-people-cloud" class="adf-people-cloud"
[class.adf-invalid]="hasError() && isDirty()" [class.adf-invalid]="hasError() && isDirty()"
> >
<ng-content *ngIf="!title" select="[label]" /> <mat-label *ngIf="!title">
<span>{{label}}</span>
<span class="adf-asterisk" [style.visibility]="required ? 'visible' : 'hidden'">*</span>
</mat-label>
<mat-label *ngIf="title">{{ title | translate }}</mat-label> <mat-label *ngIf="title">{{ title | translate }}</mat-label>
<mat-chip-grid #userMultipleChipList data-automation-id="adf-cloud-people-chip-list"> <mat-chip-grid #userMultipleChipList data-automation-id="adf-cloud-people-chip-list">
<mat-chip-row <mat-chip-row
*ngFor="let user of selectedUsers" *ngFor="let user of selectedUsers"

View File

@@ -100,14 +100,6 @@ describe('PeopleCloudComponent', () => {
expect(await inputField.getLabel()).toEqual('TITLE_KEY'); expect(await inputField.getLabel()).toEqual('TITLE_KEY');
}); });
it('should not populate label when title is not present', async () => {
fixture.detectChanges();
const inputField = await loader.getHarness(MatFormFieldHarness.with({ selector: '.adf-people-cloud' }));
expect(await inputField.getLabel()).toBeNull();
});
describe('Search user', () => { describe('Search user', () => {
beforeEach(() => { beforeEach(() => {
fixture.detectChanges(); fixture.detectChanges();

View File

@@ -80,6 +80,10 @@ import { MatTooltipModule } from '@angular/material/tooltip';
encapsulation: ViewEncapsulation.None encapsulation: ViewEncapsulation.None
}) })
export class PeopleCloudComponent implements OnInit, OnChanges, AfterViewInit { export class PeopleCloudComponent implements OnInit, OnChanges, AfterViewInit {
/** Label for the user selection component. */
@Input()
label: string;
/** Name of the application. If specified, this shows the users who have access to the app. */ /** Name of the application. If specified, this shows the users who have access to the app. */
@Input() @Input()
appName: string; appName: string;