Skip to content

Commit 3c36e74

Browse files
authored
feat: add support for description in radio button (#946)
* feat: add support for description in radio button
1 parent 6cca58d commit 3c36e74

File tree

4 files changed

+57
-5
lines changed

4 files changed

+57
-5
lines changed

projects/components/src/radio/radio-group.component.scss

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
}
3636

3737
.mat-radio-outer-circle {
38-
border-width: 0px;
38+
border-width: 0;
3939
}
4040

4141
.mat-radio-inner-circle {
@@ -69,6 +69,11 @@
6969
@include body-2-regular($gray-7);
7070
}
7171

72+
.radio-button-description {
73+
margin-top: 4px;
74+
@include body-1-regular($gray-5);
75+
}
76+
7277
&.disabled {
7378
&.mat-radio-checked .mat-radio-container .mat-radio-outer-circle {
7479
background: $gray-3;
@@ -82,9 +87,32 @@
8287
color: $gray-5;
8388
}
8489
}
90+
91+
&.column {
92+
.mat-radio-label-content {
93+
display: flex;
94+
flex-direction: column;
95+
96+
.radio-button-description {
97+
white-space: break-spaces;
98+
}
99+
}
100+
}
101+
102+
&.row {
103+
max-width: 50%;
104+
.mat-radio-label-content {
105+
display: flex;
106+
flex-direction: column;
107+
108+
.radio-button-description {
109+
white-space: break-spaces;
110+
}
111+
}
112+
}
85113
}
86114

87115
.radio-button:last-child {
88-
margin-bottom: 0px;
116+
margin-bottom: 0;
89117
}
90118
}

projects/components/src/radio/radio-group.component.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,28 @@ describe('Radio component', () => {
3434
expect(logSpy).not.toHaveBeenCalled();
3535
});
3636

37+
test('should display description if provided', () => {
38+
spectator = createHost(`<ht-radio-group [title]="title" [options]="options"></ht-radio-group>`, {
39+
hostProps: {
40+
title: 'test',
41+
options: [
42+
{
43+
label: 'TEST1',
44+
value: 'test1',
45+
description: 'description-1'
46+
},
47+
{
48+
label: 'TEST2',
49+
value: 'test2'
50+
}
51+
]
52+
}
53+
});
54+
55+
expect(spectator.queryAll('.radio-button-description').length).toBe(1);
56+
expect(spectator.queryAll('.radio-button-description')[0]).toHaveText('description-1');
57+
});
58+
3759
test('should apply disabled attribute when disabled', () => {
3860
spectator = createHost(`<ht-radio-group [title]="title" [disabled]="disabled"></ht-radio-group>`, {
3961
hostProps: {

projects/components/src/radio/radio-group.component.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { RadioOption } from './radio-option';
88
styleUrls: ['./radio-group.component.scss'],
99
changeDetection: ChangeDetectionStrategy.OnPush,
1010
template: `
11-
<ht-label class="title" [label]="this.title"></ht-label>
11+
<ht-label *ngIf="this.title" class="title" [label]="this.title"></ht-label>
1212
<mat-radio-group
1313
class="radio-group"
1414
[ngClass]="this.optionsDirection"
@@ -17,12 +17,13 @@ import { RadioOption } from './radio-option';
1717
[disabled]="this.disabled"
1818
>
1919
<mat-radio-button
20-
*ngFor="let option of options"
2120
class="radio-button"
22-
[ngClass]="{ disabled: this.disabled }"
21+
*ngFor="let option of options"
22+
[ngClass]="[this.optionsDirection, this.disabled ? 'disabled' : '']"
2323
[value]="option.value"
2424
>
2525
<ht-label class="radio-button-label" [label]="option.label"></ht-label>
26+
<span *ngIf="option.description" class="radio-button-description">{{ option.description }}</span>
2627
</mat-radio-button>
2728
</mat-radio-group>
2829
`
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export interface RadioOption {
22
value: string;
33
label: string;
4+
description?: string;
45
}

0 commit comments

Comments
 (0)