Skip to content

Commit

Permalink
feat: add suggestions from CR
Browse files Browse the repository at this point in the history
  • Loading branch information
sonya0504 committed Jul 4, 2024
1 parent f744bd7 commit 59c2846
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions src/components/organisms/UiModal/UiModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,6 @@ const cancelHandler = () => {
onMounted(() => {
if (!props.isClosable) return;
window.addEventListener('keydown', keydownHandler);
});
Expand All @@ -484,17 +483,17 @@ onBeforeUnmount(() => {
watch(
() => props.modelValue,
async (value) => {
if (value) {
await nextTick();
if (dialog.value) {
const focusableElements = dialog.value.querySelectorAll<HTMLElement>(
'a[href], button, textarea, input, select, [tabindex]:not([tabindex="-1"])',
);
// NOTE: Checks if UiModal is visible, then waits for the next rendering cycle to complete using nextTick()
if (!value) return;
await nextTick();
if (!dialog.value) return;
if (focusableElements.length > 0) {
focusElement(focusableElements[0], true);
}
}
// NOTE: Finds all focusable elements within the dialog, then sets focus on the first one if any are found
const focusableElements = dialog.value.querySelectorAll<HTMLElement>(
'a[href], button, textarea, input, select, [tabindex]:not([tabindex="-1"])',
);
if (focusableElements.length > 0) {
focusElement(focusableElements[0], true);
}
},
{ immediate: true },
Expand Down Expand Up @@ -571,7 +570,6 @@ watch(
justify-content: flex-end;
display: grid;
grid-template-areas: "cancel confirm";
}
}
Expand Down

0 comments on commit 59c2846

Please sign in to comment.