Skip to content

Openverse is a search engine for openly-licensed media. This monorepo includes all application code.

Tweak search bar styles in homepage (#788)

Krystle Salazar823207e6826d
diff --git a/src/components/VHeader/VHeader.vue b/src/components/VHeader/VHeader.vue
index 222bfb442..3411ae7d9 100644
--- a/src/components/VHeader/VHeader.vue
+++ b/src/components/VHeader/VHeader.vue
@@ -70,10 +70,7 @@ import {
} from '~/constants/action-types'
import { AUDIO, IMAGE } from '~/constants/media'
import { isMinScreen } from '~/composables/use-media-query'
-import {
- useMatchHomeRoute,
- useMatchSearchRoutes,
-} from '~/composables/use-match-routes'
+import { useMatchSearchRoutes } from '~/composables/use-match-routes'
import { useFilterSidebarVisibility } from '~/composables/use-filter-sidebar-visibility'
import { useI18nResultsCount } from '~/composables/use-i18n-utilities'
@@ -102,7 +99,6 @@ const VHeader = defineComponent({
const router = useRouter()
const { matches: isSearchRoute } = useMatchSearchRoutes()
- const { matches: isHomeRoute } = useMatchHomeRoute()
const isHeaderScrolled = inject('isHeaderScrolled')
const isMinScreenMd = isMinScreen('md', { shouldPassInSSR: true })
@@ -226,10 +222,8 @@ const VHeader = defineComponent({
isHeaderScrolled,
isMinScreenMd,
- headerHasTwoRows,
-
isSearchRoute,
- isHomeRoute,
+ headerHasTwoRows,
menuModalRef,
diff --git a/src/components/VHeader/VSearchBar/VSearchBar.vue b/src/components/VHeader/VSearchBar/VSearchBar.vue
index 14482166f..a2c583a7b 100644
--- a/src/components/VHeader/VSearchBar/VSearchBar.vue
+++ b/src/components/VHeader/VSearchBar/VSearchBar.vue
@@ -6,6 +6,7 @@
<VInputField
v-bind="$attrs"
class="flex-grow search-field"
+ :class="{ 'border-transparent': isHomeRoute }"
:label-text="$t('hero.aria.search')"
:connection-sides="['end']"
:size="size"
@@ -18,12 +19,13 @@
<!-- @slot Extra information such as loading message or result count goes here. -->
<slot />
</VInputField>
- <VSearchButton type="submit" :size="size" />
+ <VSearchButton type="submit" :size="size" :is-home-route="isHomeRoute" />
</form>
</template>
<script>
import { computed, defineComponent } from '@nuxtjs/composition-api'
+import { useMatchHomeRoute } from '~/composables/use-match-routes'
import VInputField from '~/components/VInputField/VInputField.vue'
import VSearchButton from '~/components/VHeader/VSearchBar/VSearchButton.vue'
@@ -35,10 +37,7 @@ import VSearchButton from '~/components/VHeader/VSearchBar/VSearchButton.vue'
*/
const VSearchBar = defineComponent({
name: 'VSearchBar',
- components: {
- VInputField,
- VSearchButton,
- },
+ components: { VInputField, VSearchButton },
inheritAttrs: false,
props: {
/**
@@ -56,6 +55,8 @@ const VSearchBar = defineComponent({
},
emits: ['input', 'submit'],
setup(props, { emit }) {
+ const { matches: isHomeRoute } = useMatchHomeRoute()
+
const searchText = computed(() => props.value)
const updateSearchText = (val) => {
emit('input', val)
@@ -67,6 +68,7 @@ const VSearchBar = defineComponent({
return {
handleSearch,
+ isHomeRoute,
searchText,
updateSearchText,
}
@@ -83,4 +85,9 @@ export default VSearchBar
.search-field input[type='search']::-webkit-search-results-decoration {
-webkit-appearance: none;
}
+
+/* Necessary to avoid flickering and just 'border-tx' inline class isn't working here */
+.search-field.border-transparent {
+ border-color: transparent;
+}
</style>
diff --git a/src/components/VHeader/VSearchBar/VSearchButton.vue b/src/components/VHeader/VSearchBar/VSearchButton.vue
index 4da2e1a11..6deb53fc2 100644
--- a/src/components/VHeader/VSearchBar/VSearchButton.vue
+++ b/src/components/VHeader/VSearchBar/VSearchButton.vue
@@ -1,15 +1,33 @@
<template>
- <VIconButton
- v-bind="$attrs"
- :size="`search-${size}`"
- class="search-button hover:text-white group-hover:text-white hover:bg-pink group-hover:bg-pink p-0.5px ps-1.5px focus:p-0 border md:border border-dark-charcoal-20 hover:border-pink group-hover:border-pink rounded-e-sm active:shadow-ring"
- :icon-props="{ iconPath: searchIcon }"
- :aria-label="$t('search.search')"
- v-on="$listeners"
- />
+ <div>
+ <VButton
+ v-if="isHomeRoute && isMinScreenMd"
+ v-bind="$attrs"
+ :aria-label="$t('search.search')"
+ class="inline-block cta-search-button font-semibold h-full text-2xl"
+ v-on="$listeners"
+ >{{ $t('search.search') }}</VButton
+ >
+ <VIconButton
+ v-else
+ v-bind="$attrs"
+ :size="`search-${size}`"
+ class="search-button hover:text-white group-hover:text-white hover:bg-pink group-hover:bg-pink p-0.5px ps-1.5px focus:p-0 border hover:border-pink group-hover:border-pink rounded-e-sm active:shadow-ring"
+ :class="[
+ isHomeRoute
+ ? 'bg-pink text-white border-tx'
+ : 'border-dark-charcoal-20',
+ ]"
+ :icon-props="{ iconPath: searchIcon }"
+ :aria-label="$t('search.search')"
+ v-on="$listeners"
+ />
+ </div>
</template>
<script>
+import { isMinScreen } from '~/composables/use-media-query'
+
import VIconButton from '~/components/VIconButton/VIconButton.vue'
import searchIcon from '~/assets/icons/search.svg'
@@ -24,14 +42,24 @@ export default {
required: true,
validator: (v) => ['small', 'medium', 'large', 'standalone'].includes(v),
},
+ isHomeRoute: {
+ type: Boolean,
+ default: false,
+ },
},
setup() {
- return { searchIcon }
+ const isMinScreenMd = isMinScreen('md', { shouldPassInSSR: true })
+
+ return { isMinScreenMd, searchIcon }
},
}
</script>
-<style>
+<style scoped>
+.cta-search-button {
+ @apply py-6 px-10 rounded-s-none border-b border-b-pink;
+}
+
/* @todo: Find a better way to override the VIconButton border styles */
.search-button {
/* Negative margin removes a tiny gap between the button and the input borders */
diff --git a/src/locales/po-files/openverse.pot b/src/locales/po-files/openverse.pot
index 7a5823bcf..9c6b419ee 100644
--- a/src/locales/po-files/openverse.pot
+++ b/src/locales/po-files/openverse.pot
@@ -182,7 +182,7 @@ msgctxt "audio-categories.pronunciation"
msgid "Pronunciation"
msgstr ""
-#: src/components/VHeader/VSearchBar/VSearchButton.vue:7
+#: src/components/VHeader/VSearchBar/VSearchButton.vue:6
msgctxt "search.search"
msgid "Search"
msgstr ""
@@ -1934,7 +1934,7 @@ msgctxt "header.api-nav-item"
msgid "API"
msgstr ""
-#: src/components/VHeader/VHeader.vue:163
+#: src/components/VHeader/VHeader.vue:159
msgctxt "header.loading"
msgid "Loading..."
msgstr ""
@@ -2002,7 +2002,7 @@ msgctxt "hero.subtitle"
msgid "Browse through over 600 million items to reuse"
msgstr ""
-#: src/components/VHeader/VSearchBar/VSearchBar.vue:9
+#: src/components/VHeader/VSearchBar/VSearchBar.vue:10
msgctxt "hero.aria.search"
msgid "search"
msgstr ""
diff --git a/src/pages/index.vue b/src/pages/index.vue
index d038bcb38..52505ec4c 100644
--- a/src/pages/index.vue
+++ b/src/pages/index.vue
@@ -68,6 +68,8 @@
<template #license>
<a
href="https://creativecommons.org/licenses/"
+ target="blank"
+ rel="noopener noreferrer"
class="text-dark-charcoal hover:text-dark-charcoal underline"
>{{ $t('hero.disclaimer.license') }}</a
>
@@ -118,6 +120,8 @@
<template #license>
<a
href="https://creativecommons.org/licenses/"
+ target="blank"
+ rel="noopener noreferrer"
class="text-dark-charcoal hover:text-dark-charcoal underline"
>{{ $t('hero.disclaimer.license') }}</a
>
diff --git a/test/unit/specs/components/VHeader/SearchBar/search-bar.spec.js b/test/unit/specs/components/VHeader/SearchBar/search-bar.spec.js
index 489c57209..a7cc09bfa 100644
--- a/test/unit/specs/components/VHeader/SearchBar/search-bar.spec.js
+++ b/test/unit/specs/components/VHeader/SearchBar/search-bar.spec.js
@@ -1,29 +1,48 @@
import { render, screen } from '@testing-library/vue'
-
+import { useMatchHomeRoute } from '~/composables/use-match-routes'
import SearchBar from '~/components/VHeader/VSearchBar/VSearchBar.vue'
+jest.mock('~/composables/use-match-routes', () => ({
+ useMatchHomeRoute: jest.fn(),
+}))
+
+const sizes = ['small', 'medium', 'large', 'standalone']
+
describe('SearchBar', () => {
- it('renders an input field with placeholder and type="search"', () => {
- render(SearchBar, {
- attrs: {
- placeholder: 'Enter search query',
- },
- })
-
- const inputElement = screen.getByPlaceholderText('Enter search query')
-
- expect(inputElement.tagName).toBe('INPUT')
- expect(inputElement).toHaveAttribute('type', 'search')
- expect(inputElement).toHaveAttribute('placeholder', 'Enter search query')
+ let options
+ beforeEach(() => {
+ options = {
+ attrs: { placeholder: 'Enter search query' },
+ }
})
- it('renders a button with type="submit", ARIA label and SR text', () => {
- render(SearchBar)
+ it.each(sizes)(
+ 'renders an input field with placeholder and type="search" (%s size)',
+ (size) => {
+ useMatchHomeRoute.mockImplementation(() => false)
+ options.props = { size: size }
+ render(SearchBar, options)
- const btnElement = screen.getByLabelText('search.search')
+ const inputElement = screen.getByPlaceholderText('Enter search query')
- expect(btnElement.tagName).toBe('BUTTON')
- expect(btnElement).toHaveAttribute('type', 'submit')
- expect(btnElement).toHaveAttribute('aria-label', 'search.search')
- })
+ expect(inputElement.tagName).toBe('INPUT')
+ expect(inputElement).toHaveAttribute('type', 'search')
+ expect(inputElement).toHaveAttribute('placeholder', 'Enter search query')
+ }
+ )
+
+ it.each(sizes)(
+ 'renders a button with type="submit", ARIA label and SR text (%s size)',
+ (size) => {
+ useMatchHomeRoute.mockImplementation(() => false)
+ options.props = { size: size }
+ render(SearchBar, options)
+
+ const btnElement = screen.getByLabelText('search.search')
+
+ expect(btnElement.tagName).toBe('BUTTON')
+ expect(btnElement).toHaveAttribute('type', 'submit')
+ expect(btnElement).toHaveAttribute('aria-label', 'search.search')
+ }
+ )
})