Openverse is a search engine for openly-licensed media. This monorepo includes all application code.
Fix mobile recent searches modal with banners (#4730)
Olga Bulat2ba55967d20d
diff --git a/frontend/src/app.vue b/frontend/src/app.vueindex 453f83e0b..ea8fc011f 100644--- a/frontend/src/app.vue+++ b/frontend/src/app.vue@@ -29,6 +29,9 @@ const darkMode = useDarkMode()/* UI store */const isDesktopLayout = computed(() => uiStore.isDesktopLayout)const breakpoint = computed(() => uiStore.breakpoint)+const headerHeight = computed(() => {+ return `--header-height: ${uiStore.headerHeight}px`+})const head = useLocaleHead({addDirAttribute: true,@@ -114,7 +117,7 @@ onMounted(() => {/></template></Head>- <Body>+ <Body :style="headerHeight"><div :class="[isDesktopLayout ? 'desktop' : 'mobile', breakpoint]"><VSkipToContentButton /><NuxtLayout>diff --git a/frontend/src/components/VModal/VModalContent.vue b/frontend/src/components/VModal/VModalContent.vueindex f0d2010bf..b8992fc91 100644--- a/frontend/src/components/VModal/VModalContent.vue+++ b/frontend/src/components/VModal/VModalContent.vue@@ -97,13 +97,12 @@ defineExpose({<Teleport to="#teleports"><divv-show="visible"- class="h-dyn-screen min-h-dyn-screen fixed inset-0 z-40 flex justify-center overflow-y-auto"+ class="backdrop h-dyn-screen min-h-dyn-screen fixed inset-0 z-40 flex justify-center overflow-y-auto":class="[{ 'flex-col items-center': variant === 'centered' },- variant === 'mobile-input'- ? 'top-20 h-[calc(100dvh-80px)] bg-tx'- : 'bg-dark-charcoal bg-opacity-75',+ variant === 'mobile-input' ? 'bg-tx' : 'bg-dark-charcoal bg-opacity-75',contentClasses,+ variant,]"><!-- re: disabled static element interactions rule https://github.com/WordPress/openverse/issues/2906 -->@@ -182,6 +181,10 @@ defineExpose({</template><style scoped>+.backdrop.mobile-input {+ height: calc(100dvh - var(--header-height, 80px));+ top: var(--header-height, 80px);+}/*For mobiles that do not support dvh units, we add a fallback paddingto the modal content to make sure that no clickable elements are hiddendiff --git a/frontend/src/layouts/search-layout.vue b/frontend/src/layouts/search-layout.vueindex 49e4131ff..d60402af0 100644--- a/frontend/src/layouts/search-layout.vue+++ b/frontend/src/layouts/search-layout.vue@@ -1,6 +1,6 @@<script setup lang="ts">import { computed, onMounted, provide, ref, watch } from "vue"-import { useScroll } from "@vueuse/core"+import { useElementSize, useScroll } from "@vueuse/core"import { useUiStore } from "~/stores/ui"import { isSearchTypeSupported, useSearchStore } from "~/stores/search"@@ -45,6 +45,7 @@ const showScrollButton = ref(false)* Note: template refs do not work in a Nuxt layout, so we get the `main-page` element using `document.getElementById`.*/let mainPageElement = ref<HTMLElement | null>(null)+let headerElement = ref<HTMLElement | null>(null)const { y: mainPageY } = useScroll(mainPageElement)watch(mainPageY, (y) => {@@ -54,6 +55,14 @@ watch(mainPageY, (y) => {onMounted(() => {mainPageElement.value = document.getElementById("main-page")+ headerElement.value = document.getElementsByClassName(+ "header-el"+ )[0] as HTMLElement+})++const { height } = useElementSize(headerElement)+watch(height, (height) => {+ uiStore.setHeaderHeight(height)})provide(IsHeaderScrolledKey, isHeaderScrolled)diff --git a/frontend/src/stores/ui.ts b/frontend/src/stores/ui.tsindex 4ee80bcce..7d1321702 100644--- a/frontend/src/stores/ui.ts+++ b/frontend/src/stores/ui.ts@@ -52,6 +52,7 @@ export interface UiState {shouldBlurSensitive: boolean/* A list of sensitive single result UUIDs the user has opted-into seeing */revealedSensitiveResults: string[]+ headerHeight: number}export const breakpoints = Object.keys(ALL_SCREEN_SIZES)@@ -66,6 +67,7 @@ export const useUiStore = defineStore("ui", {dismissedBanners: [],shouldBlurSensitive: true,revealedSensitiveResults: [],+ headerHeight: 80,}),getters: {@@ -255,5 +257,8 @@ export const useUiStore = defineStore("ui", {this.shouldBlurSensitive = valuethis.revealedSensitiveResults = []},+ setHeaderHeight(height: number) {+ this.headerHeight = Math.max(height, 80)+ },},})diff --git a/frontend/test/playwright/e2e/recent-searches.spec.ts b/frontend/test/playwright/e2e/recent-searches.spec.tsindex 4e38c53c3..46b243419 100644--- a/frontend/test/playwright/e2e/recent-searches.spec.ts+++ b/frontend/test/playwright/e2e/recent-searches.spec.ts@@ -2,6 +2,7 @@ import { expect, test, type Page } from "@playwright/test"import {goToSearchTerm,+ isPageDesktop,preparePageForTests,searchFromHeader,sleep,@@ -23,22 +24,48 @@ const clearButton = async (page: Page) =>page.locator(`[aria-label="${clearRecentLabel}"]`)const clickClear = async (page: Page) => (await clearButton(page)).click()+const searchbarName = t("search.searchBarLabel").replace(+ "{openverse}",+ "Openverse"+)+const recentSearches = (page: Page) =>page.locator('[data-testid="recent-searches"]')const openRecentSearches = async (page: Page) => {if (!(await recentSearches(page).isVisible())) {- await page.locator('input[type="search"]').click()+ await page.getByRole("combobox", { name: searchbarName }).click()}}+const getFocusedElementName = async (page: Page) => {+ return await page.evaluate(() => {+ const el = document.activeElement as HTMLElement+ return el ? (el.getAttribute("aria-label") ?? el.textContent) : null+ })+}+const tabToSearchbar = async (page: Page) => {await page.getByRole("link", { name: t("skipToContent") }).focus()- for (let i = 0; i < 2; i++) {++ let focusedInputName = null+ while (focusedInputName !== searchbarName) {await page.keyboard.press("Tab")+ focusedInputName = await page.evaluate(() => {+ const el = document.activeElement as HTMLElement+ return el && el.nodeName === "INPUT"+ ? el.getAttribute("aria-label")+ : null+ })}}+const openRecentSearchesWithKeyboard = async (page: Page) => {+ await tabToSearchbar(page)+ expect(await getFocusedElementName(page)).toEqual(searchbarName)+ await page.keyboard.press("ArrowDown")+}+const executeSearches = async (page: Page) => {const searches = ["honey", "galah"] // in that orderfor (const term of searches) {@@ -48,6 +75,12 @@ const executeSearches = async (page: Page) => {return searches}+const getLastFocusableElementLabel = (page: Page, firstSearch: string) => {+ return isPageDesktop(page)+ ? clearRecentLabel+ : t("recentSearches.clearSingle.label").replace("{entry}", firstSearch)+}+breakpoints.describeMobileXsAndDesktop(({ breakpoint }) => {test.beforeEach(async ({ page }) => {await preparePageForTests(page, breakpoint)@@ -100,53 +133,76 @@ breakpoints.describeMobileXsAndDesktop(({ breakpoint }) => {const recentSearchesText = await getRecentSearchesText(page)expect(recentSearchesText).toContain(noRecentLabel)})+})- test("can open recent searches with keyboard", async ({ page }) => {- await executeSearches(page)- await tabToSearchbar(page)- await page.keyboard.press("ArrowDown")+breakpoints.describeMobileXsAndDesktop(({ breakpoint }) => {+ for (const dismissBanners of [true, false]) {+ test.beforeEach(async ({ page }) => {+ await preparePageForTests(page, breakpoint, { dismissBanners })+ // We are first navigating to search because the recent searches feature has+ // not yet been implemented on the homepage.+ await goToSearchTerm(page, "galah")+ })+ const bannerStatus = `${dismissBanners ? "without" : "with"} banners`- await expect(recentSearches(page)).toBeVisible()- })+ test(`can open recent searches with keyboard, ${bannerStatus}`, async ({+ page,+ }) => {+ await executeSearches(page)- test("can close the recent searches with escape key", async ({ page }) => {- await executeSearches(page)- await tabToSearchbar(page)+ await openRecentSearchesWithKeyboard(page)+ await expect(recentSearches(page)).toBeVisible()+ })- await page.keyboard.press("ArrowDown")- await expect(recentSearches(page)).toBeVisible()+ test(`can close the recent searches with escape key, ${bannerStatus}`, async ({+ page,+ }) => {+ await executeSearches(page)- await page.keyboard.press("Escape")- await sleep(300)- await expect(recentSearches(page)).toBeHidden()- })+ await openRecentSearchesWithKeyboard(page)+ await expect(recentSearches(page)).toBeVisible()- test("can navigate out of the recent searches with tab key", async ({- page,- }) => {- const searches = await executeSearches(page)- await tabToSearchbar(page)+ await page.keyboard.press("Escape")+ await sleep(300)+ await expect(recentSearches(page)).toBeHidden()+ })- await page.keyboard.press("ArrowDown")- await expect(recentSearches(page)).toBeVisible()+ test(`can navigate out of the recent searches with tab key, ${bannerStatus}`, async ({+ page,+ }) => {+ const searches = await executeSearches(page)- for (let i = 0; i < searches.length + 3; i++) {+ await openRecentSearchesWithKeyboard(page)++ await expect(recentSearches(page)).toBeVisible()++ const lastFocusableElementLabel = getLastFocusableElementLabel(+ page,+ searches[0]+ )++ let focused = await getFocusedElementName(page)+ while (focused !== lastFocusableElementLabel) {+ await page.keyboard.press("Tab")+ focused = await getFocusedElementName(page)+ }await page.keyboard.press("Tab")- }- await expect(recentSearches(page)).toBeHidden()- })- test("can navigate out of the recent searches using shift tab", async ({- page,- }) => {- await executeSearches(page)- await tabToSearchbar(page)+ await expect(recentSearches(page)).toBeHidden()+ })- await page.keyboard.press("ArrowDown")- await expect(recentSearches(page)).toBeVisible()+ test(`can navigate out of the recent searches using shift tab, ${bannerStatus}`, async ({+ page,+ }) => {+ await executeSearches(page)+ await tabToSearchbar(page)- await page.keyboard.press("Shift+Tab")- await page.keyboard.press("Shift+Tab")- await expect(recentSearches(page)).toBeHidden()- })+ await page.keyboard.press("ArrowDown")+ await expect(recentSearches(page)).toBeVisible()++ await page.keyboard.press("Shift+Tab")+ await page.keyboard.press("Shift+Tab")+ await expect(recentSearches(page)).toBeHidden()+ })+ }})