Skip to content

Commit 38f26ec

Browse files
authored
Merge branch '17.0.x' into bpachilova/fix-13762-17.0.x
2 parents cdaade7 + 0e61a7d commit 38f26ec

File tree

5 files changed

+109
-20
lines changed

5 files changed

+109
-20
lines changed

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

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -366,21 +366,25 @@ export class IgxButtonGroupComponent extends DisplayDensityBase implements After
366366
this.selectedIndexes.push(index);
367367
}
368368

369-
this._renderer.setAttribute(button.nativeElement, 'aria-pressed', 'true');
370-
this._renderer.addClass(button.nativeElement, 'igx-button-group__item--selected');
369+
if (button.selected) {
370+
this._renderer.setAttribute(button.nativeElement, 'aria-pressed', 'true');
371+
this._renderer.addClass(button.nativeElement, 'igx-button-group__item--selected');
371372

372-
const indexInViewButtons = this.viewButtons.toArray().indexOf(button);
373-
if (indexInViewButtons !== -1) {
373+
const indexInViewButtons = this.viewButtons.toArray().indexOf(button);
374+
if (indexInViewButtons !== -1) {
374375
this.values[indexInViewButtons].selected = true;
375-
}
376+
}
376377

377-
// deselect other buttons if selectionMode is not multi
378-
if (this.selectionMode !== 'multi' && this.selectedIndexes.length > 1) {
379-
this.buttons.forEach((_, i) => {
380-
if (i !== index && this.selectedIndexes.indexOf(i) !== -1) {
381-
this.deselectButton(i);
382-
}
383-
});
378+
// deselect other buttons if selectionMode is not multi
379+
if (this.selectionMode !== 'multi' && this.selectedIndexes.length > 1) {
380+
this.buttons.forEach((_, i) => {
381+
if (i !== index && this.selectedIndexes.indexOf(i) !== -1) {
382+
this.deselectButton(i);
383+
}
384+
});
385+
}
386+
} else {
387+
this.deselectButton(index);
384388
}
385389
}
386390

@@ -508,4 +512,4 @@ export interface IButtonGroupEventArgs extends IBaseEventArgs {
508512
owner: IgxButtonGroupComponent;
509513
button: IgxButtonDirective;
510514
index: number;
511-
}
515+
}

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

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { NoopAnimationsModule } from '@angular/platform-browser/animations';
66
import { UIInteractions } from '../test-utils/ui-interactions.spec';
77
import { IgxButtonDirective } from '../directives/button/button.directive';
88
import { getComponentSize } from '../core/utils';
9+
import { NgFor } from '@angular/common';
910

1011
interface IButton {
1112
type?: string;
@@ -54,7 +55,8 @@ describe('IgxButtonGroup', () => {
5455
InitButtonGroupWithValuesComponent,
5556
TemplatedButtonGroupComponent,
5657
TemplatedButtonGroupDesplayDensityComponent,
57-
ButtonGroupWithSelectedButtonComponent
58+
ButtonGroupWithSelectedButtonComponent,
59+
ButtonGroupButtonWithBoundSelectedOutputComponent,
5860
]
5961
}).compileComponents();
6062
}));
@@ -358,6 +360,22 @@ describe('IgxButtonGroup', () => {
358360
}
359361
});
360362

363+
it('should style the corresponding button as deselected when the value bound to the selected input changes', () => {
364+
const fixture = TestBed.createComponent(ButtonGroupButtonWithBoundSelectedOutputComponent);
365+
fixture.detectChanges();
366+
367+
const btnGroupInstance = fixture.componentInstance.buttonGroup;
368+
369+
expect(btnGroupInstance.selectedButtons.length).toBe(1);
370+
expect(btnGroupInstance.buttons[1].selected).toBe(true);
371+
372+
fixture.componentInstance.selectedValue = 100;
373+
fixture.detectChanges();
374+
375+
expect(btnGroupInstance.selectedButtons.length).toBe(0);
376+
expect(btnGroupInstance.buttons[1].selected).toBe(false);
377+
});
378+
361379
});
362380

