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(KvLightbox): allow focus on open alerts, clicks on browser extensions and outside lightbox #326

Merged
merged 1 commit into from
Dec 6, 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
8 changes: 7 additions & 1 deletion @kiva/kv-components/vue/KvLightbox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,16 @@ export default {
const kvLightboxBody = ref(null);
const controlsRef = ref(null);

const trapElements = computed(() => [
kvLightbox.value, // This lightbox
'[role="alert"]', // Any open toasts/alerts on the page
]);
const {
activate: activateFocusTrap,
deactivate: deactivateFocusTrap,
} = useFocusTrap(kvLightbox);
} = useFocusTrap(trapElements, {
allowOutsideClick: true, // allow clicking outside the lightbox to close it
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be conditional based on props sent to the lightbox? We don't allow outside clicks in certain circumstances such as employee verification for campaign pages.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't bypass our existing preventClose logic. If preventClose is true, clicking on the background won't close the lightbox. This just allows clicking on the background to close the lightbox when preventClose is false.

});

let makePageInertCallback = null;
let onKeyUp = null;
Expand Down
49 changes: 49 additions & 0 deletions @kiva/kv-components/vue/stories/KvLightbox.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { mdiLightningBolt } from '@mdi/js';
import KvLightbox from '../KvLightbox.vue';
import KvMaterialIcon from '../KvMaterialIcon.vue';
import KvButton from '../KvButton.vue';
import KvToast from '../KvToast.vue';

export default {
title: 'KvLightbox',
Expand Down Expand Up @@ -253,3 +254,51 @@ export const Informational = InformationalTemplate.bind({});
Informational.args = {
title: 'Lightbox Title',
};

const ToastInLightboxTemplate = (args, {
argTypes,
}) => ({
props: Object.keys(argTypes),
components: {
KvToast,
KvButton,
KvLightbox,
},
template: `
<div>
<kv-button @click="isLightboxVisible = true;">Show lightbox</kv-button>

<kv-lightbox
:visible="isLightboxVisible"
title="Toast in Lightbox"
@lightbox-closed="isLightboxVisible = false"
>
<p>Click the button below to show a toast.</p>
<template #controls>
<kv-button @click="showToast(message, type, persist)">Show Toast</kv-button>
</template>
</kv-lightbox>

<!-- div below is a kludge for storybook docs -->
<div class="tw-fixed tw-z-toast tw-inset-0 tw-pointer-events-none">
<div class="tw-fixed tw-left-0 tw-right-0 tw-top-2 tw-pointer-events-auto">
<kv-toast ref="toastRef" @close="onClose" />
</div>
</div>
</div>
`,
data() {
return {
isLightboxVisible: false,
};
},
methods: {
showToast(messageInput, type, persistInput) {
this.$refs.toastRef.show(messageInput, type, persistInput);
},
onClose() {
},
},
});
export const toastInLightbox = ToastInLightboxTemplate.bind({});
toastInLightbox.args = { type: 'confirmation', message: 'This is a toast in a lightbox.' };
Loading