Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(file-input): read file input label when browse button is focused #1652

Merged
merged 2 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions projects/angular/clarity.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2667,13 +2667,17 @@ export class ClrLabel implements OnInit, OnDestroy {
// (undocumented)
forAttr: string;
// (undocumented)
idAttr: string;
// (undocumented)
idInput: string;
// (undocumented)
get labelText(): string;
// (undocumented)
ngOnDestroy(): void;
// (undocumented)
ngOnInit(): void;
// (undocumented)
static ɵdir: i0.ɵɵDirectiveDeclaration<ClrLabel, "label", never, { "forAttr": "for"; }, {}, never, never, false, never>;
static ɵdir: i0.ɵɵDirectiveDeclaration<ClrLabel, "label", never, { "idInput": "id"; "forAttr": "for"; }, {}, never, never, false, never>;
// (undocumented)
static ɵfac: i0.ɵɵFactoryDeclaration<ClrLabel, [{ optional: true; }, { optional: true; }, { optional: true; }, null, null]>;
}
Expand Down Expand Up @@ -3642,8 +3646,7 @@ export class ClrSignpostContent extends AbstractPopover implements OnDestroy {
// (undocumented)
signpostContentId: string;
// (undocumented)

static ɵcmp: i0.ɵɵComponentDeclaration<ClrSignpostContent, "clr-signpost-content", never, { "signpostCloseAriaLabel": "clrSignpostCloseAriaLabel"; "position": "clrPosition"; }, {}, never, ["clr-signpost-title", "*"], false, never>;
static ɵcmp: i0.ɵɵComponentDeclaration<ClrSignpostContent, "clr-signpost-content", never, { "signpostCloseAriaLabel": "clrSignpostCloseAriaLabel"; "position": "clrPosition"; }, {}, never, ["clr-signpost-title", "*"], false, never>;
// (undocumented)
static ɵfac: i0.ɵɵFactoryDeclaration<ClrSignpostContent, [null, { optional: true; }, null, null, null, null, null]>;
}
Expand Down
10 changes: 9 additions & 1 deletion projects/angular/src/forms/common/label.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import { NgControlService } from './providers/ng-control.service';
selector: 'label',
})
export class ClrLabel implements OnInit, OnDestroy {
@Input('id') idInput: string;
@HostBinding('attr.id') idAttr: string;

@Input('for') @HostBinding('attr.for') forAttr: string;

private enableGrid = true;
Expand Down Expand Up @@ -50,7 +53,12 @@ export class ClrLabel implements OnInit, OnDestroy {
this.renderer.addClass(this.el.nativeElement, `clr-col-md-${this.layoutService.labelSize}`);
}
if (this.controlIdService && !this.forAttr) {
this.subscriptions.push(this.controlIdService.idChange.subscribe(id => (this.forAttr = id)));
this.subscriptions.push(
this.controlIdService.idChange.subscribe(id => {
this.forAttr = id;
this.idAttr = this.idInput || `${id}-label`;
})
);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export class ClrFileInputContainer extends ClrAbstractContainer {
}

protected get browseButtonDescribedBy() {
return this.fileInput.elementRef.nativeElement.getAttribute('aria-describedby');
return `${this.label?.idAttr} ${this.fileInput.elementRef.nativeElement.getAttribute('aria-describedby')}`;
}

protected browse() {
Expand Down
Loading