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:
+1
-1
File diff suppressed because one or more lines are too long
Binary file not shown.
+1
-1
File diff suppressed because one or more lines are too long
Binary file not shown.
+2
-2
File diff suppressed because one or more lines are too long
Binary file not shown.
+1
-1
File diff suppressed because one or more lines are too long
Binary file not shown.
+2
File diff suppressed because one or more lines are too long
BIN
Binary file not shown.
+1
File diff suppressed because one or more lines are too long
Vendored
BIN
Binary file not shown.
-2
File diff suppressed because one or more lines are too long
BIN
Binary file not shown.
-1
File diff suppressed because one or more lines are too long
Vendored
BIN
Binary file not shown.
@@ -515,6 +515,9 @@ header[role="banner"]{
|
||||
#block-pagetitle{}
|
||||
#block-materiosapisearchblock{
|
||||
align-self: flex-end;
|
||||
// Long enough for a phrase and for the placeholder (F4).
|
||||
width: 30em;
|
||||
max-width: 50%;
|
||||
}
|
||||
@include col-mediaquery-max(3){
|
||||
flex-direction: column;
|
||||
@@ -526,6 +529,7 @@ header[role="banner"]{
|
||||
#block-materiosapisearchblock{
|
||||
box-sizing: border-box;
|
||||
width:100%;
|
||||
max-width: none;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -614,7 +618,9 @@ header[role="banner"]{
|
||||
|
||||
#materio-sapi-search-form{
|
||||
display: grid;
|
||||
grid-template-columns: auto 25px;
|
||||
// Field, search button, help button (F4).
|
||||
grid-template-columns: auto 25px 22px;
|
||||
position: relative;
|
||||
grid-template-rows: auto auto;
|
||||
row-gap: 0.2em;
|
||||
justify-items: stretch;
|
||||
@@ -655,6 +661,58 @@ header[role="banner"]{
|
||||
background-color: transparent
|
||||
}
|
||||
|
||||
// Help "?" and its tooltip (F4).
|
||||
.search-help-button{
|
||||
grid-row: 1 / 1;
|
||||
grid-column: 3 / 3;
|
||||
justify-self: end;
|
||||
align-self: center;
|
||||
width: 18px; height: 18px;
|
||||
padding: 0;
|
||||
border: 1px solid #999;
|
||||
border-radius: 50%;
|
||||
background: transparent;
|
||||
color: #666;
|
||||
font-size: 12px;
|
||||
line-height: 16px;
|
||||
text-align: center;
|
||||
cursor: pointer;
|
||||
&[aria-expanded="true"], &:hover{
|
||||
background-color: #333;
|
||||
border-color: #333;
|
||||
color: #fff;
|
||||
}
|
||||
}
|
||||
.search-help{
|
||||
position: absolute;
|
||||
z-index: 101;
|
||||
top: 100%;
|
||||
right: 0;
|
||||
width: 22em;
|
||||
max-width: 90vw;
|
||||
box-sizing: border-box;
|
||||
margin-top: 0.4em;
|
||||
padding: 0.6em 0.8em;
|
||||
border-radius: 5px;
|
||||
background-color: rgba(0, 0, 0, 0.85);
|
||||
color: #fff;
|
||||
font-size: 0.85em;
|
||||
line-height: 1.4;
|
||||
p{ margin: 0 0 0.4em; }
|
||||
ul{ margin: 0; padding: 0; }
|
||||
li{ list-style: none; }
|
||||
li button{
|
||||
padding: 0.15em 0;
|
||||
border: 0;
|
||||
background: none;
|
||||
color: #fff;
|
||||
font: inherit;
|
||||
text-align: left;
|
||||
text-decoration: underline;
|
||||
cursor: pointer;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@include col-mediaquery-max(3){
|
||||
body:not(.path-base) &{
|
||||
@@ -1427,7 +1485,6 @@ article.node--type-frontpage{
|
||||
display:none;
|
||||
}
|
||||
}
|
||||
|
||||
&>ul{
|
||||
// outline: 1px green solid;
|
||||
margin:0; padding:0;
|
||||
|
||||
@@ -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 () {
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
// Texts of the search field and of the results page (F4, F7), in French and
|
||||
// English. Kept in the repository: the Vue translation files
|
||||
// (sites/default/files/lang/*.json) are generated outside of it. The result
|
||||
// messages come from the server (materio_sapi SearchMessage).
|
||||
|
||||
const TEXTS = {
|
||||
fr: {
|
||||
placeholder: 'Décrivez le matériau recherché',
|
||||
loading: 'Chargement…',
|
||||
end: 'Fin des résultats',
|
||||
helpLabel: 'Aide à la recherche',
|
||||
help: 'Décrivez en quelques mots le matériau, son usage ou l’effet recherché.',
|
||||
examplesIntro: 'Par exemple :',
|
||||
// Checked on 23/11: the first results answer the phrase.
|
||||
examples: [
|
||||
'isolant à base de champignon',
|
||||
'textile qui change de couleur',
|
||||
'verre qui devient opaque',
|
||||
'alternative au plastique pour emballage'
|
||||
],
|
||||
suggestionsLabel: 'Suggestions',
|
||||
suggestionsOne: '1 suggestion, flèches haut et bas pour choisir',
|
||||
suggestionsMany: n => `${n} suggestions, flèches haut et bas pour choisir`
|
||||
},
|
||||
en: {
|
||||
placeholder: 'Describe the material you are looking for',
|
||||
loading: 'Loading…',
|
||||
end: 'End of results',
|
||||
helpLabel: 'Search help',
|
||||
help: 'Describe in a few words the material, its use or the effect you are looking for.',
|
||||
examplesIntro: 'For example:',
|
||||
examples: [
|
||||
'mushroom-based insulation',
|
||||
'colour-changing textile',
|
||||
'glass that turns opaque',
|
||||
'plastic alternative for packaging'
|
||||
],
|
||||
suggestionsLabel: 'Suggestions',
|
||||
suggestionsOne: '1 suggestion, use up and down arrows to choose',
|
||||
suggestionsMany: n => `${n} suggestions, use up and down arrows to choose`
|
||||
}
|
||||
}
|
||||
|
||||
// Texts of the page language, English by default.
|
||||
export function searchTexts () {
|
||||
const lang = (window.drupalDecoupled && window.drupalDecoupled.lang_code) || 'en'
|
||||
return TEXTS[lang] || TEXTS.en
|
||||
}
|
||||
@@ -135,7 +135,9 @@ export default {
|
||||
commit('resetInfos')
|
||||
// Invalidate any in-flight response from a previous search.
|
||||
commit('incrementSearchId')
|
||||
if (state.keys || state.terms.length) {
|
||||
// keys is an array, always truthy: test its length, otherwise the
|
||||
// title of the page was empty without a search (F4).
|
||||
if (state.keys.length) {
|
||||
this.commit('Common/setPagetitle', state.keys.join(', '))
|
||||
} else {
|
||||
this.commit('Common/setPagetitle', 'Base')
|
||||
|
||||
Reference in New Issue
Block a user