@@ -6,6 +6,7 @@ import QColorPicker from './QColorPicker'
66import { QBtn } from '../btn'
77import { QModal } from '../modal'
88import clone from '../../utils/clone'
9+ import { stopAndPrevent } from '../../utils/event'
910
1011let contentCss = __THEME__ === 'ios'
1112 ? {
@@ -36,10 +37,11 @@ export default {
3637 } ,
3738 displayValue : String ,
3839 placeholder : String ,
39- noClear : Boolean ,
40- clearLabel : String ,
40+ clearable : Boolean ,
4141 okLabel : String ,
42- cancelLabel : String
42+ cancelLabel : String ,
43+ disable : Boolean ,
44+ readonly : Boolean
4345 } ,
4446 data ( ) {
4547 let data = this . isPopover ( ) ? { } : {
@@ -58,6 +60,9 @@ export default {
5860 usingPopover ( ) {
5961 return this . isPopover ( )
6062 } ,
63+ editable ( ) {
64+ return ! this . disable && ! this . readonly
65+ } ,
6166 actualValue ( ) {
6267 if ( this . displayValue ) {
6368 return this . displayValue
@@ -90,15 +95,14 @@ export default {
9095 this . focused = false
9196 return this . $refs . popup . hide ( )
9297 } ,
93- clear ( ) {
94- if ( this . value ) {
95- this . $emit ( 'input' , null )
96- this . $emit ( 'change' , null )
97- }
98- this . $refs . popup . hide ( )
98+ clear ( evt ) {
99+ stopAndPrevent ( evt )
100+ this . $emit ( 'input' , null )
101+ this . $emit ( 'change' , null )
99102 } ,
100103
101104 __onFocus ( ) {
105+ this . __setModel ( this . value )
102106 this . focused = true
103107 this . $emit ( 'focus' )
104108 } ,
@@ -114,15 +118,20 @@ export default {
114118 __onHide ( ) {
115119 this . focused = false
116120 this . $emit ( 'blur' )
121+ if ( this . usingPopover ) {
122+ this . __update ( true )
123+ }
117124 } ,
118- __setModel ( ) {
119- this . model = this . value
120- ? clone ( this . value )
125+ __setModel ( val = this . value ) {
126+ this . model = val
127+ ? clone ( val )
121128 : this . defaultSelection
122129 } ,
123- __update ( ) {
130+ __update ( change ) {
124131 this . $emit ( 'input' , this . model )
125- this . $emit ( 'change' , this . model )
132+ if ( change ) {
133+ this . $emit ( 'change' , this . model )
134+ }
126135 } ,
127136
128137 __getPicker ( h , modal ) {
@@ -131,14 +140,19 @@ export default {
131140 staticClass : `no-border${ modal ? ' full-width' : '' } ` ,
132141 props : extend ( {
133142 color : this . color ,
134- value : this . model
143+ value : this . model ,
144+ disable : this . disable ,
145+ readonly : this . readonly
135146 } , this . $attrs ) ,
136147 on : {
137148 input : v => {
138149 this . model = v
139150 if ( this . usingPopover ) {
140151 this . __update ( )
141152 }
153+ } ,
154+ change : v => {
155+ this . model = v
142156 }
143157 }
144158 } )
@@ -148,18 +162,6 @@ export default {
148162 child [ __THEME__ === 'mat' ? 'push' : 'unshift' ] ( h ( 'div' , {
149163 staticClass : 'modal-buttons modal-buttons-top row full-width'
150164 } , [
151- ! this . noClear && this . model
152- ? h ( QBtn , {
153- props : {
154- color : this . color ,
155- flat : true ,
156- label : this . clearLabel || this . $q . i18n . label . clear ,
157- waitForRipple : true ,
158- compact : true
159- } ,
160- on : { click : this . clear }
161- } )
162- : null ,
163165 h ( 'div' , { staticClass : 'col' } ) ,
164166 h ( QBtn , {
165167 props : {
@@ -171,21 +173,23 @@ export default {
171173 } ,
172174 on : { click : this . hide }
173175 } ) ,
174- h ( QBtn , {
175- props : {
176- color : this . color ,
177- flat : true ,
178- label : this . okLabel || this . $q . i18n . label . set ,
179- waitForRipple : true ,
180- compact : true
181- } ,
182- on : {
183- click : ( ) => {
184- this . hide ( )
185- this . __update ( )
176+ this . editable
177+ ? h ( QBtn , {
178+ props : {
179+ color : this . color ,
180+ flat : true ,
181+ label : this . okLabel || this . $q . i18n . label . set ,
182+ waitForRipple : true ,
183+ compact : true
184+ } ,
185+ on : {
186+ click : ( ) => {
187+ this . hide ( )
188+ this . __update ( true )
189+ }
186190 }
187- }
188- } )
191+ } )
192+ : null
189193 ] ) )
190194 }
191195
@@ -256,6 +260,15 @@ export default {
256260 }
257261 } , this . __getPicker ( h , true ) ) ,
258262
263+ this . editable && this . clearable && this . actualValue . length
264+ ? h ( 'q-icon' , {
265+ slot : 'after' ,
266+ props : { name : this . $q . icon . input . clear } ,
267+ on : { click : this . clear } ,
268+ staticClass : 'q-if-control'
269+ } )
270+ : null ,
271+
259272 h ( 'q-icon' , {
260273 slot : 'after' ,
261274 props : { name : this . $q . icon . input . dropdown } ,
0 commit comments