Skip to content

Commit 5b6e7d9

Browse files
committed
refactor(density): further optimizations
1 parent caa9694 commit 5b6e7d9

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

projects/igniteui-angular/src/lib/core/density.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,22 +81,18 @@ export class DisplayDensityBase implements DoCheck, OnInit {
8181
*/
8282
@Input()
8383
public get displayDensity(): DisplayDensity {
84-
if (!this.size) {
85-
return (
86-
this._displayDensity ??
87-
this.displayDensityOptions?.displayDensity ??
88-
DisplayDensity.comfortable
89-
);
90-
}
91-
9284
switch (this.size) {
9385
case '1':
9486
return DisplayDensity.compact;
9587
case '2':
9688
return DisplayDensity.cosy;
9789
case '3':
9890
default:
99-
return DisplayDensity.comfortable;
91+
return (
92+
this._displayDensity ??
93+
this.displayDensityOptions?.displayDensity ??
94+
DisplayDensity.comfortable
95+
);
10096
}
10197
}
10298

@@ -118,7 +114,7 @@ export class DisplayDensityBase implements DoCheck, OnInit {
118114
}
119115

120116
public get size() {
121-
return globalThis.document.defaultView
117+
return globalThis.document?.defaultView
122118
.getComputedStyle(this._host.nativeElement)
123119
.getPropertyValue('--ig-size')
124120
.trim();
@@ -131,7 +127,8 @@ export class DisplayDensityBase implements DoCheck, OnInit {
131127

132128
protected oldDisplayDensityOptions: IDisplayDensityOptions = {
133129
displayDensity: DisplayDensity.comfortable,
134-
};
130+
}
131+
135132
protected _displayDensity: DisplayDensity;
136133

137134
constructor(

projects/igniteui-angular/src/lib/core/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -831,11 +831,11 @@ export const formatCurrency = new CurrencyPipe(undefined).transform;
831831

832832
/** Converts pixel values to their rem counterparts for a base value */
833833
export const rem = (value: number | string) => {
834-
const base = parseFloat(getComputedStyle(document.documentElement).getPropertyValue('--ig-base-font-size'))
834+
const base = parseFloat(getComputedStyle(globalThis.document?.documentElement).getPropertyValue('--ig-base-font-size'))
835835
return Number(value) / base;
836836
}
837837

838838
/** Get the size of the component as derived from the CSS size variable */
839839
export function getComponentSize(el: Element) {
840-
return window.getComputedStyle(el).getPropertyValue('--component-size');
840+
return globalThis.window?.getComputedStyle(el).getPropertyValue('--component-size');
841841
}

0 commit comments

Comments
 (0)