mirror of
https://gitee.com/element-plus/element-plus.git
synced 2024-12-15 09:50:58 +08:00
ef92b6c11c
* Add overlay component; Dialog component almost done * feat(dialog): add use-lockscreen * feat(dialog): coding completed awaiting tests * feat(dialog): finish writing test cases * fix test failures * Address PR comments * fallback some changes
25 lines
685 B
TypeScript
25 lines
685 B
TypeScript
import { isRef, watch } from 'vue'
|
|
import type { Ref } from 'vue'
|
|
|
|
/**
|
|
* This method provides dialogable components the ability to restore previously activated element before
|
|
* the dialog gets opened
|
|
*/
|
|
export default (toggle: Ref<boolean>, initialFocus?: Ref<HTMLElement>) => {
|
|
let previousActive: HTMLElement
|
|
watch(() => toggle.value, val => {
|
|
if (val) {
|
|
previousActive = document.activeElement as HTMLElement
|
|
if (isRef(initialFocus)) {
|
|
initialFocus.value.focus?.()
|
|
}
|
|
} else {
|
|
if (process.env.NODE_ENV === 'testing') {
|
|
previousActive.focus.call(previousActive)
|
|
} else {
|
|
previousActive.focus()
|
|
}
|
|
}
|
|
})
|
|
}
|