File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed
src/components/RefinementList Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -130,8 +130,10 @@ class RefinementList extends React.Component {
130130 const limit = this . state . isShowMoreOpen ? this . props . limitMax : this . props . limitMin ;
131131 let displayedFacetValues = this . props . facetValues . slice ( 0 , limit ) ;
132132 const displayShowMore = this . props . showMore === true &&
133+ // "Show more"
133134 this . props . facetValues . length > displayedFacetValues . length ||
134- this . state . isShowMoreOpen === true ;
135+ // "Show less", but hide it if the result set changed
136+ this . state . isShowMoreOpen && displayedFacetValues . length > this . props . limitMin ;
135137
136138 const showMoreBtn = displayShowMore ?
137139 < Template
Original file line number Diff line number Diff line change @@ -240,6 +240,28 @@ describe('RefinementList', () => {
240240 expect ( actual . length ) . toEqual ( 0 ) ;
241241 } ) ;
242242
243+ it ( 'no showMore when: state = open -> values change -> values <= limitMin ' , ( ) => {
244+ // Given
245+ let props = {
246+ facetValues : [
247+ { name : 'foo' } ,
248+ { name : 'bar' } ,
249+ { name : 'baz' }
250+ ] ,
251+ showMore : true ,
252+ limitMin : 2 ,
253+ limitMax : 5
254+ } ;
255+
256+ // When
257+ let root = shallowRender ( props ) ;
258+ root . instance ( ) . handleClickShowMore ( ) ;
259+ root . setProps ( { facetValues : props . facetValues . slice ( 2 ) } ) ;
260+
261+ // Then
262+ expect ( root . find ( { templateKey : 'show-more-active' } ) . length ) . toEqual ( 0 ) ;
263+ } ) ;
264+
243265 it ( 'does not add a showMore link when the facet values length is equal to the minLimit' , ( ) => {
244266 // Given
245267 let props = {
You can’t perform that action at this time.
0 commit comments