Skip to content

Commit

Permalink
Merge pull request #12533 from volvachev/fix-radiobuttion-inside-table
Browse files Browse the repository at this point in the history
fix(primeng/p-tableRadioButton): update logic for component with `checked` and `focused` states
  • Loading branch information
cetincakiroglu authored Jan 26, 2023
2 parents 2c1893d + a7a4906 commit b6cfb8c
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/app/components/table/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3832,9 +3832,9 @@ export class CellEditor implements AfterContentInit {
@Component({
selector: 'p-tableRadioButton',
template: `
<div class="p-radiobutton p-component" [ngClass]="{ 'p-radiobutton-focused': focused, 'p-radiobutton-disabled': disabled }" (click)="onClick($event)">
<div class="p-radiobutton p-component" [ngClass]="{ 'p-radiobutton-focused': focused, 'p-radiobutton-checked': checked, 'p-radiobutton-disabled': disabled }" (click)="onClick($event)">
<div class="p-hidden-accessible">
<input type="radio" [attr.id]="inputId" [attr.name]="name" [checked]="checked" (focus)="onFocus()" (blur)="onBlur()" [disabled]="disabled" [attr.aria-label]="ariaLabel" />
<input #rb type="radio" [attr.id]="inputId" [attr.name]="name" [checked]="checked" (focus)="onFocus()" (blur)="onBlur()" [disabled]="disabled" [attr.aria-label]="ariaLabel" />
</div>
<div #box [ngClass]="{ 'p-radiobutton-box p-component': true, 'p-highlight': checked, 'p-focus': focused, 'p-disabled': disabled }" role="radio" [attr.aria-checked]="checked">
<div class="p-radiobutton-icon"></div>
Expand All @@ -3860,13 +3860,15 @@ export class TableRadioButton {

@Input() ariaLabel: string;

@ViewChild('rb') inputViewChild: ElementRef;

checked: boolean;

focused: boolean;

subscription: Subscription;

constructor(public dt: Table, public tableService: TableService, public cd: ChangeDetectorRef) {
constructor(public dt: Table, public cd: ChangeDetectorRef) {
this.subscription = this.dt.tableService.selectionSource$.subscribe(() => {
this.checked = this.dt.isSelected(this.value);
this.cd.markForCheck();
Expand All @@ -3886,6 +3888,8 @@ export class TableRadioButton {
},
this.value
);

this.inputViewChild.nativeElement?.focus();
}
DomHandler.clearSelection();
}
Expand Down

0 comments on commit b6cfb8c

Please sign in to comment.