Skip to content

Commit 44f0c09

Browse files
Sewar-xzernonia
andauthored
fix(DismissableLayer): read properties of null (#1860)
* fix: Fix select and modal popup errors in wujie micro-frontend project * chore: update conditional and better types --------- Co-authored-by: zernonia <zernonia@gmail.com>
1 parent 5cc13ae commit 44f0c09

File tree

1 file changed

+7
-8
lines changed
  • packages/core/src/DismissableLayer

1 file changed

+7
-8
lines changed

packages/core/src/DismissableLayer/utils.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const FOCUS_OUTSIDE = 'dismissableLayer.focusOutside'
1616
function isLayerExist(layerElement: HTMLElement, targetElement: HTMLElement) {
1717
const targetLayer = targetElement.closest(
1818
'[data-dismissable-layer]',
19-
) as HTMLElement
19+
)
2020

2121
const mainLayer = layerElement.dataset.dismissableLayer === ''
2222
? layerElement
@@ -27,10 +27,8 @@ function isLayerExist(layerElement: HTMLElement, targetElement: HTMLElement) {
2727
const nodeList = Array.from(
2828
layerElement.ownerDocument.querySelectorAll('[data-dismissable-layer]'),
2929
)
30-
if (
31-
(targetLayer
32-
&& mainLayer === targetLayer)
33-
|| nodeList.indexOf(mainLayer) < nodeList.indexOf(targetLayer)
30+
31+
if (targetLayer && (mainLayer === targetLayer || nodeList.indexOf(mainLayer) < nodeList.indexOf(targetLayer))
3432
) {
3533
return true
3634
}
@@ -58,9 +56,9 @@ export function usePointerDownOutside(
5856
if (!isClient)
5957
return
6058
const handlePointerDown = async (event: PointerEvent) => {
61-
const target = event.target as HTMLElement
59+
const target = event.target as HTMLElement | undefined
6260

63-
if (!element?.value)
61+
if (!element?.value || !target)
6462
return
6563

6664
if (isLayerExist(element.value, target)) {
@@ -159,7 +157,8 @@ export function useFocusOutside(
159157

160158
await nextTick()
161159
await nextTick()
162-
if (!element.value || isLayerExist(element.value, event.target as HTMLElement))
160+
const target = event.target as HTMLElement | undefined
161+
if (!element.value || !target || isLayerExist(element.value, target))
163162
return
164163

165164
if (event.target && !isFocusInsideDOMTree.value) {

0 commit comments

Comments
 (0)