提交 cbc4e404 编写于 作者: D DCloud_LXH

feat: input ignoreCompositionEvent

上级 2f82156f
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
@input.stop="_onInput" @input.stop="_onInput"
@compositionstart.stop="_onComposition" @compositionstart.stop="_onComposition"
@compositionend.stop="_onComposition" @compositionend.stop="_onComposition"
@compositionupdate.stop="_onComposition"
@keyup.enter.stop="_onKeyup" @keyup.enter.stop="_onKeyup"
> >
<!-- fix: 禁止 readonly 状态获取焦点 --> <!-- fix: 禁止 readonly 状态获取焦点 -->
...@@ -201,7 +202,7 @@ export default { ...@@ -201,7 +202,7 @@ export default {
_onInput ($event, force) { _onInput ($event, force) {
let outOfMaxlength = false let outOfMaxlength = false
if (this.composing) { if (this.composing && this.ignoreCompositionEvent) {
return return
} }
...@@ -241,18 +242,28 @@ export default { ...@@ -241,18 +242,28 @@ export default {
if (outOfMaxlength) return if (outOfMaxlength) return
if (!this.ignoreCompositionEvent) this.valueSync = this.$refs.input.value
this.$triggerInput($event, { this.$triggerInput($event, {
value: this.valueSync value: this.valueSync
}, force) }, force)
}, },
_onComposition ($event) { _onComposition ($event) {
if ($event.type === 'compositionstart') { switch ($event.type) {
this.composing = true case 'compositionstart':
} else if (this.composing) { this.composing = true
this.composing = false break
// 部分输入法 compositionend 事件可能晚于 input case 'compositionend':
this._onInput($event) if (this.composing) {
this.composing = false
// 部分输入法 compositionend 事件可能晚于 input
this._onInput($event)
}
break
} }
!this.ignoreCompositionEvent &&
this.$trigger($event.type, $event, { data: $event.data })
}, },
_resetFormData () { _resetFormData () {
this.valueSync = '' this.valueSync = ''
......
...@@ -41,8 +41,9 @@ ...@@ -41,8 +41,9 @@
:enterkeyhint="confirmType" :enterkeyhint="confirmType"
class="uni-textarea-textarea" class="uni-textarea-textarea"
@change.stop @change.stop
@compositionstart.stop="_onCompositionstart" @compositionstart.stop="_onComposition"
@compositionend.stop="_onCompositionend" @compositionend.stop="_onComposition"
@compositionupdate.stop="_onComposition"
@input.stop="_onInput" @input.stop="_onInput"
@focus="_onFocus" @focus="_onFocus"
@blur="_onBlur" @blur="_onBlur"
...@@ -190,15 +191,22 @@ export default { ...@@ -190,15 +191,22 @@ export default {
!this.confirmHold && this.$refs.textarea.blur() !this.confirmHold && this.$refs.textarea.blur()
} }
}, },
_onCompositionstart ($event) { _onComposition ($event) {
this.composing = true switch ($event.type) {
}, case 'compositionstart':
_onCompositionend ($event) { this.composing = true
if (this.composing) { break
this.composing = false case 'compositionend':
// 部分输入法 compositionend 事件可能晚于 input if (this.composing) {
this._onInput($event) this.composing = false
// 部分输入法 compositionend 事件可能晚于 input
this._onInput($event)
}
break
} }
!this.ignoreCompositionEvent &&
this.$trigger($event.type, $event, { data: $event.data })
}, },
// 暂无完成按钮,此功能未实现 // 暂无完成按钮,此功能未实现
_confirm ($event) { _confirm ($event) {
...@@ -218,10 +226,13 @@ export default { ...@@ -218,10 +226,13 @@ export default {
this.height = height this.height = height
}, },
_onInput ($event, force) { _onInput ($event, force) {
if (this.composing) { if (this.composing && this.ignoreCompositionEvent) {
this.valueComposition = $event.target.value this.valueComposition = $event.target.value
return return
} }
if (!this.ignoreCompositionEvent) this.valueSync = this.$refs.textarea.value
this.$triggerInput($event, { this.$triggerInput($event, {
value: this.valueSync, value: this.valueSync,
cursor: this.$refs.textarea.selectionEnd cursor: this.$refs.textarea.selectionEnd
......
...@@ -66,6 +66,10 @@ export default { ...@@ -66,6 +66,10 @@ export default {
confirmHold: { confirmHold: {
type: Boolean, type: Boolean,
default: false default: false
},
ignoreCompositionEvent: {
type: Boolean,
default: true
} }
}, },
data () { data () {
......
...@@ -3,7 +3,7 @@ const webviewIds = [] ...@@ -3,7 +3,7 @@ const webviewIds = []
const UNIAPP_SERVICE_NVUE_ID = '__uniapp__service' const UNIAPP_SERVICE_NVUE_ID = '__uniapp__service'
const WEB_INVOKE_APPSERVICE = 'WEB_INVOKE_APPSERVICE' const WEB_INVOKE_APPSERVICE = 'WEB_INVOKE_APPSERVICE'
function isNvue() { function isNvue () {
return (window.__dcloud_weex_postMessage || window.__dcloud_weex_) return (window.__dcloud_weex_postMessage || window.__dcloud_weex_)
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册