Skip to content

Commit f3d8312

Browse files
committed
feat(radio-group): group label styles
1 parent f72d834 commit f3d8312

File tree

5 files changed

+125
-3
lines changed

5 files changed

+125
-3
lines changed

projects/igniteui-angular/src/lib/core/styles/components/label/_label-theme.scss

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111

1212
/// @param {Map} $schema [$light-material-schema] - The schema used as basis for styling the component.
1313
/// @param {Map} $color [null] - The text color.
14+
/// @param {Map} $disabled-color [null] - The disabled text color.
1415
@function label-theme(
1516
$schema: $light-material-schema,
16-
$color: null
17+
$color: null,
18+
$disabled-color: null,
1719
) {
1820
$name: 'igx-label';
1921
$selector: '[igxLabel]';
@@ -31,6 +33,7 @@
3133
name: $name,
3234
selector: $selector,
3335
color: $color,
36+
disabled-color: $disabled-color,
3437
theme: map.get($schema, '_meta', 'theme'),
3538
variant: map.get($schema, '_meta', 'theme'),
3639
));

projects/igniteui-angular/src/lib/core/styles/components/radio/_radio-component.scss

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@
115115
@include e(label) {
116116
@extend %radio-label--disabled !optional;
117117
}
118+
119+
@include e(label, $m: before) {
120+
@extend %radio-label--disabled !optional;
121+
}
118122
}
119123

120124
@include m(invalid) {
@@ -217,5 +221,13 @@
217221
@include m(vertical) {
218222
@extend %radio-group-display--vertical !optional;
219223
}
224+
225+
@include m(before) {
226+
@extend %radio-group-display--before !optional;
227+
}
228+
229+
@include m(disabled) {
230+
@extend %radio-group-display--disabled !optional;
231+
}
220232
}
221233
}

projects/igniteui-angular/src/lib/core/styles/components/radio/_radio-theme.scss

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,11 @@
601601
%radio-display:not(:last-of-type) {
602602
margin-inline-end: $horizontal-group-margin;
603603
}
604+
605+
[igxLabel] {
606+
display: block;
607+
margin-block-end: rem(16px);
608+
}
604609
}
605610

606611
%radio-group-display--vertical {
@@ -611,6 +616,18 @@
611616
margin-block-end: $vertical-group-margin;
612617
}
613618
}
619+
620+
%radio-group-display--disabled {
621+
[igxLabel] {
622+
color: var-get($theme, 'disabled-color');
623+
}
624+
}
625+
626+
%radio-group-display--before {
627+
[igxLabel] {
628+
text-align: end;
629+
}
630+
}
614631
}
615632

616633
/// Adds typography styles for the igx-radio component.

