File tree Expand file tree Collapse file tree 4 files changed +85
-7
lines changed
packages/devextreme-vue/src/core Expand file tree Collapse file tree 4 files changed +85
-7
lines changed Original file line number Diff line number Diff line change
1
+ <template >
2
+ <example-block title =" v-model" >
3
+ DX with value:
4
+ <br >
5
+ <dx-check-box v-model =" dxCheckBoxValue" />
6
+ <br >
7
+ <div >checkBoxValue: {{ dxCheckBoxValue ? '🟢' : '🔴' }}</div >
8
+ <br >
9
+ -------------
10
+ <br >
11
+ Native checkbox with modelValue:
12
+ <br >
13
+ <input type =" checkbox" v-model =" checkBoxValue2" />
14
+ <br >
15
+ <div >checkBoxValue: {{ checkBoxValue2 ? '🟢' : '🔴' }}</div >
16
+ <br >
17
+ </example-block >
18
+ </template >
19
+
20
+ <script >
21
+ import { ref , watch } from " vue" ;
22
+ import ExampleBlock from " ./example-block" ;
23
+ import { DxCheckBox } from " devextreme-vue/check-box" ;
24
+
25
+ const checkBoxValue2 = ref (false );
26
+
27
+ watch (checkBoxValue2, (newValue ) => console .log (" checkBoxValue2 changed:" , newValue));
28
+
29
+ export default {
30
+ components: {
31
+ ExampleBlock,
32
+ DxCheckBox,
33
+ },
34
+ data () {
35
+ return {
36
+ dxCheckBoxValue: false ,
37
+ checkBoxValue2,
38
+ };
39
+ },
40
+ };
41
+ </script >
Original file line number Diff line number Diff line change 28
28
<text-box-example />
29
29
<br />
30
30
<validator-example />
31
+ <br />
32
+ <check-box-example />
33
+ <br />
31
34
</template >
32
35
33
36
<script >
@@ -46,7 +49,8 @@ import ScrollViewExample from "./scroll-view-example";
46
49
import TabPanelExample from " ./tab-panel-example" ;
47
50
import TextBoxExample from " ./text-box-example" ;
48
51
import ValidatorExample from " ./validation-example" ;
49
-
52
+ import CheckBoxExample from " ./check-box-example" ;
53
+
50
54
export default {
51
55
components: {
52
56
AccessingInstanceExample,
@@ -63,7 +67,8 @@ export default {
63
67
ScrollViewExample,
64
68
TabPanelExample,
65
69
TextBoxExample,
66
- ValidatorExample
70
+ ValidatorExample,
71
+ CheckBoxExample
67
72
}
68
73
};
69
74
</script >
Original file line number Diff line number Diff line change 1
1
import { ComponentPublicInstance , reactive } from 'vue' ;
2
+ import { VMODEL_NAME } from '../vue-helper' ;
2
3
import Configuration , {
3
4
bindOptionWatchers ,
4
5
ExpectedChild ,
@@ -644,4 +645,35 @@ describe('onOptionChanged', () => {
644
645
645
646
expect ( emitStubRoot ) . toHaveBeenCalledTimes ( 0 ) ;
646
647
} ) ;
648
+
649
+ it ( 'should use v-model event name and mutate innerChanges with VMODEL_NAME when option is "value" and v-model is active' , ( ) => {
650
+ const innerChanges = { } ;
651
+ const config = new Configuration ( jest . fn ( ) , null , { } ) ;
652
+ const emitStub = jest . fn ( ) ;
653
+ const component = {
654
+ $emit : emitStub ,
655
+ $props : { value : false , [ VMODEL_NAME ] : false } ,
656
+ $options : {
657
+ props : { value : false , [ VMODEL_NAME ] : false } ,
658
+ model : true ,
659
+ } ,
660
+ $ : {
661
+ vnode : {
662
+ props : { value : false , [ VMODEL_NAME ] : false } ,
663
+ } ,
664
+ } ,
665
+ } ;
666
+ setEmitOptionChangedFunc ( config , component as unknown as ComponentPublicInstance , innerChanges ) ;
667
+
668
+ config . onOptionChanged ( {
669
+ fullName : 'value' ,
670
+ value : true ,
671
+ previousValue : false ,
672
+ component : null ,
673
+ } ) ;
674
+
675
+ expect ( emitStub ) . toHaveBeenCalledTimes ( 1 ) ;
676
+ expect ( emitStub ) . toHaveBeenCalledWith ( `update:${ VMODEL_NAME } ` , true ) ;
677
+ expect ( innerChanges [ VMODEL_NAME ] ) . toBe ( true ) ;
678
+ } ) ;
647
679
} ) ;
Original file line number Diff line number Diff line change @@ -306,12 +306,12 @@ function setEmitOptionChangedFunc(
306
306
config . emitOptionChanged = ( name : string , value : string ) => {
307
307
const props = vueInstance . $props ;
308
308
const vnode = vueInstance ?. $ ?. vnode ;
309
- if ( hasProp ( vueInstance , name ) && ! isEqual ( value , props [ name ] ) && vueInstance . $emit ) {
310
- innerChanges [ name ] = toRaw ( value ) ;
311
- const eventName = name === 'value' && hasVModelValue ( vueInstance . $options , props , vnode )
312
- ? `update:${ VMODEL_NAME } `
313
- : `update:${ name } ` ;
314
309
310
+ const propsName = name === 'value' && hasVModelValue ( vueInstance . $options , props , vnode ) ? VMODEL_NAME : name ;
311
+ const eventName = `update:${ propsName } ` ;
312
+
313
+ if ( hasProp ( vueInstance , name ) && ! isEqual ( value , props [ propsName ] ) && vueInstance . $emit ) {
314
+ innerChanges [ propsName ] = toRaw ( value ) ;
315
315
vueInstance . $emit ( eventName , value ) ;
316
316
}
317
317
} ;
You can’t perform that action at this time.
0 commit comments