Skip to content

Commit 1b69d57

Browse files
authored
Merge branch 'master' into mkirova/fix-default-row-height
2 parents 4dbb51a + 5f3dbea commit 1b69d57

File tree

8 files changed

+97
-11
lines changed

8 files changed

+97
-11
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ All notable changes for each version of this project will be documented in this
1414
- Added templatable row dimension headers displayed on the top, above all row headers.
1515
- Replace the `showPivotConfigurationUI` property with `pivotUI` property, adding ability now to enable/disable the configuration UI and/or the new row dimension headers.
1616
- Added `sortable` property for each IPivotDimension.
17+
- `IgxOverlayService`, `IgxToggleDirective`:
18+
- Added an optional `offsetMode` parameter to the `setOffset` method that determines whether to add (by default) or set the offset values using `OffsetMode.Add` and `OffsetMode.Set`.
19+
1720
### Changes
1821
- With the removal of the Display Density token, components now get their default sizes from the theme. Default sizes have changed for most components, with it now being medium (previously large). Here's an exhaustive list of all sizable components and their default sizes by theme:
1922
- `Avatar` - Small (All Themes)

projects/igniteui-angular/src/lib/directives/toggle/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ handlers when the toggle is opened and respectively closed.
5252
| `close` | --- | `void` | Closes the toggle. |
5353
| `toggle` | overlaySettings?: `OverlaySettings` | `void` | Closes the toggle. |
5454
| `reposition` | --- | `void` | Repositions the toggle. |
55-
| `setOffset` | Offsets the content along the corresponding axis by the provided amount. |deltaX, deltaY |
55+
| `setOffset` | deltaX: `number`, deltaY: `number`, offsetMode?: `OffsetMode` | `void` | Offsets the content along the corresponding axis by the provided amount with optional offsetMode that determines whether to add (by default) or set the offset values with OffsetMode.Add and OffsetMode.Set. |
5656

5757

5858

projects/igniteui-angular/src/lib/directives/toggle/toggle.directive.spec.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { CancelableEventArgs } from '../../core/utils';
1111

1212
import { configureTestSuite } from '../../test-utils/configure-suite';
1313
import { first } from 'rxjs/operators';
14+
import { OffsetMode } from '../../services/overlay/utilities';
1415

