fix(components): [focus-trap] respect focusout null relatedTarget (#7915)

* fix(components): [focus-trap] respect focusout null relatedTarget

* fix(components): [focus-trap] use right variable this time

Co-authored-by: OpenGraphica <opengraphica@gmail.com>
This commit is contained in:
Giwayume 2022-05-27 00:15:03 -04:00 committed by GitHub
parent 49ed2f6907
commit b6049dab1c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -12,6 +12,7 @@ import {
unref, unref,
watch, watch,
} from 'vue' } from 'vue'
import { isNil } from 'lodash-unified'
import { EVENT_CODE } from '@element-plus/constants' import { EVENT_CODE } from '@element-plus/constants'
import { useEscapeKeydown } from '@element-plus/hooks' import { useEscapeKeydown } from '@element-plus/hooks'
import { isString } from '@element-plus/utils' import { isString } from '@element-plus/utils'
@ -168,11 +169,9 @@ export default defineComponent({
if (focusLayer.paused || !trapContainer) return if (focusLayer.paused || !trapContainer) return
if (props.trapped) { if (props.trapped) {
if ( const relatedTarget = (e as FocusEvent)
!trapContainer.contains( .relatedTarget as HTMLElement | null
(e as FocusEvent).relatedTarget as HTMLElement | null if (!isNil(relatedTarget) && !trapContainer.contains(relatedTarget)) {
)
) {
tryFocus(lastFocusAfterTrapped, true) tryFocus(lastFocusAfterTrapped, true)
} }
} else { } else {