提交 650573cf 编写于 作者: Q qiang

fix: 优化 input 样式,解决 letter-spacing 样式无法生效的问题 fixed #485

上级 94850f23
...@@ -2,7 +2,14 @@ ...@@ -2,7 +2,14 @@
<uni-input v-on="$listeners"> <uni-input v-on="$listeners">
<div <div
ref="wrapper" ref="wrapper"
:disabled="disabled"> class="uni-input-wrapper">
<div
v-show="!(composing || inputValue.length)"
ref="placeholder"
:style="placeholderStyle"
:class="placeholderClass"
class="uni-input-placeholder"
>{{ placeholder }}</div>
<input <input
ref="input" ref="input"
v-model="inputValue" v-model="inputValue"
...@@ -10,23 +17,16 @@ ...@@ -10,23 +17,16 @@
:type="inputType" :type="inputType"
:maxlength="maxlength" :maxlength="maxlength"
:step="step" :step="step"
class="uni-input-input"
autocomplete="off" autocomplete="off"
@focus="_onFocus" @focus="_onFocus"
@blur="_onBlur" @blur="_onBlur"
@input.stop="_onInput" @input.stop="_onInput"
@compositionstart="_onComposition" @compositionstart="_onComposition"
@compositionend="_onComposition" @compositionend="_onComposition"
@keyup.stop="_onKeyup"> @keyup.stop="_onKeyup"
<div >
v-show="!(composing || inputValue.length)"
ref="placeholder"
:style="placeholderStyle"
:class="placeholderClass"
class="input-placeholder">{{ placeholder }}</div>
</div> </div>
<v-uni-resize-sensor
ref="sensor"
@resize="_resize" />
</uni-input> </uni-input>
</template> </template>
<script> <script>
...@@ -93,8 +93,7 @@ export default { ...@@ -93,8 +93,7 @@ export default {
inputValue: this.value + '', inputValue: this.value + '',
composing: false, composing: false,
wrapperHeight: 0, wrapperHeight: 0,
cachedValue: '', cachedValue: ''
isRendered: false
} }
}, },
computed: { computed: {
...@@ -144,14 +143,13 @@ export default { ...@@ -144,14 +143,13 @@ export default {
}) })
}, },
mounted () { mounted () {
this._initInputStyle()
if (this.confirmType === 'search') { if (this.confirmType === 'search') {
var formElem = document.createElement('form') var formElem = document.createElement('form')
formElem.action = '' formElem.action = ''
formElem.onsubmit = function () { formElem.onsubmit = function () {
return false return false
} }
formElem.className = 'uni-input-form'
formElem.appendChild(this.$refs.input) formElem.appendChild(this.$refs.input)
this.$refs.wrapper.appendChild(formElem) this.$refs.wrapper.appendChild(formElem)
} }
...@@ -165,37 +163,6 @@ export default { ...@@ -165,37 +163,6 @@ export default {
}) })
}, },
methods: { methods: {
_resize () {
if (!this.isRendered) {
this._initInputStyle()
}
},
_initInputStyle () {
const wrapper = this.$refs.wrapper
const computedStyle = window.getComputedStyle(wrapper)
const rectStyle = wrapper.getBoundingClientRect()
const inputElem = this.$refs.input
const placeholderElem = this.$refs.placeholder
// 获取到的高度为 0 则认为组件未渲染,通常是使用 v-show 时会出现此情况。
if (!rectStyle.height) {
return
} else {
this.isRendered = true
}
// 渲染之后进行计算,设置实际的高度等样式。
const realHeight = rectStyle.height - (parseFloat(computedStyle.borderTopWidth, 10) + parseFloat(computedStyle.borderBottomWidth,
10))
if (realHeight !== this.wrapperHeight) {
inputElem.style.height = `${realHeight}px`
inputElem.style.lineHeight = `${realHeight}px`
this.wrapperHeight = realHeight
}
// inputElem.style.color = computedStyle.color
placeholderElem.style.height = `${realHeight}px`
placeholderElem.style.lineHeight = `${realHeight}px`
},
_onKeyup ($event) { _onKeyup ($event) {
if ($event.keyCode === 13) { if ($event.keyCode === 13) {
this.$trigger('confirm', $event, { this.$trigger('confirm', $event, {
...@@ -275,101 +242,77 @@ export default { ...@@ -275,101 +242,77 @@ export default {
} }
</script> </script>
<style> <style>
uni-input { uni-input {
display: block; display: block;
height: 1.4rem; font-size: 16px;
text-overflow: clip; line-height: 1.4em;
overflow: hidden; height: 1.4em;
white-space: nowrap; min-height: 1.4em;
font-family: UICTFontTextStyleBody; }
min-height: 1.4rem;
}
uni-input input { uni-input[hidden] {
position: relative; display: none;
min-height: inherit; }
border: none;
height: inherit;
width: 100%;
font-size: inherit;
font-weight: inherit;
font-family: UICTFontTextStyleBody;
color: inherit;
background: transparent;
display: inherit;
padding: 0;
margin: 0;
outline: none;
vertical-align: middle;
text-align: inherit;
overflow: inherit;
white-space: inherit;
text-overflow: inherit;
-webkit-tap-highlight-color: transparent;
z-index: 2;
opacity: inherit;
}
uni-input[hidden] { .uni-input-wrapper,
display: none; .uni-input-placeholder,
} .uni-input-form,
.uni-input-input {
outline: none;
border: none;
padding: 0;
margin: 0;
text-decoration: inherit;
}
uni-input div { .uni-input-wrapper {
position: relative; display: block;
min-height: inherit; position: relative;
text-overflow: inherit; width: 100%;
border: none; height: 100%;
height: inherit; }
width: inherit;
font-size: inherit;
font-weight: inherit;
font-family: UICTFontTextStyleBody;
color: inherit;
background: inherit;
padding: 0;
margin: 0;
outline: none;
text-align: inherit;
-webkit-tap-highlight-color: transparent;
}
uni-input div[type=password] div { .uni-input-placeholder,
color: black; .uni-input-input {
} position: absolute;
width: 100%;
height: 100%;
left: 0;
top: 0;
}
uni-input div div { .uni-input-placeholder {
position: absolute; color: gray;
left: 0; overflow: hidden;
top: 0; text-overflow: clip;
width: 100%; white-space: pre;
height: inherit; word-break: keep-all;
line-height: 100%; }
min-height: inherit;
white-space: pre;
text-align: inherit;
overflow: hidden;
vertical-align: middle;
z-index: 1;
}
.input-placeholder { .uni-input-input {
color: gray; background: none;
height: inherit; color: inherit;
line-height: inherit; opacity: inherit;
background: none; font: inherit;
} line-height: inherit;
letter-spacing: inherit;
text-align: inherit;
text-indent: inherit;
text-transform: inherit;
text-shadow: inherit;
}
input[type="search"]::-webkit-search-cancel-button { .uni-input-input[type="search"]::-webkit-search-cancel-button {
display: none; display: none;
} }
input::-webkit-outer-spin-button, .uni-input-input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button { .uni-input-input::-webkit-inner-spin-button {
-webkit-appearance: none; -webkit-appearance: none;
margin: 0; margin: 0;
} }
input[type="number"] { .uni-input-input[type="number"] {
-moz-appearance: textfield; -moz-appearance: textfield;
} }
</style> </style>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册