diff --git a/datagouv-components/src/components/Search/GlobalSearch.vue b/datagouv-components/src/components/Search/GlobalSearch.vue index eb7ec1904..c36a89f02 100644 --- a/datagouv-components/src/components/Search/GlobalSearch.vue +++ b/datagouv-components/src/components/Search/GlobalSearch.vue @@ -13,6 +13,7 @@
@@ -401,11 +402,17 @@ const props = withDefaults(defineProps<{ config?: GlobalSearchConfig placeholder?: string | null hideSearchInput?: boolean + autoFocus?: boolean }>(), { config: getDefaultGlobalSearchConfig, hideSearchInput: false, + autoFocus: true, }) +const emit = defineEmits<{ + resultsCount: [total: number] +}>() + // defineModel's default is static and can't depend on props, so we cast and initialize manually const currentType = defineModel('type') as Ref if (!currentType.value) currentType.value = configKey(props.config[0] ?? { class: 'datasets' }) @@ -717,6 +724,10 @@ function resetFilters() { const searchResults = computed(() => resultsMap[currentType.value]?.data.value) const searchResultsStatus = computed(() => resultsMap[currentType.value]?.status.value) +watch(searchResults, (results) => { + if (results) emit('resultsCount', results.total) +}, { immediate: true }) + // RSS feed URL for datasets const rssUrl = computed(() => { if (currentTypeConfig.value?.class !== 'datasets') return null diff --git a/datagouv-components/src/components/Search/SearchInput.vue b/datagouv-components/src/components/Search/SearchInput.vue index 3e5a902a2..de5a6e539 100644 --- a/datagouv-components/src/components/Search/SearchInput.vue +++ b/datagouv-components/src/components/Search/SearchInput.vue @@ -37,7 +37,7 @@ import BrandedButton from '../BrandedButton.vue' const q = defineModel({ required: true }) -withDefaults(defineProps<{ +const props = withDefaults(defineProps<{ placeholder?: string | null autoFocus?: boolean }>(), { @@ -57,6 +57,7 @@ const focus = () => { } onMounted(async () => { + if (!props.autoFocus) return await nextTick() focus() })