Skip to content

Commit cb0ce2c

Browse files
authored
Merge pull request #5767 from IgniteUI/ddimitrov/fix-5765-8.1.x
Fix button group keyboard navigation
2 parents cab508f + 9fc1a46 commit cb0ce2c

File tree

4 files changed

+55
-7
lines changed

4 files changed

+55
-7
lines changed

projects/igniteui-angular/src/lib/buttonGroup/buttonGroup.component.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ export class IgxButtonGroupComponent extends DisplayDensityBase implements After
7878
@Input()
7979
public id = `igx-buttongroup-${NEXT_ID++}`;
8080

81+
/**
82+
* @hidden
83+
*/
84+
@HostBinding('style.zIndex')
85+
public zIndex = 0;
86+
8187
/**
8288
* Allows you to set a style using the `itemContentCssClass` input.
8389
* The value should be the CSS class name that will be applied to the button group.
@@ -251,7 +257,7 @@ export class IgxButtonGroupComponent extends DisplayDensityBase implements After
251257

252258
constructor(private _cdr: ChangeDetectorRef, private _renderer: Renderer2,
253259
@Optional() @Inject(DisplayDensityToken) protected _displayDensityOptions: IDisplayDensityOptions) {
254-
super(_displayDensityOptions);
260+
super(_displayDensityOptions);
255261
}
256262

257263
/**
@@ -360,7 +366,7 @@ export class IgxButtonGroupComponent extends DisplayDensityBase implements After
360366
* @hidden
361367
*/
362368
public ngAfterContentInit() {
363-
this.templateButtons.forEach( (button) => {
369+
this.templateButtons.forEach((button) => {
364370
if (!button.initialDensity) {
365371
button.displayDensity = this.displayDensity;
366372
}
Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
<div class="igx-button-group" role="group" [class.igx-button-group--vertical]="isVertical">
2-
<span *ngFor="let button of values; let i = 'index'" type="button" igxButton="flat" [displayDensity]="displayDensity" [selected]="button.selected"
3-
[attr.data-togglable]="button.togglable" [disabled]="disabled || button.disabled" [igxButtonColor]="button.color"
4-
[igxButtonBackground]="button.bgcolor" [igxLabel]="button.label" [igxRipple]="button.ripple">
2+
<button *ngFor="let button of values; let i = 'index'"
3+
type="button"
4+
igxButton="flat"
5+
[displayDensity]="displayDensity"
6+
[selected]="button.selected"
7+
[attr.data-togglable]="button.togglable"
8+
[disabled]="disabled || button.disabled"
9+
[igxButtonColor]="button.color"
10+
[igxButtonBackground]="button.bgcolor"
11+
[igxLabel]="button.label"
12+
[igxRipple]="button.ripple"
13+
>
514
<div class="igx-button-group__item-content {{ itemContentCssClass }}">
615
<igx-icon *ngIf="button.icon" fontSet="material">{{button.icon}}</igx-icon>
716
<span *ngIf="button.label">{{button.label}}</span>
817
</div>
9-
</span>
18+
</button>
1019
<ng-content></ng-content>
1120
</div>

projects/igniteui-angular/src/lib/buttonGroup/buttongroup.component.spec.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,25 @@ describe('IgxButtonGroup', () => {
232232
expect(groupChildren[1].element.nativeElement.classList.contains('igx-button--cosy')).toBe(true, 'Missing density class!');
233233
});
234234

235+
it('Button Group - should support tab navigation', () => {
236+
const fixture = TestBed.createComponent(InitButtonGroupWithValuesComponent);
237+
fixture.detectChanges();
238+
239+
const buttongroup = fixture.componentInstance.buttonGroup;
240+
const groupChildren = buttongroup.buttons;
241+
242+
for (let i = 0; i < groupChildren.length; i++) {
243+
const button = groupChildren[i];
244+
expect(button.nativeElement.tagName).toBe('BUTTON');
245+
246+
if (i < groupChildren.length - 1) {
247+
expect(button.nativeElement.disabled).toBe(false);
248+
} else {
249+
expect(button.nativeElement.disabled).toBe(true);
250+
}
251+
}
252+
});
253+
235254
});
236255

237256
@Component({ template: `<igx-buttongroup [values]="buttons"></igx-buttongroup>` })

projects/igniteui-angular/src/lib/directives/button/button.directive.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ export class IgxButtonDirective extends DisplayDensityBase {
4848
*/
4949
private _backgroundColor: string;
5050

51+
/**
52+
*@hidden
53+
*/
54+
private _disabled: boolean;
55+
5156
constructor(public element: ElementRef, private _renderer: Renderer2,
5257
@Optional() @Inject(DisplayDensityToken) protected _displayDensityOptions: IDisplayDensityOptions) {
5358
super(_displayDensityOptions);
@@ -141,6 +146,7 @@ export class IgxButtonDirective extends DisplayDensityBase {
141146
*/
142147
@Input() set disabled(val) {
143148
val = !!val;
149+
this._disabled = val;
144150
if (val) {
145151
this._renderer.addClass(this.nativeElement, `${this._cssClassPrefix}--disabled`);
146152
} else {
@@ -182,6 +188,14 @@ export class IgxButtonDirective extends DisplayDensityBase {
182188
return this._type === 'fab' && this.displayDensity === DisplayDensity.compact;
183189
}
184190

191+
/**
192+
* @hidden
193+
*/
194+
@HostBinding('attr.disabled')
195+
public get disabledAttribute() {
196+
return this._disabled ? this._disabled : null;
197+
}
198+
185199
/**
186200
* Gets or sets whether the button is selected.
187201
* Mainly used in the IgxButtonGroup component and it will have no effect if set separately.
@@ -195,7 +209,7 @@ export class IgxButtonDirective extends DisplayDensityBase {
195209
/**
196210
*@hidden
197211
*/
198-
@HostListener('click', ['$event'])
212+
@HostListener('click', ['$event'])
199213
public onClick(ev) {
200214
this.buttonClick.emit(ev);
201215
}

0 commit comments

Comments
 (0)