Skip to content

Commit aa42a26

Browse files
authored
Merge pull request #8727 from IgniteUI/SIvanova/vertical-radio-group
feat(radio-group): add vertical alignment
2 parents 8c114d2 + f4f46d4 commit aa42a26

File tree

5 files changed

+65
-5
lines changed

5 files changed

+65
-5
lines changed

CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ All notable changes for each version of this project will be documented in this
77
- `IgxDropDown`
88
- The `igx-drop-down-item` now allows for `igxPrefix`, `igxSuffix` and `igx-divider` directives to be passed as `ng-content` and they will be renderer accordingly in the item's content.
99
### General
10-
- `IgxCalendar`
11-
- A new string enumeration `IgxCalendarView` is exported. Either the new one or the current `CalendarView` can be used. `CalendarView` will be deprecated in a future release.
10+
- `IgxCalendar`
11+
- A new string enumeration `IgxCalendarView` is exported. Either the new one or the current `CalendarView` can be used. `CalendarView` will be deprecated in a future release.
12+
- `IgxRadioGroup`
13+
- Added new property `alignment` that determines the radio group alignment. Available options are `horizontal` (default) and `vertical`.
1214

1315
## 11.0.4
1416

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,9 @@
121121

122122
@include b(igx-radio-group) {
123123
display: block;
124+
125+
@include m(vertical) {
126+
display: flex;
127+
flex-flow: column;
128+
}
124129
}

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

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ import { IgxRadioComponent, RadioLabelPosition, IChangeRadioEventArgs } from '..
1515
import { IgxRippleModule } from '../ripple/ripple.directive';
1616
import { takeUntil } from 'rxjs/operators';
1717
import { Subject } from 'rxjs';
18+
import { mkenum } from '../../core/utils';
19+
20+
/**
21+
* Determines the Radio Group alignment
22+
*/
23+
export const RadioGroupAlignment = mkenum({
24+
horizontal: 'horizontal',
25+
vertical: 'vertical'
26+
});
27+
export type RadioGroupAlignment = (typeof RadioGroupAlignment)[keyof typeof RadioGroupAlignment];
1828

1929
const noop = () => { };
2030
let nextId = 0;
@@ -189,6 +199,47 @@ export class IgxRadioGroupDirective implements AfterContentInit, ControlValueAcc
189199
@HostBinding('class.igx-radio-group')
190200
public cssClass = 'igx-radio-group';
191201

202+
/**
203+
* Sets vertical alignment to the radio group, if `alignment` is set to `vertical`.
204+
* By default the alignment is horizontal.
205+
*
206+
* @example
207+
* ```html
208+
* <igx-radio-group alignment="vertical"></igx-radio-group>
209+
* ```
210+
*/
211+
@HostBinding('class.igx-radio-group--vertical')
212+
private vertical = false;
213+
214+
/**
215+
* Returns the alignment of the `igx-radio-group`.
216+
* ```typescript
217+
* @ViewChild("MyRadioGroup")
218+
* public radioGroup: IgxRadioGroupDirective;
219+
* ngAfterViewInit(){
220+
* let radioAlignment = this.radioGroup.alignment;
221+
* }
222+
* ```
223+
*/
224+
@Input()
225+
get alignment(): RadioGroupAlignment {
226+
return this.vertical ? RadioGroupAlignment.vertical : RadioGroupAlignment.horizontal;
227+
}
228+
/**
229+
* Allows you to set the radio group alignment.
230+
* Available options are `RadioGroupAlignment.horizontal` (default) and `RadioGroupAlignment.vertical`.
231+
* ```typescript
232+
* public alignment = RadioGroupAlignment.vertical;
233+
* //..
234+
* ```
235+
* ```html
236+
* <igx-radio-group [alignment]="alignment"></igx-radio-group>
237+
* ```
238+
*/
239+
set alignment (value: RadioGroupAlignment) {
240+
this.vertical = value === RadioGroupAlignment.vertical;
241+
}
242+
192243
/**
193244
* @hidden
194245
* @internal

src/app/radio/radio.sample.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ <h6 igxCardHeaderTitle>Reserve your dream vacation at {{ opt }}</h6>
3131
</section>
3232
<section class="sample-content">
3333
<article class="sample-column">
34-
<h4 class="sample-title">Radio group without data model</h4>
35-
<igx-radio-group #radioGroupZZ name="radiogroupZZ" value="Bar" required="true" (change)="onRadioChange($event)">
34+
<h4 class="sample-title">Radio group without data model (Vertical Alignment)</h4>
35+
<igx-radio-group #radioGroupZZ name="radiogroupZZ" value="Bar" required="true" (change)="onRadioChange($event)" [alignment]="alignment">
3636
<igx-radio class="radio-sample" *ngFor="let item of ['Foo', 'Bar', 'Baz']" value="{{item}}">
3737
{{item}}
3838
</igx-radio>

src/app/radio/radio.sample.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Component, ViewChild, AfterContentInit } from '@angular/core';
2-
import { IgxRadioGroupDirective } from 'igniteui-angular';
2+
import { IgxRadioGroupDirective, RadioGroupAlignment } from 'igniteui-angular';
33
import { FormGroup, FormBuilder } from '@angular/forms';
44

55
class Person {
@@ -38,6 +38,8 @@ export class RadioSampleComponent implements AfterContentInit {
3838
personKirk: Person = new Person('Kirk', this.seasons[1]);
3939
personKirkForm: FormGroup;
4040

41+
alignment = RadioGroupAlignment.vertical;
42+
4143
constructor(private _formBuilder: FormBuilder) {
4244
this._createPersonKirkForm();
4345
}

0 commit comments

Comments
 (0)