Skip to content
This repository was archived by the owner on Dec 30, 2022. It is now read-only.

Commit d293b83

Browse files
authored
fix(RefinementList): allow overriding of searchable placeholder (#576)
* fix(RefinementList): allow overriding of searchable placeholder Also noticed that the test was broken for `searchable`, so fixed that one too. New prop: placeholder on `RefinementList` fixes #572 * Update RefinementList.md * chore: searchablePlaceholder
1 parent 20780bc commit d293b83

File tree

4 files changed

+107
-8
lines changed

4 files changed

+107
-8
lines changed

docs/src/components/RefinementList.md

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Name | Type | Default | Description | Required
2525
---|---|---|---|---
2626
attribute | string | | The attribute to refine on click | yes
2727
searchable | boolean | `false` | You can also search within the options of this | no
28+
searchablePlaceholder | string | "Search here …" | If searchable is `true`, this will be the placeholder for that search box | no
2829
operator | "or" / "and" | "or" | How to apply refinements | no
2930
limit | number | 10 | Number of items to show | no
3031
showMoreLimit | number | 20 | Number of items to show when the user clicked on “show more items” | no

src/components/RefinementList.vue

+9-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@
2222
:class="suit('searchBox')"
2323
v-if="searchable"
2424
>
25-
<search-input v-model="searchForFacetValues" />
25+
<search-input
26+
v-model="searchForFacetValues"
27+
:placeholder="searchablePlaceholder"
28+
/>
2629
</div>
2730
<slot
2831
name="noResults"
@@ -121,6 +124,11 @@ export default {
121124
type: Boolean,
122125
default: false,
123126
},
127+
searchablePlaceholder: {
128+
default: 'Search here…',
129+
type: String,
130+
required: false,
131+
},
124132
operator: {
125133
default: 'or',
126134
validator(value) {

src/components/__tests__/RefinementList.js

+22-1
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,35 @@ it('renders correctly (empty)', () => {
7272
it("renders correctly when it's searchable", () => {
7373
__setState({
7474
...defaultState,
75-
searchable: true,
7675
});
7776
const wrapper = mount(RefinementList, {
7877
propsData: {
78+
searchable: true,
7979
attribute: 'something',
8080
},
8181
});
8282
expect(wrapper.html()).toMatchSnapshot();
83+
84+
expect(wrapper.find('.ais-SearchBox-input').exists()).toBe(true);
85+
});
86+
87+
it("allows override of placeholder when it's searchable", () => {
88+
__setState({
89+
...defaultState,
90+
searchable: true,
91+
});
92+
const placeholder = 'search in dogs';
93+
const wrapper = mount(RefinementList, {
94+
propsData: {
95+
searchable: true,
96+
attribute: 'something',
97+
searchablePlaceholder: placeholder,
98+
},
99+
});
100+
101+
expect(wrapper.find('.ais-SearchBox-input').attributes('placeholder')).toBe(
102+
placeholder
103+
);
83104
});
84105

85106
it("disables show more if can't refine", () => {

src/components/__tests__/__snapshots__/RefinementList.js.snap

+75-6
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,60 @@ exports[`renders correctly 1`] = `
105105
exports[`renders correctly when it's searchable 1`] = `
106106
107107
<div class="ais-RefinementList ais-RefinementList--noRefinement">
108+
<div class="ais-RefinementList-searchBox">
109+
<form action
110+
role="search"
111+
novalidate="novalidate"
112+
class="ais-SearchBox-form"
113+
>
114+
<input type="search"
115+
autocorrect="off"
116+
autocapitalize="off"
117+
autocomplete="off"
118+
spellcheck="false"
119+
required="required"
120+
maxlength="512"
121+
aria-label="Search"
122+
placeholder="Search here…"
123+
class="ais-SearchBox-input"
124+
>
125+
<button type="submit"
126+
title="Search"
127+
class="ais-SearchBox-submit"
128+
>
129+
<svg role="img"
130+
xmlns="http://www.w3.org/2000/svg"
131+
width="10"
132+
height="10"
133+
viewbox="0 0 40 40"
134+
class="ais-SearchBox-submitIcon"
135+
>
136+
<path d="M26.804 29.01c-2.832 2.34-6.465 3.746-10.426 3.746C7.333 32.756 0 25.424 0 16.378 0 7.333 7.333 0 16.378 0c9.046 0 16.378 7.333 16.378 16.378 0 3.96-1.406 7.594-3.746 10.426l10.534 10.534c.607.607.61 1.59-.004 2.202-.61.61-1.597.61-2.202.004L26.804 29.01zm-10.426.627c7.323 0 13.26-5.936 13.26-13.26 0-7.32-5.937-13.257-13.26-13.257C9.056 3.12 3.12 9.056 3.12 16.378c0 7.323 5.936 13.26 13.258 13.26z"
137+
fillrule="evenodd"
138+
>
139+
</path>
140+
</svg>
141+
</button>
142+
<button type="reset"
143+
title="Clear"
144+
hidden="hidden"
145+
class="ais-SearchBox-reset"
146+
>
147+
<svg role="img"
148+
xmlns="http://www.w3.org/2000/svg"
149+
width="1em"
150+
height="1em"
151+
viewbox="0 0 20 20"
152+
class="ais-SearchBox-resetIcon"
153+
>
154+
<path d="M8.114 10L.944 2.83 0 1.885 1.886 0l.943.943L10 8.113l7.17-7.17.944-.943L20 1.886l-.943.943-7.17 7.17 7.17 7.17.943.944L18.114 20l-.943-.943-7.17-7.17-7.17 7.17-.944.943L0 18.114l.943-.943L8.113 10z"
155+
fillrule="evenodd"
156+
>
157+
</path>
158+
</svg>
159+
</button>
160+
</form>
161+
</div>
108162
<ul class="ais-RefinementList-list">
109163
<li class="ais-RefinementList-item">
110164
<label class="ais-RefinementList-label">
@@ -113,7 +167,12 @@ exports[`renders correctly when it's searchable 1`] = `
113167
value="yo"
114168
>
115169
<span class="ais-RefinementList-labelText">
116-
yo
170+
<span class="ais-Highlight">
171+
y
172+
<mark class="ais-Highlight-highlighted">
173+
o
174+
</mark>
175+
</span>
117176
</span>
118177
<span class="ais-RefinementList-count">
119178
20
@@ -127,7 +186,9 @@ exports[`renders correctly when it's searchable 1`] = `
127186
value="how"
128187
>
129188
<span class="ais-RefinementList-labelText">
130-
how
189+
<span class="ais-Highlight">
190+
how
191+
</span>
131192
</span>
132193
<span class="ais-RefinementList-count">
133194
10
@@ -141,7 +202,9 @@ exports[`renders correctly when it's searchable 1`] = `
141202
value="are"
142203
>
143204
<span class="ais-RefinementList-labelText">
144-
are
205+
<span class="ais-Highlight">
206+
are
207+
</span>
145208
</span>
146209
<span class="ais-RefinementList-count">
147210
8
@@ -155,7 +218,9 @@ exports[`renders correctly when it's searchable 1`] = `
155218
value="you"
156219
>
157220
<span class="ais-RefinementList-labelText">
158-
you
221+
<span class="ais-Highlight">
222+
you
223+
</span>
159224
</span>
160225
<span class="ais-RefinementList-count">
161226
9
@@ -169,7 +234,9 @@ exports[`renders correctly when it's searchable 1`] = `
169234
value="doing"
170235
>
171236
<span class="ais-RefinementList-labelText">
172-
doing
237+
<span class="ais-Highlight">
238+
doing
239+
</span>
173240
</span>
174241
<span class="ais-RefinementList-count">
175242
100
@@ -183,7 +250,9 @@ exports[`renders correctly when it's searchable 1`] = `
183250
value="?"
184251
>
185252
<span class="ais-RefinementList-labelText">
186-
?
253+
<span class="ais-Highlight">
254+
?
255+
</span>
187256
</span>
188257
<span class="ais-RefinementList-count">
189258
0

0 commit comments

Comments
 (0)