File tree Expand file tree Collapse file tree 2 files changed +36
-5
lines changed Expand file tree Collapse file tree 2 files changed +36
-5
lines changed Original file line number Diff line number Diff line change @@ -231,11 +231,14 @@ export default {
231
231
if ( this . pageStart >= this . itemsLength ) {
232
232
this . resetPagination ( )
233
233
}
234
- const newItemKeys = new Set ( this . items . map ( item => getObjectValueByPath ( item , this . itemKey ) ) )
235
- const selection = this . value . filter ( item => newItemKeys . has ( getObjectValueByPath ( item , this . itemKey ) ) )
236
234
237
- if ( selection . length !== this . value . length ) {
238
- this . $emit ( 'input' , selection )
235
+ if ( this . totalItems === null ) {
236
+ const newItemKeys = new Set ( this . items . map ( item => getObjectValueByPath ( item , this . itemKey ) ) )
237
+ const selection = this . value . filter ( item => newItemKeys . has ( getObjectValueByPath ( item , this . itemKey ) ) )
238
+
239
+ if ( selection . length !== this . value . length ) {
240
+ this . $emit ( 'input' , selection )
241
+ }
239
242
}
240
243
} ,
241
244
search ( ) {
Original file line number Diff line number Diff line change @@ -123,4 +123,32 @@ test('data-iterable.js', ({ mount }) => {
123
123
expect ( callCount ) . toBe ( 2 )
124
124
expect ( selectionChanged ) . toBeCalledWith ( [ ] )
125
125
} )
126
- } )
126
+
127
+ it ( 'should not update selection if totalItems is set' , async ( ) => {
128
+ const items = [ { id : 'foo' } , { id : 'bar' } ]
129
+ let value = [ ]
130
+
131
+ const wrapper = dataIterableCmp ( value , items )
132
+
133
+ let callCount = 0
134
+ const selectionChanged = jest . fn ( )
135
+ // Emulate v-model behaviour
136
+ wrapper . vm . $on ( 'input' , function ( newValue ) {
137
+ callCount += 1
138
+ value = newValue
139
+ selectionChanged . apply ( this , arguments )
140
+ } )
141
+
142
+ wrapper . find ( '.select-me' ) [ 0 ] . trigger ( 'click' )
143
+
144
+ expect ( callCount ) . toBe ( 1 )
145
+ expect ( selectionChanged ) . toBeCalledWith ( [ items [ 0 ] ] )
146
+
147
+ // because totalItems is set,
148
+ // the selection is not going to be updated
149
+ wrapper . setProps ( { value, items : [ items [ 1 ] ] , totalItems : 42 } )
150
+
151
+ expect ( callCount ) . toBe ( 1 )
152
+ expect ( selectionChanged ) . toBeCalledWith ( [ items [ 0 ] ] )
153
+ } )
154
+ } )
You can’t perform that action at this time.
0 commit comments