Skip to content

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

Fix homepage content switcher size (#827)

Olga Bulatf6f798e93257
diff --git a/src/components/VContentSwitcher/VContentSwitcherButton.vue b/src/components/VContentSwitcher/VContentSwitcherButton.vue
index b7cb1addd..0651cb3f0 100644
--- a/src/components/VContentSwitcher/VContentSwitcherButton.vue
+++ b/src/components/VContentSwitcher/VContentSwitcherButton.vue
@@ -40,7 +40,12 @@ export default {
activeItem: {
type: String,
default: ALL_MEDIA,
- validator: (val) => [ALL_MEDIA, IMAGE, AUDIO].includes(val),
+ validator: (v) => [ALL_MEDIA, IMAGE, AUDIO].includes(v),
+ },
+ type: {
+ type: String,
+ default: 'header',
+ validator: (v) => ['header', 'searchbar'].includes(v),
},
},
setup(props) {
@@ -52,13 +57,28 @@ export default {
const isIconButton = computed(
() => isHeaderScrolled?.value && !isMinScreenMd.value
)
- const sizeClasses = computed(() =>
- isIconButton.value ? 'w-10 h-10' : 'ps-2 pe-3'
- )
+ const sizeClasses = computed(() => {
+ if (props.type === 'searchbar') {
+ return 'h-12 px-2'
+ } else if (isIconButton.value) {
+ return 'w-10 h-10'
+ } else {
+ /**
+ When there is a caret down icon (on 'md' screens), paddings are balanced,
+ without it, paddings need to be adjusted.
+ */
+ return 'ps-2 pe-3 md:px-2'
+ }
+ })
+
const buttonVariant = computed(() => {
- return isMinScreenMd.value && !isHeaderScrolled?.value
- ? 'tertiary'
- : 'action-menu'
+ if (props.type === 'searchbar') {
+ return 'action-menu'
+ } else {
+ return isMinScreenMd.value && !isHeaderScrolled?.value
+ ? 'tertiary'
+ : 'action-menu'
+ }
})
const buttonLabel = computed(() => {
const labelKey = {
diff --git a/src/components/VContentSwitcher/VContentSwitcherPopover.vue b/src/components/VContentSwitcher/VContentSwitcherPopover.vue
index f6f611e87..75ebb5b8b 100644
--- a/src/components/VContentSwitcher/VContentSwitcherPopover.vue
+++ b/src/components/VContentSwitcher/VContentSwitcherPopover.vue
@@ -8,8 +8,14 @@
<template #trigger="{ a11yProps }">
<VContentSwitcherButton
:a11y-props="a11yProps"
- :active-item="activeItem"
aria-controls="content-switcher-popover"
+ :active-item="activeItem"
+ :class="{
+ '!border-tx': isInSearchBar,
+ 'group-hover:!border-dark-charcoal-20':
+ isInSearchBar && !a11yProps['aria-expanded'],
+ }"
+ :type="placement"
/>
</template>
<VContentTypes
@@ -22,7 +28,7 @@
</template>
<script>
-import { ref } from '@nuxtjs/composition-api'
+import { computed, ref } from '@nuxtjs/composition-api'
import useContentType from '~/composables/use-content-type'
import checkIcon from '~/assets/icons/checkmark.svg'
@@ -46,12 +52,23 @@ export default {
type: String,
required: true,
},
+ placement: {
+ type: String,
+ default: 'header',
+ },
},
setup(props, { emit }) {
const content = useContentType()
const contentMenuPopover = ref(null)
+ /**
+ * When in the searchbar, content switcher button has a border when the
+ * search bar group is hovered on.
+ * @type {ComputedRef<boolean>}
+ */
+ const isInSearchBar = computed(() => props.placement === 'searchbar')
+
/**
* Only the contentMenuPopover needs to be closed programmatically
*/
@@ -70,6 +87,7 @@ export default {
checkIcon,
selectItem,
contentMenuPopover,
+ isInSearchBar,
closeMenu,
}
},
diff --git a/src/pages/index.vue b/src/pages/index.vue
index 52505ec4c..bb3b74c0e 100644
--- a/src/pages/index.vue
+++ b/src/pages/index.vue
@@ -43,7 +43,7 @@
</div>
<VSearchBar
v-model.trim="searchTerm"
- class="max-w-[40rem] mt-4 lg:mt-8"
+ class="max-w-[40rem] mt-4 lg:mt-8 group"
size="standalone"
:placeholder="$t('hero.search.placeholder')"
@submit="handleSearch"
@@ -54,6 +54,7 @@
ref="contentSwitcher"
class="mx-3"
:active-item="contentType"
+ placement="searchbar"
@select="setContentType"
/>
</ClientOnly>