Skip to content

Commit

Permalink
fix(comp:modal): reading contains after onmounted causes an exception (
Browse files Browse the repository at this point in the history
  • Loading branch information
danranVm committed Dec 23, 2022
1 parent f19efbe commit de416c1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
16 changes: 8 additions & 8 deletions packages/components/drawer/src/DrawerWrapper.tsx
Expand Up @@ -201,9 +201,9 @@ function watchVisibleChange(
() => props.visible,
visible => {
if (visible) {
const wrapperElement = wrapperRef.value!
const wrapperElement = wrapperRef.value
const activeElement = document.activeElement
if (!wrapperElement.contains(activeElement)) {
if (wrapperElement && !wrapperElement.contains(activeElement)) {
lastOutSideActiveElement = activeElement as HTMLElement
sentinelStartRef.value?.focus()
}
Expand Down Expand Up @@ -286,17 +286,17 @@ function useEvents(
) {
let lastOutSideActiveElement: HTMLElement | null = null
const onEnter = () => {
const wrapperElement = wrapperRef.value!
const wrapperElement = wrapperRef.value
const activeElement = document.activeElement
if (!wrapperElement.contains(activeElement)) {
if (wrapperElement && !wrapperElement.contains(activeElement)) {
lastOutSideActiveElement = activeElement as HTMLElement
}
}

const onAfterEnter = () => {
const wrapperElement = wrapperRef.value!
const wrapperElement = wrapperRef.value
const activeElement = document.activeElement
if (!wrapperElement.contains(activeElement)) {
if (wrapperElement && !wrapperElement.contains(activeElement)) {
wrapperElement.focus()
}

Expand All @@ -306,14 +306,14 @@ function useEvents(

const onAfterLeave = () => {
if (lastOutSideActiveElement && isFunction(lastOutSideActiveElement.focus)) {
const wrapperElement = wrapperRef.value!
const wrapperElement = wrapperRef.value
const activeElement = document.activeElement

if (
!activeElement ||
activeElement === document.body ||
activeElement === wrapperElement ||
wrapperElement.contains(activeElement)
(wrapperElement && wrapperElement.contains(activeElement))
) {
lastOutSideActiveElement.focus()
}
Expand Down
2 changes: 1 addition & 1 deletion packages/components/menu/src/contents/menu-sub/MenuSub.tsx
Expand Up @@ -37,7 +37,7 @@ export default defineComponent({
props: menuSubProps,
setup(props) {
const common = useGlobalConfig('common')
const mergedTransitionName = computed(() => `${common.prefixCls}-fade`)
const mergedTransitionName = computed(() => `${common.prefixCls}-fade-fast`)

// menuContext must exist
const {
Expand Down
14 changes: 7 additions & 7 deletions packages/components/modal/src/ModalWrapper.tsx
Expand Up @@ -240,9 +240,9 @@ function watchVisibleChange(
() => props.visible,
visible => {
if (visible) {
const wrapperElement = wrapperRef.value!
const wrapperElement = wrapperRef.value
const activeElement = document.activeElement
if (!wrapperElement.contains(activeElement)) {
if (wrapperElement && !wrapperElement.contains(activeElement)) {
lastOutSideActiveElement = activeElement as HTMLElement
sentinelStartRef.value?.focus()
}
Expand Down Expand Up @@ -329,9 +329,9 @@ function useEvents(
) {
let lastOutSideActiveElement: HTMLElement | null = null
const onEnter = () => {
const wrapperElement = wrapperRef.value!
const wrapperElement = wrapperRef.value
const activeElement = document.activeElement
if (!wrapperElement.contains(activeElement)) {
if (wrapperElement && !wrapperElement.contains(activeElement)) {
lastOutSideActiveElement = activeElement as HTMLElement
}

Expand All @@ -347,9 +347,9 @@ function useEvents(
}

const onAfterEnter = () => {
const wrapperElement = wrapperRef.value!
const wrapperElement = wrapperRef.value
const activeElement = document.activeElement
if (!wrapperElement.contains(activeElement)) {
if (wrapperElement && !wrapperElement.contains(activeElement)) {
wrapperElement.focus()
}

Expand All @@ -366,7 +366,7 @@ function useEvents(
!activeElement ||
activeElement === document.body ||
activeElement === wrapperElement ||
wrapperElement.contains(activeElement)
(wrapperElement && wrapperElement.contains(activeElement))
) {
lastOutSideActiveElement.focus()
}
Expand Down

0 comments on commit de416c1

Please sign in to comment.