mirror of
https://gitee.com/element-plus/element-plus.git
synced 2024-12-05 12:48:04 +08:00
d2e9de9511
* feat(components): [el-dialog] enhancement for dialog a11y - Refactor dialog to script setup * Separates dialog and its content into different components * Remove unused code & fix a potential bug in focus-trap component * Update dialog-content.vue Co-authored-by: bqy <1743369777@qq.com>
48 lines
1.1 KiB
Vue
48 lines
1.1 KiB
Vue
<template>
|
|
<el-button type="text" @click="dialogVisible = true"
|
|
>click to open the Dialog</el-button
|
|
>
|
|
|
|
<div>
|
|
<p>Close dialog and the input will be focused</p>
|
|
<el-input ref="inputRef" placeholder="Please input" />
|
|
</div>
|
|
|
|
<el-dialog
|
|
v-model="dialogVisible"
|
|
destroy-on-close
|
|
title="Tips"
|
|
width="30%"
|
|
@close-auto-focus="handleCloseAutoFocus"
|
|
>
|
|
<span>This is a message</span>
|
|
<el-divider />
|
|
<el-input placeholder="Initially focused" />
|
|
<template #footer>
|
|
<span class="dialog-footer">
|
|
<el-button @click="dialogVisible = false">Cancel</el-button>
|
|
<el-button type="primary" @click="dialogVisible = false"
|
|
>Confirm</el-button
|
|
>
|
|
</span>
|
|
</template>
|
|
</el-dialog>
|
|
</template>
|
|
|
|
<script lang="ts" setup>
|
|
import { ref } from 'vue'
|
|
import type { ElInput } from 'element-plus'
|
|
|
|
const dialogVisible = ref(false)
|
|
const inputRef = ref<InstanceType<typeof ElInput>>()
|
|
|
|
const handleCloseAutoFocus = () => {
|
|
inputRef.value?.focus()
|
|
}
|
|
</script>
|
|
<style scoped>
|
|
.dialog-footer button:first-child {
|
|
margin-right: 10px;
|
|
}
|
|
</style>
|