1516
describe('IgxToggle', () => {
1617
configureTestSuite();
@@ -213,6 +214,34 @@ describe('IgxToggle', () => {
213214
expect(toggle.closed.emit).toHaveBeenCalled();
214215
}));
215216

217+
it('should offset the toggle content correctly using setOffset method and optional offsetMode', () => {
218+
const fixture = TestBed.createComponent(IgxToggleActionTestComponent);
219+
const component = fixture.componentInstance;
220+
const toggle = component.toggle;
221+
const overlayId = toggle.overlayId;
222+
fixture.detectChanges();
223+
224+
const overlayService = TestBed.inject(IgxOverlayService);
225+
spyOn(overlayService, 'setOffset').and.callThrough();
226+
fixture.detectChanges();
227+
228+
// Set initial offset
229+
toggle.setOffset(20, 20);
230+
expect(overlayService.setOffset).toHaveBeenCalledWith(overlayId, 20, 20, undefined);
231+
232+
// Add offset values to the existing ones (default behavior)
233+
toggle.setOffset(10, 10);
234+
expect(overlayService.setOffset).toHaveBeenCalledWith(overlayId, 10, 10, undefined);
235+
236+
// Add offset values using OffsetMode.Add
237+
toggle.setOffset(20, 20, OffsetMode.Add);
238+
expect(overlayService.setOffset).toHaveBeenCalledWith(overlayId, 20, 20, OffsetMode.Add);
239+
240+
// Set offset values using OffsetMode.Set
241+
toggle.setOffset(10, 10, OffsetMode.Set);
242+
expect(overlayService.setOffset).toHaveBeenCalledWith(overlayId, 10, 10, OffsetMode.Set);
243+
});
244+
216245
it('Toggle should be registered into navigationService if it is passed through identifier', fakeAsync(() => {
217246
const fixture = TestBed.createComponent(IgxToggleServiceInjectComponent);
218247
fixture.detectChanges();

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { filter, first, takeUntil } from 'rxjs/operators';
1919
import { IgxNavigationService, IToggleView } from '../../core/navigation';
2020
import { IgxOverlayService } from '../../services/overlay/overlay';
2121
import { IPositionStrategy } from '../../services/overlay/position/IPositionStrategy';
22-
import { OverlayClosingEventArgs, OverlayEventArgs, OverlaySettings } from '../../services/overlay/utilities';
22+
import { OffsetMode, OverlayClosingEventArgs, OverlayEventArgs, OverlaySettings } from '../../services/overlay/utilities';
2323
import { Subscription, Subject, MonoTypeOperatorFunction } from 'rxjs';
2424

2525
export interface ToggleViewEventArgs extends IBaseEventArgs {
@@ -318,10 +318,11 @@ export class IgxToggleDirective implements IToggleView, OnInit, OnDestroy {
318318
}
319319

320320
/**
321-
* Offsets the content along the corresponding axis by the provided amount
321+
* Offsets the content along the corresponding axis by the provided amount with optional
322+
* offsetMode that determines whether to add (by default) or set the offset values with OffsetMode.Add and OffsetMode.Set
322323
*/
323-
public setOffset(deltaX: number, deltaY: number) {
324-
this.overlayService.setOffset(this._overlayId, deltaX, deltaY);
324+
public setOffset(deltaX: number, deltaY: number, offsetMode?: OffsetMode) {
325+
this.overlayService.setOffset(this._overlayId, deltaX, deltaY, offsetMode);
325326
}
326327

327328
/**

projects/igniteui-angular/src/lib/services/overlay/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ this.overlay.show(component, overlaySettings);
9999
|detach | Remove overlay with the provided id |id |
100100
|detachAll | Remove all the overlays |- |
101101
|reposition | Repositions the native element of the component with provided id |id |
102-
|setOffset | Offsets the content along the corresponding axis by the provided amount |id, deltaX, deltaY |
102+
|setOffset | Offsets the content along the corresponding axis by the provided amount with optional offsetMode that determines whether to add (by default) or set the offset values with OffsetMode.Add and OffsetMode.Set | id, deltaX, deltaY, offsetMode? |
103103

104104
###### IPositionStrategy
105105

projects/igniteui-angular/src/lib/services/overlay/overlay.spec.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import { CloseScrollStrategy } from './scroll/close-scroll-strategy';
3434
import { NoOpScrollStrategy } from './scroll/NoOpScrollStrategy';
3535
import {
3636
HorizontalAlignment,
37+
OffsetMode,
3738
OverlayCancelableEventArgs,
3839
OverlayEventArgs,
3940
OverlaySettings,
@@ -847,6 +848,39 @@ describe('igxOverlay', () => {
847848
overlayInstance.detachAll();
848849
}));
849850

851+
it('Should offset the overlay content correctly using setOffset method and optional offsetMode', fakeAsync(() => {
852+
const fixture = TestBed.createComponent(WidthTestOverlayComponent);
853+
const overlayInstance = fixture.componentInstance.overlay;
854+
855+
const id = fixture.componentInstance.overlay.attach(SimpleRefComponent);
856+
overlayInstance.show(id);
857+
fixture.detectChanges();
858+
tick();
859+
860+
// Set initial offset
861+
overlayInstance.setOffset(id, 20, 20);
862+
const overlayInfo = overlayInstance.getOverlayById(id);
863+
expect(overlayInfo.transformX).toEqual(20);
864+
expect(overlayInfo.transformY).toEqual(20);
865+
866+
// Add offset values to the existing ones (default behavior)
867+
overlayInstance.setOffset(id, 10, 10);
868+
expect(overlayInfo.transformX).toEqual(30);
869+
expect(overlayInfo.transformY).toEqual(30);
870+
871+
// Add offset values using OffsetMode.Add
872+
overlayInstance.setOffset(id, 20, 20, OffsetMode.Add);
873+
expect(overlayInfo.transformX).toEqual(50);
874+
expect(overlayInfo.transformY).toEqual(50);
875+
876+
// Set offset values using OffsetMode.Set
877+
overlayInstance.setOffset(id, 10, 10, OffsetMode.Set);
878+
expect(overlayInfo.transformX).toEqual(10);
879+
expect(overlayInfo.transformY).toEqual(10);
880+
881+
overlayInstance.detachAll();
882+
}));
883+
850884
it('#1690 - click on second filter does not close first one.', fakeAsync(() => {
851885
const fixture = TestBed.createComponent(TwoButtonsComponent);
852886
const button1 = fixture.nativeElement.getElementsByClassName('buttonOne')[0];

projects/igniteui-angular/src/lib/services/overlay/overlay.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import { NoOpScrollStrategy } from './scroll/NoOpScrollStrategy';
3232
import {
3333
AbsolutePosition,
3434
HorizontalAlignment,
35+
OffsetMode,
3536
OverlayAnimationEventArgs,
3637
OverlayCancelableEventArgs,
3738
OverlayClosingEventArgs,
@@ -489,24 +490,34 @@ export class IgxOverlayService implements OnDestroy {
489490
}
490491

491492
/**
492-
* Offsets the content along the corresponding axis by the provided amount
493+
* Offsets the content along the corresponding axis by the provided amount with optional offsetMode that determines whether to add (by default) or set the offset values
493494
*
494495
* @param id Id to offset overlay for
495496
* @param deltaX Amount of offset in horizontal direction
496497
* @param deltaY Amount of offset in vertical direction
498+
* @param offsetMode Determines whether to add (by default) or set the offset values with OffsetMode.Add and OffsetMode.Set
497499
* ```typescript
498-
* this.overlay.setOffset(id, deltaX, deltaY);
500+
* this.overlay.setOffset(id, deltaX, deltaY, offsetMode);
499501
* ```
500502
*/
501-
public setOffset(id: string, deltaX: number, deltaY: number) {
503+
public setOffset(id: string, deltaX: number, deltaY: number, offsetMode?: OffsetMode) {
502504
const info: OverlayInfo = this.getOverlayById(id);
503505

504506
if (!info) {
505507
return;
506508
}
507509

508-
info.transformX += deltaX;
509-
info.transformY += deltaY;
510+
switch (offsetMode) {
511+
case OffsetMode.Set:
512+
info.transformX = deltaX;
513+
info.transformY = deltaY;
514+
break;
515+
case OffsetMode.Add:
516+
default:
517+
info.transformX += deltaX;
518+
info.transformY += deltaY;
519+
break;
520+
}
510521

511522
const transformX = info.transformX;
512523
const transformY = info.transformY;

projects/igniteui-angular/src/lib/services/overlay/utilities.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ export enum AbsolutePosition {
4747
Center = 'center'
4848
}
4949

50+
/**
51+
* Determines whether to add or set the offset values.
52+
*/
53+
export enum OffsetMode {
54+
Add,
55+
Set
56+
}
57+
5058
// TODO: make this interface
5159
export class Point {
5260
constructor(public x: number, public y: number) { }

0 commit comments

Comments
 (0)