Skip to content

Commit 86b65e9

Browse files
authored
fix(toggle): Change the way how the dropdown passes size to toggle (#14636)
1 parent fd36c02 commit 86b65e9

File tree

6 files changed

+38
-21
lines changed

6 files changed

+38
-21
lines changed

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -223,17 +223,6 @@ export class IgxToggleDirective implements IToggleView, OnInit, OnDestroy {
223223
return;
224224
}
225225

226-
const target = overlaySettings && overlaySettings.target;
227-
228-
// Get the size from the target element
229-
if (target && target instanceof Element) {
230-
const styles = window.getComputedStyle(target);
231-
const componentSize = styles.getPropertyValue('--component-size');
232-
const globalSize = styles.getPropertyValue('--ig-size');
233-
const size = componentSize || globalSize || '3';
234-
this.elementRef.nativeElement.style.setProperty('--ig-size', size);
235-
}
236-
237226
this._collapsed = false;
238227
this.cdr.detectChanges();
239228

projects/igniteui-angular/src/lib/drop-down/drop-down.base.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { IDropDownList } from './drop-down.common';
99
import { DropDownActionKey } from './drop-down.common';
1010
import { IgxDropDownItemBaseDirective } from './drop-down-item.base';
1111
import { DOCUMENT } from '@angular/common';
12-
import { Size } from '../grids/common/enums';
1312

1413
let NEXT_ID = 0;
1514

@@ -163,14 +162,6 @@ export abstract class IgxDropDownBaseDirective implements IDropDownList, OnInit
163162
return this.element;
164163
}
165164

166-
/**
167-
* @hidden
168-
* @internal
169-
*/
170-
public get dropDownSize() {
171-
return this.computedStyles?.getPropertyValue('--ig-size') || Size.Medium;
172-
}
173-
174165
/**
175166
* @hidden
176167
* @internal

projects/igniteui-angular/src/lib/drop-down/drop-down.component.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<div class="igx-drop-down__list" [style.width]="width"
22
igxToggle
3-
[style.--ig-size]="dropDownSize"
43
(appended)="onToggleContentAppended($event)"
54
(opening)="onToggleOpening($event)" (opened)="onToggleOpened()"
65
(closing)="onToggleClosing($event)" (closed)="onToggleClosed()">

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,6 +1357,27 @@ describe('igxOverlay', () => {
13571357

13581358
overlay.detachAll();
13591359
}));
1360+
1361+
it('Should properly move computed size style to the overlay content container.', fakeAsync(() => {
1362+
const fixture = TestBed.createComponent(SimpleRefComponent);
1363+
fixture.detectChanges();
1364+
1365+
fixture.componentInstance.item.nativeElement.style.setProperty('--ig-size', 'var(--ig-size-small)');
1366+
fixture.detectChanges();
1367+
const overlayInstance = fixture.componentInstance.overlay;
1368+
const overlaySettings: OverlaySettings = {
1369+
positionStrategy: new ConnectedPositioningStrategy(),
1370+
modal: false,
1371+
closeOnOutsideClick: false
1372+
};
1373+
const firstCallId = overlayInstance.attach(fixture.componentInstance.item, overlaySettings);
1374+
overlayInstance.show(firstCallId);
1375+
tick();
1376+
1377+
const overlayContent = document.getElementsByClassName(CLASS_OVERLAY_CONTENT)[0] as HTMLElement;
1378+
expect(overlayContent.style.getPropertyValue('--ig-size')).toEqual('1');
1379+
overlayInstance.detach(firstCallId);
1380+
}));
13601381
});
13611382

13621383
describe('Unit Tests - Scroll Strategies: ', () => {

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ export class IgxOverlayService implements OnDestroy {
346346
info.hook = this.placeElementHook(info.elementRef.nativeElement);
347347
const elementRect = info.elementRef.nativeElement.getBoundingClientRect();
348348
info.initialSize = { width: elementRect.width, height: elementRect.height };
349+
this.addComponentSize(info);
349350
this.moveElementToOverlay(info);
350351
this.contentAppended.emit({ id: info.id, componentRef: info.componentRef });
351352
info.settings.scrollStrategy.initialize(this._document, this, info.id);
@@ -669,6 +670,11 @@ export class IgxOverlayService implements OnDestroy {
669670
}
670671

671672
private updateSize(info: OverlayInfo) {
673+
// set content div size
674+
if (info.size) {
675+
info.elementRef.nativeElement.parentElement.style.setProperty('--ig-size', info.size);
676+
}
677+
672678
if (info.componentRef) {
673679
// if we are positioning component this is first time it gets visible
674680
// and we can finally get its size
@@ -977,4 +983,14 @@ export class IgxOverlayService implements OnDestroy {
977983
info.closeAnimationPlayer.finish();
978984
}
979985
}
986+
987+
private addComponentSize(info: OverlayInfo) {
988+
if (info.elementRef?.nativeElement instanceof Element) {
989+
const styles = this._document.defaultView.getComputedStyle(info.elementRef.nativeElement);
990+
const componentSize = styles.getPropertyValue('--component-size');
991+
const globalSize = styles.getPropertyValue('--ig-size');
992+
const size = componentSize || globalSize;
993+
info.size = size;
994+
}
995+
}
980996
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ export interface OverlayInfo {
172172
transformY?: number;
173173
event?: Event;
174174
wrapperElement?: HTMLElement;
175+
size?: string
175176
}
176177

177178
/** @hidden */

0 commit comments

Comments
 (0)