Skip to content

Commit 197313d

Browse files
dafoLipata
authored andcommitted
feat(overlay, toggle): new setOffset method #5833 (#6082)
1 parent 2423251 commit 197313d

File tree

7 files changed

+85
-4
lines changed

7 files changed

+85
-4
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
All notable changes for each version of this project will be documented in this file.
44

5-
65
## 9.0.0
76

87
### General
@@ -17,6 +16,11 @@ All notable changes for each version of this project will be documented in this
1716
- `IgxGrid`, `IgxTreeGrid`, `IgxHierarchicalGrid`
1817
- **Behavioral Change** - Pinning columns is no longer automatically prevented when the pinning area would exceed the size of the grid.
1918

19+
### New Features
20+
- `IgxOverlayService`:
21+
- `setOffset` method added. It repositions the content in the horizontal and vertical directions.
22+
- `IgxToggleDirective`:
23+
- `setOffset` method added. It repositions the content in the horizontal and vertical directions.
2024

2125
## 8.2.6
2226

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Basic initialization
1515
</div>
1616
```
1717

18-
Opne/Close toggle through public methods that are provided by exporting the directive with name **toggle**.
18+
Open/Close toggle through public methods that are provided by exporting the directive with name **toggle**.
1919
```html
2020
<button (click)="toggleRef.open()">Open</button>
2121
<button (click)="toggleRef.close()">Close</button>
@@ -49,6 +49,8 @@ handlers when the toggle is opened and respectively closed.
4949
| `close` | --- | `void` | Closes the toggle. |
5050
| `toggle` | overlaySettings?: `OverlaySettings` | `void` | Closes the toggle. |
5151
| `reposition` | --- | `void` | Repositions the toggle. |
52+
| `setOffset` | Repositions the content in the horizontal and/or vertical directions. |deltaX, deltaY |
53+
5254

5355

5456
# IgxToggleAction Directive

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,13 @@ export class IgxToggleDirective implements IToggleView, OnInit, OnDestroy {
276276
this.overlayService.reposition(this._overlayId);
277277
}
278278

279+
/**
280+
* Repositions the content in the horizontal and/or vertical directions.
281+
*/
282+
setOffset(deltaX: number, deltaY: number) {
283+
this.overlayService.setOffset(this._overlayId, deltaX, deltaY);
284+
}
285+
279286
/**
280287
* @hidden
281288
*/

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ this.overlay.show(component, overlaySettings);
9696
|hide | Remove the provided native element of for the component with provided id |id |
9797
|hideAll | Remove the all native elements and hides the overlay |- |
9898
|reposition | Repositions the native element of the component with provided id |id |
99+
|setOffset | Repositions the content in the horizontal and/or vertical directions. |id, deltaX, deltaY |
99100

100101
###### IPositionStrategy
101102

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

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,48 @@ describe('igxOverlay', () => {
504504
expect(BaseFitPositionStrategy.prototype.position).toHaveBeenCalledTimes(3);
505505
});
506506

