Search texts and states, help tooltip, wider field (F4)

materio_sapi: result messages with real plurals; without any exact
match the results are called close (the neighbour search always finds
some). Former help sentence of the base page kept, French corrected.
Messages in SearchMessage, unit tested; French added by update 11002.

materiotheme: placeholder "Describe the material you are looking for",
wider search field, "?" button with a help tooltip and clickable
examples, "Loading…", "End of results"; texts in vuejs/i18n/search.js.
Page title "Base" restored without a search (keys is an array, test its
length).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ShDspHaZGwHoRZCsPBJzsM
This commit is contained in:
2026-11-23 16:44:28 +01:00
co-authored by Claude Opus 5.5
parent f7eb6518e7
commit 1e882d5bda
25 changed files with 372 additions and 48 deletions
@@ -8,6 +8,7 @@
class="materio-sapi-search-form"
role="search"
@submit.prevent="submit"
@keydown.esc="closeHelp"
>
<div class="form-item form-item-search">
<input
@@ -23,7 +24,7 @@
:aria-controls="listId"
:aria-activedescendant="active >= 0 ? optionId(active) : null"
:maxlength="maxLength"
:placeholder="$t('default.Search')"
:placeholder="text.placeholder"
:aria-label="$t('default.Search')"
enterkeyhint="search"
autocomplete="off"
@@ -38,7 +39,7 @@
:id="listId"
class="search-suggestions"
role="listbox"
:aria-label="text.list"
:aria-label="text.suggestionsLabel"
>
<li
v-for="(item, i) in suggestions"
@@ -60,6 +61,34 @@
:value="$t('default.Search')"
:title="$t('default.Search')"
>
<!-- Help: a "?" button opens a tooltip with examples (F4). Disclosure
pattern: aria-expanded on the button, Escape or a click outside
closes it. -->
<button
ref="helpButton"
type="button"
class="search-help-button"
:aria-expanded="helpOpen ? 'true' : 'false'"
aria-controls="search-help"
:title="text.helpLabel"
@click="helpOpen = !helpOpen"
><span aria-hidden="true">?</span><span class="visually-hidden">{{ text.helpLabel }}</span></button>
<div
v-show="helpOpen"
id="search-help"
ref="help"
class="search-help"
role="region"
:aria-label="text.helpLabel"
>
<p>{{ text.help }}</p>
<p>{{ text.examplesIntro }}</p>
<ul>
<li v-for="example in text.examples" :key="example">
<button type="button" @click="searchExample(example)">{{ example }}</button>
</li>
</ul>
</div>
</form>
</template>
@@ -68,23 +97,7 @@ import router from 'vuejs/route'
import { mapState } from 'vuex'
import MA from 'vuejs/api/ma-axios'
import qs from 'querystring-es3'
// Texts of the suggestion list, for screen readers. Kept here: the Vue
// translation files are generated outside the repository.
const TEXTS = {
fr: {
list: 'Suggestions',
none: '',
one: '1 suggestion, flèches haut et bas pour choisir',
many: n => `${n} suggestions, flèches haut et bas pour choisir`
},
en: {
list: 'Suggestions',
none: '',
one: '1 suggestion, use up and down arrows to choose',
many: n => `${n} suggestions, use up and down arrows to choose`
}
}
import { searchTexts } from 'vuejs/i18n/search'
export default {
router,
@@ -99,6 +112,7 @@ export default {
announce: '',
listId: 'search-suggestions',
timer: null,
helpOpen: false,
// Answers of older requests are dropped.
requestId: 0
}
@@ -107,10 +121,7 @@ export default {
...mapState({
keys: state => state.Search.keys
}),
text () {
const lang = (window.drupalDecoupled && drupalDecoupled.lang_code) || 'en'
return TEXTS[lang] || TEXTS.en
}
text: searchTexts
},
methods: {
phraseFromKeys (keys) {
@@ -145,7 +156,7 @@ export default {
this.active = -1
this.open = this.suggestions.length > 0
const n = this.suggestions.length
this.announce = n === 0 ? this.text.none : (n === 1 ? this.text.one : this.text.many(n))
this.announce = n === 0 ? '' : (n === 1 ? this.text.suggestionsOne : this.text.suggestionsMany(n))
})
.catch(error => {
console.warn('Issue with search suggestions', error)
@@ -204,6 +215,24 @@ export default {
// Only the phrase, no terms.
this.go(phrase ? { keys: phrase } : {})
},
// An example of the help runs as a typed phrase.
searchExample (example) {
this.helpOpen = false
this.typed = example
this.submit()
},
closeHelp () {
if (this.helpOpen) {
this.helpOpen = false
this.$refs.helpButton.focus()
}
},
// A click outside the tooltip and its button closes it.
onDocumentClick (e) {
if (this.helpOpen && !this.$refs.help.contains(e.target) && !this.$refs.helpButton.contains(e.target)) {
this.helpOpen = false
}
},
go (query) {
// Hide the keyboard on mobile devices.
this.$refs.input.blur()
@@ -221,8 +250,12 @@ export default {
// Direct page load: the store already holds the keys of the URL.
this.typed = this.phraseFromKeys(this.keys)
},
mounted () {
document.addEventListener('click', this.onDocumentClick)
},
beforeDestroy () {
clearTimeout(this.timer)
document.removeEventListener('click', this.onDocumentClick)
}
}
</script>
@@ -1,7 +1,7 @@
<template>
<div id="Base">
<div class="loading" v-if="!searchinfos">
<span>{{ $t('default.Loading…') }}</span>
<span>{{ text.loading }}</span>
</div>
<div class="cards-list" v-else>
<!-- aria-live: screen readers announce the result message of each search (F1). -->
@@ -9,7 +9,7 @@
{{ searchinfos }}
</aside>
<div class="loading" v-if="!items.length & !noresults">
<span>{{ $t('default.Loading…') }}</span>
<span>{{ text.loading }}</span>
</div>
<ul v-else>
<li v-for="item in displayedItems" v-bind:key="item.id">
@@ -22,7 +22,7 @@
:identifier="searchId"
@infinite="nextPage"
>
<div slot="no-more">No more results</div>
<div slot="no-more">{{ text.end }}</div>
</infinite-loading>
</div>
</div>
@@ -35,6 +35,7 @@ import Card from 'vuejs/components/Content/Card'
import CardThematique from 'vuejs/components/Content/CardThematique'
import { mapState, mapActions } from 'vuex'
import { searchTexts } from 'vuejs/i18n/search'
export default {
name: "Base",
@@ -54,6 +55,7 @@ export default {
searchId: state => state.Search.searchId,
keys: state => state.Search.keys
}),
text: searchTexts,
// items is a sparse array (pages placed by offset); drop the holes left by
// pages that returned fewer results than the limit before rendering.
displayedItems () {