Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ui-kit): dialog closing and a11y #346

Merged
merged 3 commits into from
Jul 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions packages/devtools-ui-kit/src/components/NDialog.vue
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
<script setup lang="ts">
import { computed, nextTick, ref, watchEffect } from 'vue'
import { useVModel } from '@vueuse/core'
import { onClickOutside, useVModel } from '@vueuse/core'
import { useFocusTrap } from '@vueuse/integrations/useFocusTrap'

const props = withDefaults(
defineProps<{
modelValue?: boolean
dim?: boolean
autoClose?: boolean
}>(),
{
modelValue: false,
dim: true,
autoClose: true,
},
)

Expand All @@ -37,10 +39,14 @@ watchEffect(
},
)

function close() {
show.value = false
emit('close')
}
onClickOutside(card, () => {
harlan-zw marked this conversation as resolved.
Show resolved Hide resolved
if (props.modelValue && props.autoClose) {
show.value = false
emit('close')
}
}, {
ignore: ['a', 'button', 'summary'],
})
</script>

<script lang="ts">
Expand All @@ -54,16 +60,17 @@ export default {
<div
v-show="show"
class="n-dialog fixed inset-0 z-100 flex items-center justify-center n-transition"
role="dialog"
aria-modal="true"
:class="[
show ? '' : 'op0 pointer-events-none visibility-none',
]"
>
<div
class="absolute inset-0 -z-1"
:class="[
dim ? 'bg-black/50' : '',
dim ? 'glass-effect' : '',
]"
@click="close()"
/>
<NCard v-bind="$attrs" ref="card" class="max-h-screen of-auto">
<slot />
Expand Down
2 changes: 1 addition & 1 deletion packages/devtools/client/components/DrawerRight.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ onClickOutside(el, () => {
if (props.modelValue && props.autoClose)
emit('close')
}, {
ignore: ['a', 'button', 'summary'],
ignore: ['a', 'button', 'summary', '[role="dialog"]'],
})
</script>

Expand Down