507+
it('Should properly call setOffset method', fakeAsync(() => {
508+
const fix = TestBed.createComponent(WidthTestOverlayComponent);
509+
const overlayInstance = fix.componentInstance.overlay;
510+
const id = fix.componentInstance.overlay.attach(SimpleRefComponent);
511+
512+
overlayInstance.show(id);
513+
514+
fix.detectChanges();
515+
tick();
516+
517+
overlayInstance.setOffset(id, 40, 40);
518+
const overlayContent: Element = document.getElementsByClassName(CLASS_OVERLAY_CONTENT_MODAL)[0];
519+
const component = document.getElementsByClassName('simpleRef')[0];
520+
const contentRectOverlay = overlayContent.getBoundingClientRect();
521+
const componentRectOverlay = component.getBoundingClientRect();
522+
let overlayContentTransform = (<any>overlayContent).style.transform;
523+
const firstTransform = 'translate(40px, 40px)';
524+
const secondTransform = 'translate(30px, 60px)';
525+
526+
expect(contentRectOverlay.top).toEqual(componentRectOverlay.top);
527+
expect(contentRectOverlay.left).toEqual(componentRectOverlay.left);
528+
expect(overlayContentTransform).toEqual(firstTransform);
529+
530+
// Set the offset again and verify it is changed correctly
531+
overlayInstance.setOffset(id, -10, 20);
532+
fix.detectChanges();
533+
tick();
534+
const contentRectOverlayNew = overlayContent.getBoundingClientRect();
535+
const componentRectOverlayNew = component.getBoundingClientRect();
536+
overlayContentTransform = (<any>overlayContent).style.transform;
537+
538+
expect(contentRectOverlayNew.top).toEqual(componentRectOverlayNew.top);
539+
expect(contentRectOverlayNew.left).toEqual(componentRectOverlayNew.left);
540+
541+
expect(contentRectOverlayNew.top).not.toEqual(contentRectOverlay.top);
542+
expect(contentRectOverlayNew.left).not.toEqual(contentRectOverlay.left);
543+
544+
expect(componentRectOverlayNew.top).not.toEqual(componentRectOverlay.top);
545+
expect(componentRectOverlayNew.left).not.toEqual(componentRectOverlay.left);
546+
expect(overlayContentTransform).toEqual(secondTransform);
547+
}));
548+
507549
it('fix for #1690 - click on second filter does not close first one.', fakeAsync(() => {
508550
const fixture = TestBed.createComponent(TwoButtonsComponent);
509551
const button1 = fixture.nativeElement.getElementsByClassName('buttonOne')[0];
@@ -3451,7 +3493,7 @@ export class SimpleDynamicComponent {
34513493
}
34523494

34533495
@Component({
3454-
template: `<div #item style='position: absolute; width:100px; height: 100px; background-color: red'></div>`
3496+
template: `<div #item class="simpleRef" style='position: absolute; width:100px; height: 100px; background-color: red'></div>`
34553497
})
34563498
export class SimpleRefComponent {
34573499
@ViewChild('item', { static: true })

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,29 @@ export class IgxOverlayService implements OnDestroy {
245245
false);
246246
}
247247

248+
/**
249+
* Repositions the content in the horizontal and/or vertical directions.
250+
* ```typescript
251+
* this.overlay.setOffset(id, x, y);
252+
* ```
253+
*/
254+
setOffset(id: string, deltaX: number, deltaY: number) {
255+
const info: OverlayInfo = this.getOverlayById(id);
256+
257+
if (!info) {
258+
return;
259+
}
260+
261+
info.transformX += deltaX;
262+
info.transformY += deltaY;
263+
264+
const transformX = info.transformX;
265+
const transformY = info.transformY;
266+
267+
const translate = `translate(${transformX}px, ${transformY}px)`;
268+
info.elementRef.nativeElement.parentElement.style.transform = translate;
269+
}
270+
248271
private _show(info: OverlayInfo) {
249272
const eventArgs: OverlayCancelableEventArgs = { id: info.id, componentRef: info.componentRef, cancel: false };
250273
this.onOpening.emit(eventArgs);
@@ -334,7 +357,7 @@ export class IgxOverlayService implements OnDestroy {
334357
}
335358

336359
private getOverlayInfo(component: any, moduleRef?: Pick<NgModuleRef<any>, 'injector' | 'componentFactoryResolver'>): OverlayInfo {
337-
const info: OverlayInfo = { ngZone: this._zone };
360+
const info: OverlayInfo = { ngZone: this._zone, transformX: 0, transformY: 0 };
338361
if (component instanceof ElementRef) {
339362
info.elementRef = <ElementRef>component;
340363
} else {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ export interface OverlayInfo {
102102
openAnimationInnerPlayer?: any;
103103
closeAnimationInnerPlayer?: any;
104104
ngZone: NgZone;
105+
transformX?: number;
106+
transformY?: number;
105107
}
106108

107109
/** @hidden */

0 commit comments

Comments
 (0)