Skip to content

Commit 79941e0

Browse files
marker-daomarker dao ®
andauthored
Overlay: Prevent domUtils.contains call if content is null (#31889)
Co-authored-by: marker dao ® <[email protected]>
1 parent 3fdd8dd commit 79941e0

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

packages/devextreme/js/__internal/ui/overlay/overlay.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,8 @@ class Overlay<
458458
const isAttachedTarget = $(window.document).is($target) || isTargetDocument;
459459
const isInnerOverlay = $($target).closest(`.${INNER_OVERLAY_CLASS}`).length;
460460
const isTargetContent = this._$content?.is($target);
461-
const isTargetInContent = domUtils.contains(this._$content?.get(0), target);
461+
const content = this._$content?.get(0);
462+
const isTargetInContent = content ? domUtils.contains(content, target) : false;
462463

463464
const isOutsideClick = isAttachedTarget
464465
&& !isInnerOverlay

packages/devextreme/testing/tests/DevExpress.ui.widgets/overlay.tests.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2199,6 +2199,27 @@ testModule('hide on outside click', moduleConfig, () => {
21992199
assert.strictEqual(overlay2.option('visible'), false, 'Second overlay is hidden, because of outsideclick');
22002200
});
22012201

2202+
test('overlay should handle outside click without errors when content is null', function(assert) {
2203+
const overlay = $('#overlay').dxOverlay({
2204+
hideOnOutsideClick: true,
2205+
visible: true,
2206+
}).dxOverlay('instance');
2207+
2208+
const originalContent = overlay._$content;
2209+
2210+
overlay._$content = null;
2211+
2212+
try {
2213+
$(document).trigger('dxpointerdown');
2214+
assert.ok(true, 'No error when content is null');
2215+
assert.strictEqual(overlay.option('visible'), false, 'Overlay should hide on outside click when content is null');
2216+
} catch(e) {
2217+
assert.ok(false, `Error occurred with null content: ${e.message}`);
2218+
} finally {
2219+
overlay._$content = originalContent;
2220+
}
2221+
});
2222+
22022223
test('document events should be unsubscribed at each overlay hiding', function(assert) {
22032224
const $overlay1 = $('#overlay').dxOverlay({
22042225
hideOnOutsideClick: true,

0 commit comments

Comments
 (0)