Skip to content

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

Convert the last components to script-setup (#4805)

Olga Bulat44db880d61c2
diff --git a/frontend/src/components/TableSortIcon.vue b/frontend/src/components/TableSortIcon.vue
index 7fd5cb51f..e8b7633ff 100644
--- a/frontend/src/components/TableSortIcon.vue
+++ b/frontend/src/components/TableSortIcon.vue
@@ -1,15 +1,5 @@
-<script lang="ts">
-import { defineComponent } from "vue"
-
-export default defineComponent({
- name: "TableSortIcon",
- props: {
- active: {
- type: Boolean,
- required: true,
- },
- },
-})
+<script setup lang="ts">
+defineProps<{ active: boolean }>()
</script>
<template>
diff --git a/frontend/src/components/VCollectionHeader/VCollectionHeader.vue b/frontend/src/components/VCollectionHeader/VCollectionHeader.vue
index 825c36666..9b138052c 100644
--- a/frontend/src/components/VCollectionHeader/VCollectionHeader.vue
+++ b/frontend/src/components/VCollectionHeader/VCollectionHeader.vue
@@ -1,5 +1,5 @@
-<script lang="ts">
-import { computed, defineComponent, type PropType } from "vue"
+<script setup lang="ts">
+import { computed } from "vue"
import { useAnalytics } from "~/composables/use-analytics"
@@ -24,129 +24,104 @@ const icons = {
/**
* Renders the header of a tag/creator/source collection page.
*/
-export default defineComponent({
- name: "VCollectionHeader",
- components: { VScrollableLine, VIcon, VButton },
- props: {
- collectionParams: {
- type: Object as PropType<CollectionParams>,
- required: true,
- },
- creatorUrl: {
- type: String,
- },
- mediaType: {
- type: String as PropType<SupportedMediaType>,
- required: true,
- },
- },
- setup(props) {
- const mediaStore = useMediaStore()
- const providerStore = useProviderStore()
- const searchStore = useSearchStore()
-
- const iconName = computed(() => icons[props.collectionParams.collection])
- const collection = computed(() => props.collectionParams.collection)
-
- const source = computed(() => {
- if (props.collectionParams.collection === "tag") {
- return {
- name: "",
- link: "",
- }
- }
- return {
- name: providerStore.getProviderName(
- props.collectionParams.source,
- props.mediaType
- ),
- link: providerStore.getSourceUrl(
- props.collectionParams.source,
- props.mediaType
- ),
- }
- })
-
- const title = computed(() => {
- if (props.collectionParams.collection === "tag") {
- return props.collectionParams.tag
- } else if (props.collectionParams.collection === "creator") {
- return props.collectionParams.creator
- }
- return source.value.name
- })
-
- const url = computed(() => {
- if (props.collectionParams.collection === "tag") {
- return undefined
- } else if (props.collectionParams.collection === "creator") {
- return props.creatorUrl
- }
- return source.value.link
- })
-
- const sourceCollectionLink = computed(() => {
- if (props.collectionParams.collection !== "creator") {
- return ""
- }
- return searchStore.getCollectionPath({
- type: props.mediaType,
- collectionParams: {
- collection: "source",
- source: props.collectionParams.source,
- },
- })
- })
-
- const showCollectionExternalLink = computed(() => {
- return Boolean(props.collectionParams.collection !== "tag" && url.value)
- })
-
- const { getI18nCollectionResultCountLabel } = useI18nResultsCount()
-
- const resultsLabel = computed(() => {
- if (mediaStore.resultCount === 0 && mediaStore.fetchState.isFetching) {
- return ""
- }
- const resultsCount = mediaStore.results[props.mediaType].count
-
- return getI18nCollectionResultCountLabel(
- resultsCount,
- props.mediaType,
- props.collectionParams.collection
- )
- })
-
- const { sendCustomEvent } = useAnalytics()
-
- const sendAnalyticsEvent = () => {
- if (props.collectionParams.collection === "tag") {
- return
- }
-
- const eventName =
- props.collectionParams.collection === "creator"
- ? "VISIT_CREATOR_LINK"
- : "VISIT_SOURCE_LINK"
- sendCustomEvent(eventName, {
- url: url.value,
- source: props.collectionParams.source,
- })
- }
+const props = defineProps<{
+ mediaType: SupportedMediaType
+ collectionParams: CollectionParams
+ creatorUrl?: string
+}>()
+
+const mediaStore = useMediaStore()
+const providerStore = useProviderStore()
+const searchStore = useSearchStore()
+const iconName = computed(() => icons[props.collectionParams.collection])
+const collection = computed(() => props.collectionParams.collection)
+
+const source = computed(() => {
+ if (props.collectionParams.collection === "tag") {
return {
- collection,
- title,
- resultsLabel,
- source,
- url,
- sourceCollectionLink,
- showCollectionExternalLink,
- iconName,
- sendAnalyticsEvent,
+ name: "",
+ link: "",
}
- },
+ }
+ return {
+ name: providerStore.getProviderName(
+ props.collectionParams.source,
+ props.mediaType
+ ),
+ link: providerStore.getSourceUrl(
+ props.collectionParams.source,
+ props.mediaType
+ ),
+ }
+})
+
+const title = computed(() => {
+ if (props.collectionParams.collection === "tag") {
+ return props.collectionParams.tag
+ } else if (props.collectionParams.collection === "creator") {
+ return props.collectionParams.creator
+ }
+ return source.value.name
+})
+
+const url = computed(() => {
+ if (props.collectionParams.collection === "tag") {
+ return undefined
+ } else if (props.collectionParams.collection === "creator") {
+ return props.creatorUrl
+ }
+ return source.value.link
+})
+
+const sourceCollectionLink = computed(() => {
+ if (props.collectionParams.collection !== "creator") {
+ return ""
+ }
+ return searchStore.getCollectionPath({
+ type: props.mediaType,
+ collectionParams: {
+ collection: "source",
+ source: props.collectionParams.source,
+ },
+ })
+})
+
+const showCollectionExternalLink = computed(() => {
+ return Boolean(props.collectionParams.collection !== "tag" && url.value)
+})
+
+const { getI18nCollectionResultCountLabel } = useI18nResultsCount()
+
+const resultsLabel = computed(() => {
+ if (mediaStore.resultCount === 0 && mediaStore.fetchState.isFetching) {
+ return ""
+ }
+ const resultsCount = mediaStore.results[props.mediaType].count
+
+ return getI18nCollectionResultCountLabel(
+ resultsCount,
+ props.mediaType,
+ props.collectionParams.collection
+ )
})
+
+const { sendCustomEvent } = useAnalytics()
+
+const sendAnalyticsEvent = () => {
+ if (props.collectionParams.collection === "tag") {
+ return
+ }
+
+ const eventName =
+ props.collectionParams.collection === "creator"
+ ? "VISIT_CREATOR_LINK"
+ : "VISIT_SOURCE_LINK"
+ sendCustomEvent(eventName, {
+ url: url.value,
+ source: props.collectionParams.source,
+ })
+}
</script>
<template>
diff --git a/frontend/src/components/VContentPage.vue b/frontend/src/components/VContentPage.vue
index 2cb907e2f..7ccb8c542 100644
--- a/frontend/src/components/VContentPage.vue
+++ b/frontend/src/components/VContentPage.vue
@@ -1,16 +1,5 @@
-<script lang="ts">
-import { defineComponent } from "vue"
-
+<script setup lang="ts">
import { skipToContentTargetId } from "~/constants/window"
-
-export default defineComponent({
- name: "VContentPage",
- setup() {
- return {
- skipToContentTargetId,
- }
- },
-})
</script>
<template>
diff --git a/frontend/src/components/VFooter/VFooter.vue b/frontend/src/components/VFooter/VFooter.vue
index ca326f8f4..87880908d 100644
--- a/frontend/src/components/VFooter/VFooter.vue
+++ b/frontend/src/components/VFooter/VFooter.vue
@@ -1,5 +1,9 @@
-<script lang="ts">
-import { computed, defineComponent, PropType, ref } from "vue"
+<script setup lang="ts">
+/**
+ * The footer is the section displayed at the bottom of a page. It can contain
+ * some branding, links to other pages and an option to change the language.
+ */
+import { computed, ref } from "vue"
import usePages from "~/composables/use-pages"
import useResizeObserver from "~/composables/use-resize-observer"
@@ -15,74 +19,50 @@ import VLanguageSelect from "~/components/VLanguageSelect/VLanguageSelect.vue"
import VPageLinks from "~/components/VHeader/VPageLinks.vue"
import VWordPressLink from "~/components/VHeader/VWordPressLink.vue"
-/**
- * The footer is the section displayed at the bottom of a page. It can contain
- * some branding, links to other pages and an option to change the language.
- */
-export default defineComponent({
- name: "VFooter",
- components: {
- VWordPressLink,
- VPageLinks,
- VLanguageSelect,
- VLink,
- VBrand,
- },
- props: {
+type FooterMode = "internal" | "content"
+
+const props = withDefaults(
+ defineProps<{
/**
* whether the footer is being rendered on a search page or an internal
* page (about, feedback, etc.); This determines whether the Openverse
* logo and other links are displayed.
* Search pages use "content" footer.
*/
- mode: {
- type: String as PropType<"internal" | "content">,
- required: false,
- },
- languageProps: {
- type: Object as PropType<SelectFieldProps>,
- default: () => ({}),
- },
- },
- setup(props) {
- const uiStore = useUiStore()
- const { all: allPages, current: currentPage } = usePages()
-
- const isContentMode = computed(() => props.mode === "content")
-
- /** JS-based responsiveness */
- const footerEl = ref<HTMLElement | null>(null)
- const initialWidth = SCREEN_SIZES[uiStore.breakpoint]
- const { dimens: footerDimens } = useResizeObserver(footerEl, {
- initialWidth,
- })
-
- /**
- * Return a list of all breakpoints that are smaller than the current screen width. This allows us to use the smallest variant class to target CSS styles.
- *
- * I.e., with a width at 1200, the footer will have `footer-2xl footer-lg`. Using `footer-lg`, we can apply styles to both `footer-2xl` and `footer-lg`.
- */
- const variantNames = computed(() =>
- Object.entries(SCREEN_SIZES)
- .filter(([, val]) => footerDimens.value.width >= val)
- .map(([key]) => `footer-${key}`)
- )
-
- const linkColumnHeight = computed(() => ({
- "--link-col-height": Math.ceil(Object.keys(allPages).length / 2),
- }))
-
- return {
- isContentMode,
- allPages,
- currentPage,
-
- footerEl,
- variantNames,
- linkColumnHeight,
- }
- },
+ mode: FooterMode
+ languageProps?: SelectFieldProps
+ }>(),
+ {
+ languageProps: () => ({}),
+ }
+)
+
+const uiStore = useUiStore()
+const { all: allPages } = usePages()
+
+const isContentMode = computed(() => props.mode === "content")
+
+/** JS-based responsiveness */
+const footerEl = ref<HTMLElement | null>(null)
+const initialWidth = SCREEN_SIZES[uiStore.breakpoint]
+const { dimens: footerDimens } = useResizeObserver(footerEl, {
+ initialWidth,
})
+
+/**
+ * Return a list of all breakpoints that are smaller than the current screen width. This allows us to use the smallest variant class to target CSS styles.
+ *
+ * I.e., with a width at 1200, the footer will have `footer-2xl footer-lg`. Using `footer-lg`, we can apply styles to both `footer-2xl` and `footer-lg`.
+ */
+const variantNames = computed(() =>
+ Object.entries(SCREEN_SIZES)
+ .filter(([, val]) => footerDimens.value.width >= val)
+ .map(([key]) => `footer-${key}`)
+)
+
+const linkColumnHeight = computed(() => ({
+ "--link-col-height": Math.ceil(Object.keys(allPages).length / 2),
+}))
</script>
<template>
diff --git a/frontend/src/components/VFourOhFour.vue b/frontend/src/components/VFourOhFour.vue
index 80ac6ff79..638248dfe 100644
--- a/frontend/src/components/VFourOhFour.vue
+++ b/frontend/src/components/VFourOhFour.vue
@@ -1,8 +1,6 @@
-<script lang="ts">
+<script setup lang="ts">
import { navigateTo, useHead } from "#imports"
-import { defineComponent } from "vue"
-
import { useSearchStore } from "~/stores/search"
import { useAnalytics } from "~/composables/use-analytics"
@@ -13,40 +11,27 @@ import VLink from "~/components/VLink.vue"
import VStandaloneSearchBar from "~/components/VHeader/VSearchBar/VStandaloneSearchBar.vue"
import VSvg from "~/components/VSvg/VSvg.vue"
-export default defineComponent({
- name: "VFourOhFour",
- components: {
- VLink,
- VStandaloneSearchBar,
- VSvg,
- },
- props: ["error"],
- setup() {
- const searchStore = useSearchStore()
+import type { NuxtError } from "#app"
- const { sendCustomEvent } = useAnalytics()
+defineProps<{ error: NuxtError }>()
- const handleSearch = (searchTerm: string) => {
- sendCustomEvent("SUBMIT_SEARCH", {
- searchType: ALL_MEDIA,
- query: searchTerm,
- })
+const searchStore = useSearchStore()
- return navigateTo(
- searchStore.updateSearchPath({ type: ALL_MEDIA, searchTerm })
- )
- }
+const { sendCustomEvent } = useAnalytics()
- useHead({
- meta: [{ hid: "theme-color", name: "theme-color", content: "#ffe033" }],
- })
+const handleSearch = (searchTerm: string) => {
+ sendCustomEvent("SUBMIT_SEARCH", {
+ searchType: ALL_MEDIA,
+ query: searchTerm,
+ })
- return {
- handleSearch,
+ return navigateTo(
+ searchStore.updateSearchPath({ type: ALL_MEDIA, searchTerm })
+ )
+}
- skipToContentTargetId,
- }
- },
+useHead({
+ meta: [{ hid: "theme-color", name: "theme-color", content: "#ffe033" }],
})
</script>
diff --git a/frontend/src/components/VGlobalAudioSection/VGlobalAudioSection.vue b/frontend/src/components/VGlobalAudioSection/VGlobalAudioSection.vue
index 097b9a820..c79c6baf2 100644
--- a/frontend/src/components/VGlobalAudioSection/VGlobalAudioSection.vue
+++ b/frontend/src/components/VGlobalAudioSection/VGlobalAudioSection.vue
@@ -1,7 +1,7 @@
-<script lang="ts">
+<script setup lang="ts">
import { useRoute } from "#imports"
-import { watch, computed, defineComponent } from "vue"
+import { watch, computed } from "vue"
import { AUDIO } from "~/constants/media"
import { useActiveAudio } from "~/composables/use-active-audio"
@@ -18,129 +18,114 @@ import { getRouteNameString } from "~/utils/route-utils"
import VIconButton from "~/components/VIconButton/VIconButton.vue"
import VGlobalAudioTrack from "~/components/VAudioTrack/VGlobalAudioTrack.vue"
-export default defineComponent({
- name: "VGlobalAudioSection",
- components: {
- VIconButton,
- VGlobalAudioTrack,
- },
- setup() {
- const route = useRoute()
-
- const activeMediaStore = useActiveMediaStore()
- const mediaStore = useMediaStore()
- const uiStore = useUiStore()
-
- const activeAudio = useActiveAudio()
-
- /* Active audio track */
- const getAudioItemById = (trackId: string): AudioDetail | null => {
- const audioFromMediaStore = mediaStore.getItemById(AUDIO, trackId)
- if (audioFromMediaStore) {
- return audioFromMediaStore as AudioDetail
- }
- const singleResultStore = useSingleResultStore()
- if (singleResultStore.mediaId === trackId) {
- return singleResultStore.audio
- }
- return null
- }
- const audio = computed(() => {
- const trackId = activeMediaStore.id
- if (trackId) {
- return getAudioItemById(trackId)
- }
- return null
- })
+const route = useRoute()
+
+const activeMediaStore = useActiveMediaStore()
+const mediaStore = useMediaStore()
+const uiStore = useUiStore()
+
+const activeAudio = useActiveAudio()
+
+/* Active audio track */
+const getAudioItemById = (trackId: string): AudioDetail | null => {
+ const audioFromMediaStore = mediaStore.getItemById(AUDIO, trackId)
+ if (audioFromMediaStore) {
+ return audioFromMediaStore as AudioDetail
+ }
+ const singleResultStore = useSingleResultStore()
+ if (singleResultStore.mediaId === trackId) {
+ return singleResultStore.audio
+ }
+ return null
+}
+const audio = computed(() => {
+ const trackId = activeMediaStore.id
+ if (trackId) {
+ return getAudioItemById(trackId)
+ }
+ return null
+})
- /* Message */
-
- const handleError = (event: Event) => {
- if (!(event.target instanceof HTMLAudioElement)) {
- activeMediaStore.setMessage({ message: "err_unknown" })
- return
- }
- const error = event.target.error
- if (!error) {
- return
- }
- let errorMsg
- switch (error.code) {
- case error.MEDIA_ERR_ABORTED: {
- errorMsg = "err_aborted"
- break
- }
- case error.MEDIA_ERR_NETWORK: {
- errorMsg = "err_network"
- break
- }
- case error.MEDIA_ERR_DECODE: {
- errorMsg = "err_decode"
- break
- }
- case error.MEDIA_ERR_SRC_NOT_SUPPORTED: {
- errorMsg = "err_unsupported"
- break
- }
- default: {
- errorMsg = "err_unknown"
- }
- }
- activeMediaStore.setMessage({ message: errorMsg })
+/* Message */
+
+const handleError = (event: Event) => {
+ if (!(event.target instanceof HTMLAudioElement)) {
+ activeMediaStore.setMessage({ message: "err_unknown" })
+ return
+ }
+ const error = event.target.error
+ if (!error) {
+ return
+ }
+ let errorMsg
+ switch (error.code) {
+ case error.MEDIA_ERR_ABORTED: {
+ errorMsg = "err_aborted"
+ break
+ }
+ case error.MEDIA_ERR_NETWORK: {
+ errorMsg = "err_network"
+ break
+ }
+ case error.MEDIA_ERR_DECODE: {
+ errorMsg = "err_decode"
+ break
+ }
+ case error.MEDIA_ERR_SRC_NOT_SUPPORTED: {
+ errorMsg = "err_unsupported"
+ break
+ }
+ default: {
+ errorMsg = "err_unknown"
}
+ }
+ activeMediaStore.setMessage({ message: errorMsg })
+}
+
+watch(
+ activeAudio.obj,
+ (audio, _, onInvalidate) => {
+ if (!audio) {
+ return
+ }
+ audio.addEventListener("error", handleError)
- watch(
- activeAudio.obj,
- (audio, _, onInvalidate) => {
- if (!audio) {
- return
- }
- audio.addEventListener("error", handleError)
-
- onInvalidate(() => {
- audio.removeEventListener("error", handleError)
- })
- },
- { immediate: true }
- )
-
- const handleClose = () => {
+ onInvalidate(() => {
+ audio.removeEventListener("error", handleError)
+ })
+ },
+ { immediate: true }
+)
+
+const handleClose = () => {
+ activeAudio.obj.value?.pause()
+ activeAudio.obj.value = undefined
+ activeMediaStore.ejectActiveMediaItem()
+}
+
+/**
+ * Router observation
+ *
+ * The player will continue only within 'search-audio' and 'audio-id' routes,
+ * and on desktop, only if the next route is the 'audio-id' page of the
+ * track currently playing, or the original search result page.
+ */
+watch(
+ () => route,
+ (newRouteVal, oldRouteVal) => {
+ const oldName = getRouteNameString(oldRouteVal)
+ const newName = getRouteNameString(newRouteVal)
+ if (
+ (oldName.includes("audio") && !newName.includes("audio")) ||
+ (uiStore.isDesktopLayout &&
+ newName.includes("audio-id") &&
+ newRouteVal.params.id != activeMediaStore.id)
+ ) {
activeAudio.obj.value?.pause()
- activeAudio.obj.value = undefined
activeMediaStore.ejectActiveMediaItem()
}
-
- /**
- * Router observation
- *
- * The player will continue only within 'search-audio' and 'audio-id' routes,
- * and on desktop, only if the next route is the 'audio-id' page of the
- * track currently playing, or the original search result page.
- */
- watch(
- () => route,
- (newRouteVal, oldRouteVal) => {
- const oldName = getRouteNameString(oldRouteVal)
- const newName = getRouteNameString(newRouteVal)
- if (
- (oldName.includes("audio") && !newName.includes("audio")) ||
- (uiStore.isDesktopLayout &&
- newName.includes("audio-id") &&
- newRouteVal.params.id != activeMediaStore.id)
- ) {
- activeAudio.obj.value?.pause()
- activeMediaStore.ejectActiveMediaItem()
- }
- }
- )
-
- return {
- audio,
-
- handleClose,
- }
- },
-})
+ }
+)
</script>
<template>
diff --git a/frontend/src/components/VHeader/VSearchBar/VSearchBar.vue b/frontend/src/components/VHeader/VSearchBar/VSearchBar.vue
index 1ca00cb11..29843a70e 100644
--- a/frontend/src/components/VHeader/VSearchBar/VSearchBar.vue
+++ b/frontend/src/components/VHeader/VSearchBar/VSearchBar.vue
@@ -12,9 +12,7 @@ import { onClickOutside } from "@vueuse/core"
import { useRecentSearches } from "~/composables/use-recent-searches"
-import VInputField, {
- FIELD_SIZES,
-} from "~/components/VInputField/VInputField.vue"
+import VInputField from "~/components/VInputField/VInputField.vue"
import VSearchButton from "~/components/VHeader/VSearchBar/VSearchButton.vue"
import VRecentSearches from "~/components/VRecentSearches/VRecentSearches.vue"
@@ -26,12 +24,10 @@ const props = withDefaults(
* the search query given as input to the field
*/
modelValue?: string
- size?: keyof typeof FIELD_SIZES
placeholder?: string
}>(),
{
modelValue: "",
- size: "medium",
}
)
@@ -57,11 +53,8 @@ const handleSearch = () => {
/* Recent searches */
const recentClasses = computed(() => {
- // Calculated by adding 8px to all heights defined in `VInputField.vue`.
- const FIELD_OFFSETS = {
- medium: "top-14",
- } as const
- return FIELD_OFFSETS[props.size]
+ // Calculated by adding 8px to the height of `VInputField.vue`.
+ return "top-14"
})
const focusInput = () => {
inputFieldRef.value?.focusInput()
@@ -124,7 +117,6 @@ const nonClassAttrs = computed(() => {
class="search-field flex-grow border-tx bg-secondary text-secondary focus-within:bg-default focus:border-focus group-hover:bg-secondary group-hover:text-default group-hover:focus-within:bg-default"
:label-text="$t('search.searchBarLabel', { openverse: 'Openverse' })"
:connection-sides="['end']"
- :size="size"
field-id="search-bar"
type="search"
autocomplete="off"
diff --git a/frontend/src/components/VIconButton/VIconButton.vue b/frontend/src/components/VIconButton/VIconButton.vue
index b35e11614..0b28d986f 100644
--- a/frontend/src/components/VIconButton/VIconButton.vue
+++ b/frontend/src/components/VIconButton/VIconButton.vue
@@ -1,5 +1,9 @@
-<script lang="ts">
-import { computed, defineComponent, PropType } from "vue"
+<script setup lang="ts">
+/**
+ * The icon-only version of VButton component. In some cases, VButton is replaced
+ * with VIconButton in small breakpoints.
+ */
+import { computed } from "vue"
import type {
ButtonConnections,
@@ -10,59 +14,31 @@ import type {
import VIcon, { type IconProps } from "~/components/VIcon/VIcon.vue"
import VButton from "~/components/VButton.vue"
-import type { TranslateResult } from "vue-i18n"
+const props = defineProps<{
+ /**
+ * The size of the button, matches the sizes of VButton component.
+ */
+ size: ButtonSize
+ /**
+ * The visual variant of the button, matches the variants of VButton component.
+ */
+ variant: ButtonVariant
+ /**
+ * Props to pass down to the `VIcon` component nested inside the button.
+ * See documentation on `VIcon`.
+ */
+ iconProps?: IconProps
+ /**
+ * Connections to pass down to the `VButton` component nested inside the button.
+ */
+ connections?: ButtonConnections[]
+ /**
+ * The label used for accessibility purposes.
+ */
+ label: string
+}>()
-/**
- * The icon-only version of VButton component. In some cases, VButton is replaced
- * with VIconButton in small breakpoints.
- */
-export default defineComponent({
- name: "VIconButton",
- components: { VIcon, VButton },
- props: {
- /**
- * The size of the button, matches the sizes of VButton component.
- */
- size: {
- type: String as PropType<ButtonSize>,
- required: true,
- },
- /**
- * The visual variant of the button, matches the variants of VButton component.
- */
- variant: {
- type: String as PropType<ButtonVariant>,
- required: true,
- },
- /**
- * Props to pass down to the `VIcon` component nested inside the button.
- * See documentation on `VIcon`.
- */
- iconProps: {
- type: Object as PropType<IconProps>,
- required: false,
- },
- /**
- * Connections to pass down to the `VButton` component nested inside the button.
- */
- connections: {
- type: Array as PropType<ButtonConnections[]>,
- },
- /**
- * The label used for accessibility purposes.
- */
- label: {
- type: [String, Object] as PropType<string | TranslateResult>,
- required: true,
- },
- },
- setup(props) {
- const iconSize = computed(() => props.iconProps?.size ?? 6)
- return {
- iconSize,
- }
- },
-})
+const iconSize = computed(() => props.iconProps?.size ?? 6)
</script>
<template>
diff --git a/frontend/src/components/VInputField/VInputField.vue b/frontend/src/components/VInputField/VInputField.vue
index 564bf837a..c136b0d40 100644
--- a/frontend/src/components/VInputField/VInputField.vue
+++ b/frontend/src/components/VInputField/VInputField.vue
@@ -1,120 +1,67 @@
-<script lang="ts">
-import {
- ref,
- computed,
- defineComponent,
- PropType,
- InputTypeHTMLAttribute,
-} from "vue"
-
-import { defineEvent } from "~/types/emits"
-
-export const FIELD_SIZES = {
- medium: "h-12",
-} as const
-export type FieldSize = keyof typeof FIELD_SIZES
-
+<script setup lang="ts">
/**
* Provides a control to enter text as input.
*/
-export default defineComponent({
- name: "VInputField",
- inheritAttrs: false,
- model: {
- prop: "modelValue",
- event: "update:modelValue",
- },
- props: {
- /**
- * the textual content of the input field
- */
- modelValue: {
- type: String,
- default: "",
- },
+import { ref, computed, useAttrs, type InputTypeHTMLAttribute } from "vue"
+
+defineOptions({ inheritAttrs: false })
+/**
+ * the textual content of the input field
+ */
+const modelValue = defineModel<string>()
+type Connection = "start" | "end"
+
+withDefaults(
+ defineProps<{
/**
* the textual content of the label associated with this input field; This
* label is SR-only. If you want to display a visible label, add
* `for="fieldId"` to the label element and set the `fieldId` prop to the
* same value as the `for` attribute.
*/
- labelText: {
- type: String,
- },
+ labelText?: string
/**
* the ID to assign to the field; This can be used to attach custom labels
* to the field.
*/
- fieldId: {
- type: String,
- required: true,
- },
+ fieldId: string
/**
* list of sides where the field is connected to other controls
*/
- connectionSides: {
- type: Array,
- default: () => [],
- validator: (v: string[]) =>
- v.every((item) => ["start", "end"].includes(item)),
- },
- /**
- * Medium size is for desktop header
- * Large size is for mobile header
- */
- size: {
- type: String as PropType<keyof typeof FIELD_SIZES>,
- required: true,
- validator: (v: string) => Object.keys(FIELD_SIZES).includes(v),
- },
- placeholder: {
- type: String,
- },
- type: {
- type: String as PropType<InputTypeHTMLAttribute>,
- default: "text",
- },
- },
- emits: {
- "update:modelValue": defineEvent<[string]>(),
- },
- expose: ["focusInput"],
- setup(props, { emit, attrs }) {
- const inputEl = ref<HTMLInputElement | null>(null)
-
- const focusInput = () => {
- inputEl.value?.focus()
- }
+ connectionSides?: Connection[]
- const updateModelValue = (event: Event) => {
- emit("update:modelValue", (event.target as HTMLInputElement).value)
- }
- const sizeClass = computed(() => FIELD_SIZES[props.size])
+ placeholder?: string
+ type?: InputTypeHTMLAttribute
+ }>(),
+ {
+ connectionSides: () => [],
+ type: "text",
+ }
+)
- const nonClassAttrs = computed(() => {
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
- const { class: _, ...rest } = attrs
- return rest
- })
+const emit = defineEmits<{ "update:modelValue": [string] }>()
+const attrs = useAttrs()
+const inputEl = ref<HTMLInputElement | null>(null)
- return {
- inputEl,
-
- focusInput,
+const focusInput = () => {
+ inputEl.value?.focus()
+}
- emit,
+const updateModelValue = (event: Event) => {
+ emit("update:modelValue", (event.target as HTMLInputElement).value)
+}
- sizeClass,
- nonClassAttrs,
- updateModelValue,
- }
- },
+const nonClassAttrs = computed(() => {
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
+ const { class: _, ...rest } = attrs
+ return rest
})
+defineExpose({ focusInput })
</script>
<template>
<div
- class="input-field group flex flex-row items-center overflow-hidden rounded-sm border p-0.5px focus-within:border-1.5 focus-within:border-focus focus-within:bg-surface focus-within:p-0 group-hover:bg-surface"
+ class="input-field group flex h-12 flex-row items-center overflow-hidden rounded-sm border p-0.5px focus-within:border-1.5 focus-within:border-focus focus-within:bg-surface focus-within:p-0 group-hover:bg-surface"
:class="[
{
// Padding is set to 1.5px to accommodate the border that will appear later.
@@ -123,7 +70,6 @@ export default defineComponent({
'rounded-e-none border-e-0 pe-1.5px focus-within:rounded-e-none focus-within:border-e-0 focus-within:pe-1.5px':
connectionSides.includes('end'),
},
- sizeClass,
$attrs.class,
]"
>
diff --git a/frontend/src/components/VPill.vue b/frontend/src/components/VPill.vue
index 64714b8f4..2e768d68b 100644
--- a/frontend/src/components/VPill.vue
+++ b/frontend/src/components/VPill.vue
@@ -1,10 +1,4 @@
-<script lang="ts">
-import { defineComponent } from "vue"
-
-export default defineComponent({
- name: "VPill",
-})
-</script>
+<script setup lang="ts"></script>
<template>
<div
diff --git a/frontend/src/components/VRadio/VRadio.vue b/frontend/src/components/VRadio/VRadio.vue
index 95481bab0..be4850ae1 100644
--- a/frontend/src/components/VRadio/VRadio.vue
+++ b/frontend/src/components/VRadio/VRadio.vue
@@ -1,59 +1,39 @@
-<script lang="ts">
-import { computed, defineComponent } from "vue"
-
-import { defineEvent } from "~/types/emits"
-
-import VSvg from "~/components/VSvg/VSvg.vue"
+<script setup lang="ts">
/**
* Renders a radio input field, useful for choosing one of a few options that
* can all be presented on the screen at once.
*/
-export default defineComponent({
- name: "VRadio",
- components: { VSvg },
- inheritAttrs: false,
- model: {
- prop: "modelValue",
- event: "change",
- },
- props: {
+import { computed } from "vue"
+
+import VSvg from "~/components/VSvg/VSvg.vue"
+
+defineOptions({ inheritAttrs: false })
+
+const emit = defineEmits<{ "update:modelValue": [string] }>()
+const props = withDefaults(
+ defineProps<{
/**
- * the input `id` property; This is used to connect the label to the radio.
+ * The input `id` property. This is used to connect the label to the radio.
*/
- id: {
- type: String,
- required: true,
- },
+ id: string
/**
* the value associated with this radio input
*/
- value: {
- type: String,
- required: true,
- },
+ value: string
/**
* the value of the `v-model` associated with the radio group
*/
- modelValue: {
- type: String,
- default: "",
- },
- },
- emits: {
- "update:modelValue": defineEvent<[string]>(),
- },
- setup(props, { emit }) {
- const isChecked = computed(() => props.value === props.modelValue)
- const handleInput = () => {
- emit("update:modelValue", props.value)
- }
+ modelValue?: string
+ }>(),
+ {
+ modelValue: "",
+ }
+)
- return {
- isChecked,
- handleInput,
- }
- },
-})
+const isChecked = computed(() => props.value === props.modelValue)
+const handleInput = () => {
+ emit("update:modelValue", props.value)
+}
</script>
<template>
diff --git a/frontend/src/components/VSelectField/VSelectField.vue b/frontend/src/components/VSelectField/VSelectField.vue
index 74ddb2430..dd89bcb7e 100644
--- a/frontend/src/components/VSelectField/VSelectField.vue
+++ b/frontend/src/components/VSelectField/VSelectField.vue
@@ -1,7 +1,6 @@
<script setup lang="ts">
import { computed, useAttrs, useSlots } from "vue"
-import { defineEvent } from "~/types/emits"
import type { ProperlyExtractPropTypes } from "~/types/prop-extraction"
import VIcon from "~/components/VIcon/VIcon.vue"
@@ -41,9 +40,7 @@ const props = withDefaults(
}
)
-const emit = defineEmits({
- "update:modelValue": defineEvent<[string]>(),
-})
+const emit = defineEmits<{ "update:modelValue": [string] }>()
const attrs = useAttrs()
const slots = useSlots()
diff --git a/frontend/src/components/VSkipToContentButton.vue b/frontend/src/components/VSkipToContentButton.vue
index a824cf4fa..2e8c82a1b 100644
--- a/frontend/src/components/VSkipToContentButton.vue
+++ b/frontend/src/components/VSkipToContentButton.vue
@@ -1,17 +1,7 @@
-<script lang="ts">
+<script setup lang="ts">
import { skipToContentTargetId } from "~/constants/window"
import VButton from "~/components/VButton.vue"
-
-export default {
- name: "VSkipToContentButton",
- components: { VButton },
- setup() {
- return {
- skipToContentTargetId,
- }
- },
-}
</script>
<template>
diff --git a/frontend/src/components/VSourcesTable.vue b/frontend/src/components/VSourcesTable.vue
index b12f65f58..72949df09 100644
--- a/frontend/src/components/VSourcesTable.vue
+++ b/frontend/src/components/VSourcesTable.vue
@@ -1,109 +1,87 @@
-<script lang="ts">
-import { defineComponent, type PropType, reactive, ref } from "vue"
+<script setup lang="ts">
+import { reactive, ref } from "vue"
import { useProviderStore } from "~/stores/provider"
+import { useSearchStore } from "~/stores/search"
import { useGetLocaleFormattedNumber } from "~/composables/use-get-locale-formatted-number"
import type { SupportedMediaType } from "~/constants/media"
import type { MediaProvider } from "~/types/media-provider"
-import { useSearchStore } from "~/stores/search"
-
import TableSortIcon from "~/components/TableSortIcon.vue"
import VLink from "~/components/VLink.vue"
-export default defineComponent({
- name: "VSourcesTable",
- components: {
- TableSortIcon,
- VLink,
- },
- props: {
- media: {
- type: String as PropType<SupportedMediaType>,
- required: true,
- },
- },
- setup(props) {
- const providerStore = useProviderStore()
- const searchStore = useSearchStore()
-
- const sorting = reactive({
- direction: "asc",
- field: "display_name" as keyof Omit<MediaProvider, "logo_url">,
- })
-
- // The providers in store are sorted by `source_name`, here we sort them by `display_name`.
- const providers = ref<MediaProvider[]>(
- providerStore.providers[props.media].sort(compareProviders)
- )
-
- function sortTable(field: keyof Omit<MediaProvider, "logo_url">) {
- let direction = field === "media_count" ? "desc" : "asc"
- if (field === sorting.field) {
- direction = sorting.direction === "asc" ? "desc" : "asc"
- }
-
- sorting.direction = direction
- sorting.field = field
-
- const sortedProviders = providers.value.sort(compareProviders)
-
- providers.value =
- direction === "asc" ? sortedProviders : sortedProviders.reverse()
- }
-
- function cleanSourceUrlForPresentation(url: string) {
- const stripProtocol = (s: string) => s.replace(/https?:\/\//, "")
- const stripLeadingWww = (s: string) =>
- s.startsWith("www.") ? s.replace("www.", "") : s
- const removeAfterSlash = (s: string) => s.split("/")[0]
-
- return removeAfterSlash(stripLeadingWww(stripProtocol(url)))
- }
-
- const getLocaleFormattedNumber = useGetLocaleFormattedNumber()
-
- function compareProviders(prov1: MediaProvider, prov2: MediaProvider) {
- let field1 = prov1[sorting.field]
- let field2 = prov2[sorting.field]
- if (sorting.field === "display_name") {
- field1 = prov1[sorting.field].toLowerCase()
- field2 = prov2[sorting.field].toLowerCase()
- }
-
- if (sorting.field === "source_url") {
- field1 = cleanSourceUrlForPresentation(field1 as string)
- field2 = cleanSourceUrlForPresentation(field2 as string)
- }
- if (field1 > field2) {
- return 1
- }
- if (field1 < field2) {
- return -1
- }
- return 0
- }
-
- const providerViewUrl = (provider: MediaProvider) => {
- return searchStore.getCollectionPath({
- type: props.media,
- collectionParams: {
- collection: "source",
- source: provider.source_name,
- },
- })
- }
- return {
- getLocaleFormattedNumber,
- providers,
- sorting,
- sortTable,
- cleanSourceUrlForPresentation,
- providerViewUrl,
- }
- },
+const props = defineProps<{ media: SupportedMediaType }>()
+
+const providerStore = useProviderStore()
+const searchStore = useSearchStore()
+
+const sorting = reactive({
+ direction: "asc",
+ field: "display_name" as keyof Omit<MediaProvider, "logo_url">,
})
+
+// The providers in store are sorted by `source_name`, here we sort them by `display_name`.
+const providers = ref<MediaProvider[]>(
+ providerStore.providers[props.media].sort(compareProviders)
+)
+
+function sortTable(field: keyof Omit<MediaProvider, "logo_url">) {
+ let direction = field === "media_count" ? "desc" : "asc"
+ if (field === sorting.field) {
+ direction = sorting.direction === "asc" ? "desc" : "asc"
+ }
+
+ sorting.direction = direction
+ sorting.field = field
+
+ const sortedProviders = providers.value.sort(compareProviders)
+
+ providers.value =
+ direction === "asc" ? sortedProviders : sortedProviders.reverse()
+}
+
+function cleanSourceUrlForPresentation(url: string) {
+ const stripProtocol = (s: string) => s.replace(/https?:\/\//, "")
+ const stripLeadingWww = (s: string) =>
+ s.startsWith("www.") ? s.replace("www.", "") : s
+ const removeAfterSlash = (s: string) => s.split("/")[0]
+
+ return removeAfterSlash(stripLeadingWww(stripProtocol(url)))
+}
+
+const getLocaleFormattedNumber = useGetLocaleFormattedNumber()
+
+function compareProviders(prov1: MediaProvider, prov2: MediaProvider) {
+ let field1 = prov1[sorting.field]
+ let field2 = prov2[sorting.field]
+ if (sorting.field === "display_name") {
+ field1 = prov1[sorting.field].toLowerCase()
+ field2 = prov2[sorting.field].toLowerCase()
+ }
+
+ if (sorting.field === "source_url") {
+ field1 = cleanSourceUrlForPresentation(field1 as string)
+ field2 = cleanSourceUrlForPresentation(field2 as string)
+ }
+ if (field1 > field2) {
+ return 1
+ }
+ if (field1 < field2) {
+ return -1
+ }
+ return 0
+}
+
+const providerViewUrl = (provider: MediaProvider) => {
+ return searchStore.getCollectionPath({
+ type: props.media,
+ collectionParams: {
+ collection: "source",
+ source: provider.source_name,
+ },
+ })
+}
</script>
<template>
diff --git a/frontend/src/components/VTooltip/VTooltip.vue b/frontend/src/components/VTooltip/VTooltip.vue
index 5de7c79c3..f9ef18bf9 100644
--- a/frontend/src/components/VTooltip/VTooltip.vue
+++ b/frontend/src/components/VTooltip/VTooltip.vue
@@ -1,14 +1,7 @@
-<script lang="ts">
-import {
- defineComponent,
- ref,
- PropType,
- watch,
- toRefs,
- onBeforeUnmount,
-} from "vue"
-
-import { zIndexValidator } from "~/constants/z-indices"
+<script setup lang="ts">
+import { ref, watch, toRefs, onBeforeUnmount } from "vue"
+
+import type { ZIndex } from "~/constants/z-indices"
import { useFloatingUi } from "~/composables/use-floating-ui"
import { hasFocusWithin } from "~/utils/reakit-utils/focus"
@@ -17,126 +10,100 @@ import VIconButton from "~/components/VIconButton/VIconButton.vue"
import type { Placement, Strategy } from "@floating-ui/dom"
-export default defineComponent({
- name: "VTooltip",
- components: { VIconButton },
- props: {
+const props = withDefaults(
+ defineProps<{
/**
* The placement of the tooltip relative to the trigger. Should be one of the options
* for `placement` passed to floating-ui.
*
* @see https://floating-ui.com/docs/tutorial#placements
- *
- * @default 'bottom'
*/
- placement: {
- type: String as PropType<Placement>,
- default: "bottom",
- },
+ placement?: Placement
/**
* The positioning strategy of the tooltip. If your reference element is in a fixed container
* use the fixed strategy; otherwise use the default, absolute strategy.
*
* @see https://floating-ui.com/docs/computeposition#strategy
- *
- * @default 'absolute'
*/
- strategy: {
- type: String as PropType<Strategy>,
- default: "absolute",
- },
+ strategy?: Strategy
/**
* The id of the element labelling the popover content.
* The owning element must have `aria-describedby` set to this value.
*/
- describedBy: {
- type: String,
- required: true,
- },
+ describedBy: string
/**
* the z-index to apply to the tooltip content
*/
- zIndex: {
- type: [Number, String],
- default: "popover", // named z-index
- validator: zIndexValidator,
- },
- },
- setup(props) {
- const visibleRef = ref(false)
- const triggerContainerRef = ref<HTMLElement | null>(null)
-
- const closeIfNeeded = () => {
- if (triggerRef.value && !hasFocusWithin(triggerRef.value)) {
- visibleRef.value = false
- }
- }
-
- const open = () => {
- visibleRef.value = true
- }
-
- const listeners = {
- mouseover: open,
- mouseout: closeIfNeeded,
- focus: open,
- blur: closeIfNeeded,
- }
-
- const setTrigger = (triggerElement: HTMLElement) => {
- triggerRef.value = triggerElement
- for (const [event, listener] of Object.entries(listeners)) {
- triggerElement.addEventListener(event, listener)
- }
- }
+ zIndex?: ZIndex
+ }>(),
+ {
+ placement: "bottom",
+ strategy: "absolute",
+ zIndex: "popover",
+ }
+)
+
+const visibleRef = ref(false)
+const triggerContainerRef = ref<HTMLElement | null>(null)
+
+const closeIfNeeded = () => {
+ if (triggerRef.value && !hasFocusWithin(triggerRef.value)) {
+ visibleRef.value = false
+ }
+}
+
+const open = () => {
+ visibleRef.value = true
+}
+
+const listeners = {
+ mouseover: open,
+ mouseout: closeIfNeeded,
+ focus: open,
+ blur: closeIfNeeded,
+}
+
+const setTrigger = (triggerElement: HTMLElement) => {
+ triggerRef.value = triggerElement
+ for (const [event, listener] of Object.entries(listeners)) {
+ triggerElement.addEventListener(event, listener)
+ }
+}
+
+const triggerRef = ref<HTMLElement | null>(null)
+watch(triggerContainerRef, (container) => {
+ if (container) {
+ setTrigger(container.firstElementChild as HTMLElement)
+ }
+})
- const triggerRef = ref<HTMLElement | null>(null)
- watch(triggerContainerRef, (container) => {
- if (container) {
- setTrigger(container.firstElementChild as HTMLElement)
- }
- })
-
- onBeforeUnmount(() => {
- if (triggerRef.value) {
- for (const [event, listener] of Object.entries(listeners)) {
- triggerRef.value.removeEventListener(event, listener)
- }
- }
- })
-
- const tooltipRef = ref<HTMLElement | null>(null)
- const propsRefs = toRefs(props)
-
- const { style } = useFloatingUi({
- floatingElRef: tooltipRef,
- floatingPropsRefs: {
- placement: propsRefs.placement,
- strategy: propsRefs.strategy,
- clippable: ref(false),
- visible: visibleRef,
- triggerElement: triggerRef,
- },
- })
-
- const handleEscape = () => {
- if (visibleRef.value) {
- visibleRef.value = false
- }
+onBeforeUnmount(() => {
+ if (triggerRef.value) {
+ for (const [event, listener] of Object.entries(listeners)) {
+ triggerRef.value.removeEventListener(event, listener)
}
+ }
+})
- return {
- visibleRef,
- triggerContainerRef,
- triggerRef,
- tooltipRef,
- style,
-
- open,
- handleEscape,
- }
+const tooltipRef = ref<HTMLElement | null>(null)
+const propsRefs = toRefs(props)
+
+const { style } = useFloatingUi({
+ floatingElRef: tooltipRef,
+ floatingPropsRefs: {
+ placement: propsRefs.placement,
+ strategy: propsRefs.strategy,
+ clippable: ref(false),
+ visible: visibleRef,
+ triggerElement: triggerRef,
},
})
+
+const handleEscape = () => {
+ if (visibleRef.value) {
+ visibleRef.value = false
+ }
+}
</script>
<template>
diff --git a/frontend/src/types/emits.ts b/frontend/src/types/emits.ts
deleted file mode 100644
index 88fb4e637..000000000
--- a/frontend/src/types/emits.ts
+++ /dev/null
@@ -1,47 +0,0 @@
-/**
- * Type utility function for defining `emits` values on components
- * without needing to provide an actual validator function.
- *
- * This works by casting `null` (which acts as a "skip" validation
- * signal) to a function type based on the array of parameters passed
- * in to the function.
- *
- * This is also a way around TS and ESLint rules about unused parameters.
- * The currently recommended way to document emits with Composition API,
- * is to use a function that always returns `true`, so validation is effectively
- * skipped as well. However, then TS and ESlint will complain about unused
- * parameters depending on your configuration. We'd like to keep those rules
- * and compiler flags on as they are useful for catching bugs, but needing to
- * disable them for every emits is cumbersome! Casting null, therefore, is a
- * clean and relatively straightforward solution, at least until we're able
- * to move to the `script setup` syntax and can use `defineEmit`, which solves
- * this problem.
- *
- * @example
- * ```typescript
- * export default defineComponent({
- * emits: {
- * click: defineEvent<[MouseEvent]>(), // (e: MouseEvent) => void
- * open: defineEvent(), // () => void
- * close: defineEvent<[{ reason: CloseReason }]>(), // (p: { reason: CloseReason }) => void
- * },
- * setup(_, { emit }) {
- * const state = ref('closed')
- * const handleClick = (e: MouseEvent) => {
- * // this will cause a TS error if you don't pass a `MouseEvent` payload
- * emit('click', e)
- * if (state.value === 'closed') {
- * emit('open', { reason: 'click' }) // this will cause an error because the `open` event takes no payload
- * } else {
- * emit('close') // this will cause an error because the `close` event requires a payload
- * }
- * }
- * }
- * })
- * ```
- */
-export function defineEvent<Payload extends unknown[] | null = null>() {
- return null as unknown as Payload extends [...infer A]
- ? (...args: [...A]) => void
- : () => void
-}
diff --git a/frontend/test/unit/specs/components/VHeader/SearchBar/search-bar.spec.js b/frontend/test/unit/specs/components/VHeader/SearchBar/search-bar.spec.js
index f3d14ce9c..7414d3c9d 100644
--- a/frontend/test/unit/specs/components/VHeader/SearchBar/search-bar.spec.js
+++ b/frontend/test/unit/specs/components/VHeader/SearchBar/search-bar.spec.js
@@ -7,52 +7,42 @@ import { render } from "~~/test/unit/test-utils/render"
import { useMatchHomeRoute } from "~/composables/use-match-routes"
import VSearchBar from "~/components/VHeader/VSearchBar/VSearchBar.vue"
-import { FIELD_SIZES } from "~/components/VInputField/VInputField.vue"
vi.mock("~/composables/use-match-routes", () => ({
useMatchHomeRoute: vi.fn(),
}))
-const sizes = Object.keys(FIELD_SIZES)
const defaultPlaceholder = "Enter search query"
describe("VSearchBar", () => {
let options
beforeEach(() => {
options = {
- props: { placeholder: defaultPlaceholder, size: "medium" },
+ props: { placeholder: defaultPlaceholder },
}
})
- it.each(sizes)(
- 'renders an input field with placeholder and type="search" (%s size)',
- async (size) => {
- useMatchHomeRoute.mockImplementation(() => false)
- options.props.size = size
- await render(VSearchBar, options)
+ it('renders an input field with placeholder and type="search"', async () => {
+ useMatchHomeRoute.mockImplementation(() => false)
+ await render(VSearchBar, options)
- const inputElement = screen.getByPlaceholderText(defaultPlaceholder)
+ const inputElement = screen.getByPlaceholderText(defaultPlaceholder)
- expect(inputElement.tagName).toBe("INPUT")
- expect(inputElement).toHaveAttribute("type", "search")
- expect(inputElement).toHaveAttribute("placeholder", defaultPlaceholder)
- }
- )
+ expect(inputElement.tagName).toBe("INPUT")
+ expect(inputElement).toHaveAttribute("type", "search")
+ expect(inputElement).toHaveAttribute("placeholder", defaultPlaceholder)
+ })
- it.each(sizes)(
- 'renders a button with type="submit", ARIA label and SR text (%s size)',
- async (size) => {
- useMatchHomeRoute.mockImplementation(() => false)
- options.props.size = size
- await render(VSearchBar, options)
+ it('renders a button with type="submit", ARIA label and SR text', async () => {
+ useMatchHomeRoute.mockImplementation(() => false)
+ await render(VSearchBar, options)
- const btnElement = screen.getByRole("button", { name: /search/i })
+ const btnElement = screen.getByRole("button", { name: /search/i })
- expect(btnElement.tagName).toBe("BUTTON")
- expect(btnElement).toHaveAttribute("type", "submit")
- expect(btnElement).toHaveAttribute("aria-label", "Search")
- }
- )
+ expect(btnElement.tagName).toBe("BUTTON")
+ expect(btnElement).toHaveAttribute("type", "submit")
+ expect(btnElement).toHaveAttribute("aria-label", "Search")
+ })
describe("placeholder", () => {
it("should default to hero.search.placeholder", async () => {