363381
@Component({
@@ -484,3 +502,24 @@ class TemplatedButtonGroupDesplayDensityComponent {
484502
class ButtonGroupWithSelectedButtonComponent {
485503
@ViewChild(IgxButtonGroupComponent, { static: true }) public buttonGroup: IgxButtonGroupComponent;
486504
}
505+
506+
@Component({
507+
template: `
508+
<igx-buttongroup>
509+
<button igxButton *ngFor="let item of items" [selected]="item.key === selectedValue">{{item.value}}</button>
510+
</igx-buttongroup>
511+
`,
512+
standalone: true,
513+
imports: [ IgxButtonGroupComponent, IgxButtonDirective, NgFor ]
514+
})
515+
class ButtonGroupButtonWithBoundSelectedOutputComponent {
516+
@ViewChild(IgxButtonGroupComponent, { static: true }) public buttonGroup: IgxButtonGroupComponent;
517+
518+
public items = [
519+
{ key: 0, value: 'Button 1' },
520+
{ key: 1, value: 'Button 2' },
521+
{ key: 2, value: 'Button 3' },
522+
];
523+
524+
public selectedValue = 1;
525+
}

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,12 @@ export class IgxButtonDirective extends DisplayDensityBase {
127127
@Input({ transform: booleanAttribute })
128128
public set selected(value: boolean) {
129129
if (this._selected !== value) {
130-
if (!this._selected) {
131-
this.buttonSelected.emit({
132-
button: this
133-
});
134-
}
135130

136131
this._selected = value;
132+
133+
this.buttonSelected.emit({
134+
button: this
135+
});
137136
}
138137
}
139138

projects/igniteui-angular/src/lib/grids/grid/grid-row-selection.spec.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,53 @@ describe('IgxGrid - Row Selection #grid', () => {
543543
}
544544
});
545545

546+
it('Should select the correct rows with Shift + Click when grouping is activated', () => {
547+
expect(grid.selectRowOnClick).toBe(true);
548+
spyOn(grid.rowSelectionChanging, 'emit').and.callThrough();
549+
550+
grid.groupBy({
551+
fieldName: 'ProductName', dir: SortingDirection.Desc, ignoreCase: false
552+
});
553+
554+
fix.detectChanges();
555+
556+
const firstGroupRow = grid.gridAPI.get_row_by_index(1);
557+
const lastGroupRow = grid.gridAPI.get_row_by_index(4);
558+
559+
// Clicking on the first row within a group
560+
UIInteractions.simulateClickEvent(firstGroupRow.nativeElement);
561+
fix.detectChanges();
562+
563+
GridSelectionFunctions.verifyRowSelected(firstGroupRow);
564+
565+
// Simulate Shift+Click on a row within another group
566+
const mockEvent = new MouseEvent('click', { shiftKey: true });
567+
lastGroupRow.nativeElement.dispatchEvent(mockEvent);
568+
fix.detectChanges();
569+
570+
expect(grid.selectedRows).toEqual([5, 14, 8]); // ids
571+
expect(grid.rowSelectionChanging.emit).toHaveBeenCalledTimes(2);
572+
expect(grid.rowSelectionChanging.emit).toHaveBeenCalledWith({
573+
added: [grid.dataView[2], grid.dataView[4]],
574+
cancel: false,
575+
event: jasmine.anything(),
576+
newSelection: [grid.dataView[1], grid.dataView[2], grid.dataView[4]],
577+
oldSelection: [grid.dataView[1]],
578+
removed: [],
579+
allRowsSelected: false,
580+
owner: grid
581+
});
582+
583+
const expectedSelectedRowIds = [5, 14, 8];
584+
grid.dataView.forEach((rowData, index) => {
585+
if (expectedSelectedRowIds.includes(rowData.ProductID)) {
586+
const row = grid.gridAPI.get_row_by_index(index);
587+
GridSelectionFunctions.verifyRowSelected(row);
588+
}
589+
});
590+
591+
});
592+
546593
it('Should NOT select multiple rows with Shift + Click when selectRowOnClick has false value', () => {
547594
grid.selectRowOnClick = false;
548595
spyOn(grid.rowSelectionChanging, 'emit').and.callThrough();

projects/igniteui-angular/src/lib/grids/selection/selection.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ export class IgxGridSelectionService {
689689
/** Returns all data in the grid, with applied filtering and sorting and without deleted rows. */
690690
public get allData(): Array<any> {
691691
let allData;
692-
if (this.isFilteringApplied() || this.grid.sortingExpressions.length) {
692+
if (this.isFilteringApplied() || this.grid.sortingExpressions.length || this.grid.groupingExpressions?.length) {
693693
allData = this.grid.pinnedRecordsCount ? this.grid._filteredSortedUnpinnedData : this.grid.filteredSortedData;
694694
} else {
695695
allData = this.grid.gridAPI.get_all_data(true);

0 commit comments

Comments
 (0)