Skip to content

Commit

Permalink
Fix focus in NC textarea after disclose animation
Browse files Browse the repository at this point in the history
  • Loading branch information
yaaax committed Jul 31, 2024
1 parent bcead31 commit 7d77fdb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,22 @@ function onFileRequestFinished() {
const lazyAccordionRef = ref<InstanceType<typeof LazyAccordion>>();
const commentFieldRef = ref<HTMLTextAreaElement>();
let hasJustBeenSetAsNotCompliant = false;
async function disclose() {
const accordion = lazyAccordionRef.value?.accordionRef;
hasJustBeenSetAsNotCompliant = true;
dsfr(accordion).accordionsGroup.members[0].disclose();
}
function lazyAccordionOpened() {
if (!hasJustBeenSetAsNotCompliant) {
return;
}
// FIXME: avoid setTimeout()
setTimeout(() => {
commentFieldRef.value?.focus();
}, 10);
commentFieldRef.value?.focus();
hasJustBeenSetAsNotCompliant = false;
}
</script>

Expand All @@ -92,6 +99,7 @@ async function disclose() {
ref="lazyAccordionRef"
title="Erreur et recommandation"
disclose-color="var(--background-default-grey)"
@opened="lazyAccordionOpened"
>
<!-- COMMENT -->
<div class="fr-input-group fr-mb-1w">
Expand Down
5 changes: 5 additions & 0 deletions confiture-web-app/src/components/audit/LazyAccordion.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const accordionRef = ref<HTMLDivElement>();
defineExpose({ accordionRef });
const emit = defineEmits(["opened"]);
const showContent = ref(false);
const uniqueId = useUniqueId();
Expand All @@ -23,6 +25,9 @@ function onConceal() {
function onDisclose() {
showContent.value = true;
requestAnimationFrame(function () {
emit("opened");
});
}
</script>

Expand Down

0 comments on commit 7d77fdb

Please sign in to comment.