diff --git a/frontend/src/views/apps/FlareApp.vue b/frontend/src/views/apps/FlareApp.vue index ee1b92b..6327ae4 100644 --- a/frontend/src/views/apps/FlareApp.vue +++ b/frontend/src/views/apps/FlareApp.vue @@ -101,7 +101,8 @@ const unmatchDialog = ref(false) const activeExploreMode = ref('all') const actionToast = ref('') const draftPhotos = ref([]) -const activeChoiceField = ref(null) +const activeChoiceField = ref('gender') +const choiceOpened = ref(false) const choiceSheetContent = ref(null) let activeChoiceTrigger: HTMLElement | null = null const profileDraft = reactive({ @@ -125,14 +126,12 @@ const bioInputStyle: CSSProperties = { } const activeChoiceOptions = computed(() => - activeChoiceField.value ? choiceOptions(activeChoiceField.value) : [], + choiceOptions(activeChoiceField.value), ) const activeChoiceTitle = computed(() => - activeChoiceField.value ? choiceFieldLabel(activeChoiceField.value) : '', -) -const activeChoiceValue = computed(() => - activeChoiceField.value ? profileDraft[activeChoiceField.value] : '', + choiceFieldLabel(activeChoiceField.value), ) +const activeChoiceValue = computed(() => profileDraft[activeChoiceField.value]) const filteredSuggestions = computed(() => activeExploreMode.value === 'all' @@ -316,7 +315,7 @@ function choiceLabel(field: FlareChoiceField): string { function choiceLinkProps(field: FlareChoiceField): Record { return { 'aria-controls': 'flare-choice-sheet', - 'aria-expanded': activeChoiceField.value === field, + 'aria-expanded': choiceOpened.value && activeChoiceField.value === field, 'aria-haspopup': 'dialog', class: 'flare-choice-trigger', onClick: (event: MouseEvent) => @@ -325,21 +324,28 @@ function choiceLinkProps(field: FlareChoiceField): Record { } } -function openChoice(field: FlareChoiceField, trigger: HTMLElement): void { +async function openChoice( + field: FlareChoiceField, + trigger: HTMLElement, +): Promise { activeChoiceTrigger = trigger activeChoiceField.value = field - void nextTick(() => { - choiceSheetContent.value - ?.querySelector('[aria-selected="true"]') - ?.focus() + await nextTick() + await new Promise((resolve) => { + globalThis.requestAnimationFrame(() => resolve()) }) + choiceOpened.value = true + await nextTick() + choiceSheetContent.value + ?.querySelector('[aria-selected="true"]') + ?.focus({ preventScroll: true }) } function closeChoice(): void { const trigger = activeChoiceTrigger - activeChoiceField.value = null + choiceOpened.value = false activeChoiceTrigger = null - void nextTick(() => trigger?.focus()) + void nextTick(() => trigger?.focus({ preventScroll: true })) } function selectChoice(value: string): void { @@ -1477,18 +1483,19 @@ onMounted(async () => {