Commit e2a877c46abf9be9b7d436c307485f4e4f7712dd

Authored by 梁灏
1 parent 1044a56b

Input add search & enterButton prop

examples/routers/input.vue
@@ -128,14 +128,19 @@ @@ -128,14 +128,19 @@
128 <Icon type="ios-alarm-outline" slot="suffix" /> 128 <Icon type="ios-alarm-outline" slot="suffix" />
129 <Icon type="ios-aperture" slot="prefix" /> 129 <Icon type="ios-aperture" slot="prefix" />
130 </Input> 130 </Input>
131 - <br> 131 + <br><br><br><br>
  132 + <Input v-model="value" search enter-button style="width: 300px" />
  133 + <br><br>
  134 + <Input v-model="value" search style="width: 300px" />
  135 + <br><br>
  136 + <Input v-model="value" search enter-button="搜索" style="width: 300px" />
132 </div> 137 </div>
133 </template> 138 </template>
134 <script> 139 <script>
135 export default { 140 export default {
136 data () { 141 data () {
137 return { 142 return {
138 - value: '你好你好你真好你好你好你真好你好你好你真好你好你好你真好', 143 + value: '',
139 value11: '', 144 value11: '',
140 value12: '', 145 value12: '',
141 value13: '', 146 value13: '',
src/components/input/input.vue
@@ -4,6 +4,7 @@ @@ -4,6 +4,7 @@
4 <div :class="[prefixCls + '-group-prepend']" v-if="prepend" v-show="slotReady"><slot name="prepend"></slot></div> 4 <div :class="[prefixCls + '-group-prepend']" v-if="prepend" v-show="slotReady"><slot name="prepend"></slot></div>
5 <i class="ivu-icon" :class="['ivu-icon-ios-close-circle', prefixCls + '-icon', prefixCls + '-icon-clear' , prefixCls + '-icon-normal']" v-if="clearable && currentValue" @click="handleClear"></i> 5 <i class="ivu-icon" :class="['ivu-icon-ios-close-circle', prefixCls + '-icon', prefixCls + '-icon-clear' , prefixCls + '-icon-normal']" v-if="clearable && currentValue" @click="handleClear"></i>
6 <i class="ivu-icon" :class="['ivu-icon-' + icon, prefixCls + '-icon', prefixCls + '-icon-normal']" v-else-if="icon" @click="handleIconClick"></i> 6 <i class="ivu-icon" :class="['ivu-icon-' + icon, prefixCls + '-icon', prefixCls + '-icon-normal']" v-else-if="icon" @click="handleIconClick"></i>
  7 + <i class="ivu-icon ivu-icon-ios-search" :class="[prefixCls + '-icon', prefixCls + '-icon-normal', prefixCls + '-search-icon']" v-else-if="search && enterButton === false" @click="handleSearch"></i>
7 <span class="ivu-input-suffix" v-else-if="showSuffix"><slot name="suffix"><i class="ivu-icon" :class="['ivu-icon-' + suffix]" v-if="suffix"></i></slot></span> 8 <span class="ivu-input-suffix" v-else-if="showSuffix"><slot name="suffix"><i class="ivu-icon" :class="['ivu-icon-' + suffix]" v-if="suffix"></i></slot></span>
8 <transition name="fade"> 9 <transition name="fade">
9 <i class="ivu-icon ivu-icon-ios-loading ivu-load-loop" :class="[prefixCls + '-icon', prefixCls + '-icon-validate']" v-if="!icon"></i> 10 <i class="ivu-icon ivu-icon-ios-loading ivu-load-loop" :class="[prefixCls + '-icon', prefixCls + '-icon-validate']" v-if="!icon"></i>
@@ -32,6 +33,10 @@ @@ -32,6 +33,10 @@
32 @input="handleInput" 33 @input="handleInput"
33 @change="handleChange"> 34 @change="handleChange">
34 <div :class="[prefixCls + '-group-append']" v-if="append" v-show="slotReady"><slot name="append"></slot></div> 35 <div :class="[prefixCls + '-group-append']" v-if="append" v-show="slotReady"><slot name="append"></slot></div>
  36 + <div :class="[prefixCls + '-group-append', prefixCls + '-search']" v-else-if="search && enterButton" @click="handleSearch">
  37 + <i class="ivu-icon ivu-icon-ios-search" v-if="enterButton === true"></i>
  38 + <template v-else>{{ enterButton }}</template>
  39 + </div>
35 <span class="ivu-input-prefix" v-else-if="showPrefix"><slot name="prefix"><i class="ivu-icon" :class="['ivu-icon-' + prefix]" v-if="prefix"></i></slot></span> 40 <span class="ivu-input-prefix" v-else-if="showPrefix"><slot name="prefix"><i class="ivu-icon" :class="['ivu-icon-' + prefix]" v-if="prefix"></i></slot></span>
36 </template> 41 </template>
37 <textarea 42 <textarea
@@ -152,6 +157,14 @@ @@ -152,6 +157,14 @@
152 suffix: { 157 suffix: {
153 type: String, 158 type: String,
154 default: '' 159 default: ''
  160 + },
  161 + search: {
  162 + type: Boolean,
  163 + default: false
  164 + },
  165 + enterButton: {
  166 + type: [Boolean, String],
  167 + default: false
155 } 168 }
156 }, 169 },
157 data () { 170 data () {
@@ -173,11 +186,12 @@ @@ -173,11 +186,12 @@
173 { 186 {
174 [`${prefixCls}-wrapper-${this.size}`]: !!this.size, 187 [`${prefixCls}-wrapper-${this.size}`]: !!this.size,
175 [`${prefixCls}-type`]: this.type, 188 [`${prefixCls}-type`]: this.type,
176 - [`${prefixCls}-group`]: this.prepend || this.append,  
177 - [`${prefixCls}-group-${this.size}`]: (this.prepend || this.append) && !!this.size, 189 + [`${prefixCls}-group`]: this.prepend || this.append || (this.search && this.enterButton),
  190 + [`${prefixCls}-group-${this.size}`]: (this.prepend || this.append || (this.search && this.enterButton)) && !!this.size,
178 [`${prefixCls}-group-with-prepend`]: this.prepend, 191 [`${prefixCls}-group-with-prepend`]: this.prepend,
179 - [`${prefixCls}-group-with-append`]: this.append,  
180 - [`${prefixCls}-hide-icon`]: this.append // #554 192 + [`${prefixCls}-group-with-append`]: this.append || (this.search && this.enterButton),
  193 + [`${prefixCls}-hide-icon`]: this.append, // #554
  194 + [`${prefixCls}-with-search`]: (this.search && this.enterButton)
181 } 195 }
182 ]; 196 ];
183 }, 197 },
@@ -188,7 +202,7 @@ @@ -188,7 +202,7 @@
188 [`${prefixCls}-${this.size}`]: !!this.size, 202 [`${prefixCls}-${this.size}`]: !!this.size,
189 [`${prefixCls}-disabled`]: this.disabled, 203 [`${prefixCls}-disabled`]: this.disabled,
190 [`${prefixCls}-with-prefix`]: this.showPrefix, 204 [`${prefixCls}-with-prefix`]: this.showPrefix,
191 - [`${prefixCls}-with-suffix`]: this.showSuffix 205 + [`${prefixCls}-with-suffix`]: this.showSuffix || (this.search && this.enterButton === false)
192 } 206 }
193 ]; 207 ];
194 }, 208 },
@@ -276,6 +290,10 @@ @@ -276,6 +290,10 @@
276 this.$emit('input', ''); 290 this.$emit('input', '');
277 this.setCurrentValue(''); 291 this.setCurrentValue('');
278 this.$emit('on-change', e); 292 this.$emit('on-change', e);
  293 + },
  294 + handleSearch () {
  295 + if (this.disable) return false;
  296 + this.$refs.input.focus();
279 } 297 }
280 }, 298 },
281 watch: { 299 watch: {
src/styles/components/input.less
@@ -101,6 +101,53 @@ @@ -101,6 +101,53 @@
101 &-with-suffix{ 101 &-with-suffix{
102 padding-right: 32px; 102 padding-right: 32px;
103 } 103 }
  104 +
  105 + // search
  106 + &-search{
  107 + cursor: pointer;
  108 + padding: 0 16px !important;
  109 + background: @primary-color !important;
  110 + color: #fff !important;
  111 + border-color: @primary-color !important;
  112 + transition: all @transition-time @ease-in-out;
  113 + position: relative;
  114 + z-index: 2;
  115 +
  116 + &:hover{
  117 + background: tint(@primary-color, 20%) !important;
  118 + border-color: tint(@primary-color, 20%) !important;
  119 + }
  120 + &:active{
  121 + background: shade(@primary-color, 5%) !important;
  122 + border-color: shade(@primary-color, 5%) !important;
  123 + }
  124 +
  125 + &-icon{
  126 + cursor: pointer;
  127 + transition: color @transition-time @ease-in-out;
  128 + &:hover{
  129 + color: inherit;
  130 + }
  131 + }
  132 +
  133 + &:before{
  134 + content: '';
  135 + display: block;
  136 + width: 1px;
  137 + position: absolute;
  138 + top: -1px;
  139 + bottom: -1px;
  140 + left: -1px;
  141 + background: inherit;
  142 + }
  143 + }
  144 + &-with-search{
  145 + &:hover{
  146 + .@{input-prefix-cls} {
  147 + border-color: tint(@primary-color, 20%);
  148 + }
  149 + }
  150 + }
104 } 151 }
105 152
106 .@{input-prefix-cls}-group{ 153 .@{input-prefix-cls}-group{