Skip to content
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
32 changes: 30 additions & 2 deletions projects/components/src/radio/radio-group.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
}

.mat-radio-outer-circle {
border-width: 0px;
border-width: 0;
}

.mat-radio-inner-circle {
Expand Down Expand Up @@ -69,6 +69,11 @@
@include body-2-regular($gray-7);
}

.radio-button-description {
margin-top: 4px;
@include body-1-regular($gray-5);
}

&.disabled {
&.mat-radio-checked .mat-radio-container .mat-radio-outer-circle {
background: $gray-3;
Expand All @@ -82,9 +87,32 @@
color: $gray-5;
}
}

&.column {
.mat-radio-label-content {
display: flex;
flex-direction: column;

.radio-button-description {
white-space: break-spaces;
}
}
}

&.row {
max-width: 50%;
.mat-radio-label-content {
display: flex;
flex-direction: column;

.radio-button-description {
white-space: break-spaces;
}
}
}
}

.radio-button:last-child {
margin-bottom: 0px;
margin-bottom: 0;
}
}
22 changes: 22 additions & 0 deletions projects/components/src/radio/radio-group.component.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,28 @@ describe('Radio component', () => {
expect(logSpy).not.toHaveBeenCalled();
});

test('should display description if provided', () => {
spectator = createHost(`<ht-radio-group [title]="title" [options]="options"></ht-radio-group>`, {
hostProps: {
title: 'test',
options: [
{
label: 'TEST1',
value: 'test1',
description: 'description-1'
},
{
label: 'TEST2',
value: 'test2'
}
]
}
});

expect(spectator.queryAll('.radio-button-description').length).toBe(1);
expect(spectator.queryAll('.radio-button-description')[0]).toHaveText('description-1');
});

test('should apply disabled attribute when disabled', () => {
spectator = createHost(`<ht-radio-group [title]="title" [disabled]="disabled"></ht-radio-group>`, {
hostProps: {
Expand Down
7 changes: 4 additions & 3 deletions projects/components/src/radio/radio-group.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { RadioOption } from './radio-option';
styleUrls: ['./radio-group.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<ht-label class="title" [label]="this.title"></ht-label>
<ht-label *ngIf="this.title" class="title" [label]="this.title"></ht-label>
<mat-radio-group
class="radio-group"
[ngClass]="this.optionsDirection"
Expand All @@ -17,12 +17,13 @@ import { RadioOption } from './radio-option';
[disabled]="this.disabled"
>
<mat-radio-button
*ngFor="let option of options"
class="radio-button"
[ngClass]="{ disabled: this.disabled }"
*ngFor="let option of options"
[ngClass]="[this.optionsDirection, this.disabled ? 'disabled' : '']"
[value]="option.value"
>
<ht-label class="radio-button-label" [label]="option.label"></ht-label>
<span *ngIf="option.description" class="radio-button-description">{{ option.description }}</span>
</mat-radio-button>
</mat-radio-group>
`
Expand Down
1 change: 1 addition & 0 deletions projects/components/src/radio/radio-option.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export interface RadioOption {
value: string;
label: string;
description?: string;
}