fix(overlays): undefined document.body (#2070)

* Fix undefined `document.body`

* Add changeset
This commit is contained in:
Fábio Santos 2023-09-06 08:34:04 -03:00 committed by GitHub
parent b0a74f2831
commit ebe13e14b0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 4 deletions

View file

@ -0,0 +1,5 @@
---
'@lion/ui': patch
---
fix: undefined document.body

View file

@ -103,9 +103,6 @@ async function preloadPopper() {
return /** @type {* & Promise<PopperModule>} */ (import('@popperjs/core/dist/esm/popper.js')); return /** @type {* & Promise<PopperModule>} */ (import('@popperjs/core/dist/esm/popper.js'));
} }
// @ts-expect-error [external]: CSS not yet typed
const supportsCSSTypedObject = window.CSS?.number && document.body.attributeStyleMap?.set;
/** /**
* OverlayController is the fundament for every single type of overlay. With the right * OverlayController is the fundament for every single type of overlay. With the right
* configuration, it can be used to build (modal) dialogs, tooltips, dropdowns, popovers, * configuration, it can be used to build (modal) dialogs, tooltips, dropdowns, popovers,
@ -808,7 +805,8 @@ export class OverlayController extends EventTarget {
document.body.clientHeight - /** @type {number} */ (this.__bodyClientHeight); document.body.clientHeight - /** @type {number} */ (this.__bodyClientHeight);
const newMarginRight = this.__bodyMarginRight + scrollbarWidth; const newMarginRight = this.__bodyMarginRight + scrollbarWidth;
const newMarginBottom = this.__bodyMarginBottom + scrollbarHeight; const newMarginBottom = this.__bodyMarginBottom + scrollbarHeight;
if (supportsCSSTypedObject) { // @ts-expect-error [external]: CSS not yet typed
if (window.CSS?.number && document.body.attributeStyleMap?.set) {
// @ts-expect-error [external]: types attributeStyleMap + CSS.px not available yet // @ts-expect-error [external]: types attributeStyleMap + CSS.px not available yet
document.body.attributeStyleMap.set('margin-right', CSS.px(newMarginRight)); document.body.attributeStyleMap.set('margin-right', CSS.px(newMarginRight));
// @ts-expect-error [external]: types attributeStyleMap + CSS.px not available yet // @ts-expect-error [external]: types attributeStyleMap + CSS.px not available yet