projects/igniteui-angular/src/lib/directives/radio/radio-group.directive.ts

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {
22
AfterContentInit,
33
AfterViewInit,
44
ChangeDetectorRef,
5-
ContentChildren, Directive, DoCheck, EventEmitter, HostBinding, HostListener, Input, OnDestroy, Optional, Output, QueryList, Self, booleanAttribute
5+
ContentChildren, Directive, DoCheck, EventEmitter, HostBinding, HostListener, Input, OnDestroy, Optional, Output, QueryList, Self, booleanAttribute, AfterViewChecked
66
} from '@angular/core';
77
import { ControlValueAccessor, NgControl, Validators } from '@angular/forms';
88
import { fromEvent, noop, Subject } from 'rxjs';
@@ -51,7 +51,7 @@ let nextId = 0;
5151
selector: 'igx-radio-group, [igxRadioGroup]',
5252
standalone: true
5353
})
54-
export class IgxRadioGroupDirective implements AfterContentInit, AfterViewInit, ControlValueAccessor, OnDestroy, DoCheck {
54+
export class IgxRadioGroupDirective implements AfterContentInit, AfterViewInit, ControlValueAccessor, OnDestroy, DoCheck, AfterViewChecked {
5555
/**
5656
* Returns reference to the child radio buttons.
5757
*
@@ -195,6 +195,26 @@ export class IgxRadioGroupDirective implements AfterContentInit, AfterViewInit,
195195
@HostBinding('class.igx-radio-group--vertical')
196196
private vertical = false;
197197

198+
/**
199+
* A css class applied to the component if any of the
200+
* child radio buttons labelPosition is set to `before`.
201+
*
202+
* @hidden
203+
* @internal
204+
*/
205+
@HostBinding('class.igx-radio-group--before')
206+
private _labelBefore = false;
207+
208+
/**
209+
* A css class applied to the component if all
210+
* child radio buttons are disabled.
211+
*
212+
* @hidden
213+
* @internal
214+
*/
215+
@HostBinding('class.igx-radio-group--disabled')
216+
private _disabled = false;
217+
198218
@HostListener('click', ['$event'])
199219
protected handleClick(event: MouseEvent) {
200220
event.stopPropagation();
@@ -325,6 +345,11 @@ export class IgxRadioGroupDirective implements AfterContentInit, AfterViewInit,
325345
* @internal
326346
*/
327347
private queryChange$ = new Subject<void>();
348+
/**
349+
* @hidden
350+
* @internal
351+
*/
352+
private _lastDisabledState = false;
328353

329354
/**
330355
* @hidden
@@ -348,6 +373,17 @@ export class IgxRadioGroupDirective implements AfterContentInit, AfterViewInit,
348373
}
349374
});
350375
}
376+
377+
this.updateDisabled();
378+
this.getLabelPosition();
379+
}
380+
381+
/**
382+
* @hidden
383+
* @internal
384+
*/
385+
public ngAfterViewChecked() {
386+
this.updateDisabled();
351387
}
352388

353389
/**
@@ -382,6 +418,37 @@ export class IgxRadioGroupDirective implements AfterContentInit, AfterViewInit,
382418
}
383419
}
384420

421+
/**
422+
* @hidden
423+
* @internal
424+
*/
425+
private getDisabled(): boolean {
426+
return this.radioButtons?.toArray().every(button => button.disabled);
427+
}
428+
429+
/**
430+
* @hidden
431+
* @internal
432+
*/
433+
private updateDisabled() {
434+
const allDisabled = this.getDisabled();
435+
436+
if (this._lastDisabledState !== allDisabled) {
437+
this._lastDisabledState = allDisabled;
438+
setTimeout(() => {
439+
this._disabled = allDisabled;
440+
});
441+
}
442+
}
443+
444+
/**
445+
* @hidden
446+
* @internal
447+
*/
448+
private getLabelPosition() {
449+
this._labelBefore = this.radioButtons?.some(button => button.labelPosition === 'before') ?? false;
450+
}
451+
385452
/**
386453
* @hidden
387454
* @internal
@@ -414,6 +481,7 @@ export class IgxRadioGroupDirective implements AfterContentInit, AfterViewInit,
414481

415482
public ngDoCheck(): void {
416483
this._updateTabIndex();
484+
this.getLabelPosition();
417485
}
418486

419487
private _updateTabIndex() {

src/app/input-controls/input-controls.sample.html

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,28 @@ <h4 class="sample-title">Angular Inputs</h4>
4949
[value]="properties.value? properties.value : 'Bar'">Bar</igx-radio>
5050
</igx-radio-group>
5151
</article>
52+
53+
54+
<article>
55+
<strong>Angular Radio Group with Label</strong>
56+
<i>* When any of the buttons label position is "before",
57+
<br> the group label should be right-aligned.</i>
58+
59+
<igx-radio-group [alignment]="alignment">
60+
<label igxLabel>Radio Group Label</label>
61+
<igx-radio
62+
[checked]="properties.checked"
63+
[disabled]="properties.disabled"
64+
[invalid]="properties.invalid"
65+
>Radio Button 1</igx-radio>
66+
67+
<igx-radio
68+
[disabled]="properties.disabled"
69+
[invalid]="properties.invalid"
70+
[labelPosition]="properties.labelPosition"
71+
>Radio Button 2</igx-radio>
72+
</igx-radio-group>
73+
</article>
5274
</div>
5375

5476
<div class="wc-inputs">

0 commit comments

Comments
 (0)