提交 cb238828 编写于 作者: D DCloud_LXH

fix:

1. 修复 input 组件cursor、selectionStart、selectionEnd属性无效
2. 更新 移除textarea组件cursor、selectionStart、selectionEnd属性仅在设置自动获取焦点时生效
3. 修复 当自动获取焦点时,cursor、selectionStart、selectionEnd属性无效
上级 bcc322d5
......@@ -98,12 +98,9 @@ export default {
},
data () {
return {
composing: false,
valid: true,
wrapperHeight: 0,
cachedValue: '',
// Safari 14 以上修正禁用状态颜色
fixColor: String(navigator.vendor).indexOf('Apple') === 0 && CSS.supports('image-orientation:from-image')
cachedValue: ''
}
},
computed: {
......@@ -212,21 +209,6 @@ export default {
value: this.valueSync
}, force)
},
_onFocus ($event) {
this.$trigger('focus', $event, {
value: $event.target.value
})
},
_onBlur ($event) {
// iOS 输入法 compositionend 事件可能晚于 blur
if (this.composing) {
this.composing = false
this._onInput($event, true)
}
this.$trigger('blur', $event, {
value: $event.target.value
})
},
_onComposition ($event) {
if ($event.type === 'compositionstart') {
this.composing = true
......
......@@ -100,18 +100,6 @@ export default {
type: [Boolean, String],
default: false
},
cursor: {
type: [Number, String],
default: -1
},
selectionStart: {
type: [Number, String],
default: -1
},
selectionEnd: {
type: [Number, String],
default: -1
},
confirmType: {
type: String,
default: ''
......@@ -120,14 +108,10 @@ export default {
data () {
return {
valueComposition: '',
composing: false,
focusSync: this.focus,
height: 0,
focusChangeSource: '',
// iOS 13 以下版本需要修正边距
fixMargin: String(navigator.platform).indexOf('iP') === 0 && String(navigator.vendor).indexOf('Apple') === 0 && window.matchMedia(DARK_TEST_STRING).media !== DARK_TEST_STRING,
// Safari 14 以上修正禁用状态颜色
fixColor: String(navigator.vendor).indexOf('Apple') === 0 && CSS.supports('image-orientation:from-image')
fixMargin: String(navigator.platform).indexOf('iP') === 0 && String(navigator.vendor).indexOf('Apple') === 0 && window.matchMedia(DARK_TEST_STRING).media !== DARK_TEST_STRING
}
},
computed: {
......@@ -135,18 +119,6 @@ export default {
var maxlength = Number(this.maxlength)
return isNaN(maxlength) ? 140 : maxlength
},
cursorNumber () {
var cursor = Number(this.cursor)
return isNaN(cursor) ? -1 : cursor
},
selectionStartNumber () {
var selectionStart = Number(this.selectionStart)
return isNaN(selectionStart) ? -1 : selectionStart
},
selectionEndNumber () {
var selectionEnd = Number(this.selectionEnd)
return isNaN(selectionEnd) ? -1 : selectionEnd
},
valueCompute () {
return (this.composing ? this.valueComposition : this.valueSync).split('\n')
},
......@@ -160,20 +132,6 @@ export default {
this.focusChangeSource = 'focus'
}
},
focusSync (val) {
this.$emit('update:focus', val)
this._checkSelection()
this._checkCursor()
},
cursorNumber () {
this._checkCursor()
},
selectionStartNumber () {
this._checkSelection()
},
selectionEndNumber () {
this._checkSelection()
},
height (height) {
let lineHeight = parseFloat(getComputedStyle(this.$el).lineHeight)
if (isNaN(lineHeight)) {
......@@ -228,35 +186,6 @@ export default {
this.$refs.textarea.blur()
}
},
_onFocus: function ($event) {
this.focusSync = true
this.$trigger('focus', $event, {
value: this.valueSync
})
},
_checkSelection () {
if (this.focusSync && (!this.focusChangeSource) && this.selectionStartNumber > -1 && this.selectionEndNumber > -1) {
this.$refs.textarea.selectionStart = this.selectionStartNumber
this.$refs.textarea.selectionEnd = this.selectionEndNumber
}
},
_checkCursor () {
if (this.focusSync && (this.focusChangeSource === 'focus' || ((!this.focusChangeSource) && this.selectionStartNumber < 0 && this.selectionEndNumber < 0)) && this.cursorNumber > -1) {
this.$refs.textarea.selectionEnd = this.$refs.textarea.selectionStart = this.cursorNumber
}
},
_onBlur: function ($event) {
// iOS 输入法 compositionend 事件可能晚于 blur
if (this.composing) {
this.composing = false
this._onInput($event, true)
}
this.focusSync = false
this.$trigger('blur', $event, {
value: this.valueSync,
cursor: this.$refs.textarea.selectionEnd
})
},
_onCompositionstart ($event) {
this.composing = true
},
......
......@@ -49,11 +49,27 @@ export default {
focus: {
type: [Boolean, String],
default: false
},
cursor: {
type: [Number, String],
default: -1
},
selectionStart: {
type: [Number, String],
default: -1
},
selectionEnd: {
type: [Number, String],
default: -1
}
},
data () {
return {
valueSync: this._getValueString(this.value)
composing: false,
valueSync: this._getValueString(this.value),
focusSync: this.focus,
// Safari 14 以上修正禁用状态颜色
fixColor: String(navigator.vendor).indexOf('Apple') === 0 && CSS.supports('image-orientation:from-image')
}
},
watch: {
......@@ -63,11 +79,35 @@ export default {
} else {
this._blur()
}
},
focusSync (val) {
this.$emit('update:focus', val)
},
cursorNumber () {
this._checkCursor()
},
selectionStartNumber () {
this._checkSelection()
},
selectionEndNumber () {
this._checkSelection()
}
},
computed: {
needFocus () {
return this.autoFocus || this.focus
},
cursorNumber () {
var cursor = Number(this.cursor)
return isNaN(cursor) ? -1 : cursor
},
selectionStartNumber () {
var selectionStart = Number(this.selectionStart)
return isNaN(selectionStart) ? -1 : selectionStart
},
selectionEndNumber () {
var selectionEnd = Number(this.selectionEnd)
return isNaN(selectionEnd) ? -1 : selectionEnd
}
},
created () {
......@@ -133,6 +173,38 @@ export default {
_blur () {
const field = this._field
field && field.blur()
},
_onFocus ($event) {
this.focusSync = true
this.$trigger('focus', $event, {
value: this.valueSync
})
// 从 watch:focusSync 中移出到这里。在watcher中如果focus初始值为ture,则不会执行以下逻辑
this._checkSelection()
this._checkCursor()
},
_onBlur ($event) {
// iOS 输入法 compositionend 事件可能晚于 blur
if (this.composing) {
this.composing = false
this._onInput($event, true)
}
this.focusSync = false
this.$trigger('blur', $event, {
value: this.valueSync,
cursor: $event.target.selectionEnd
})
},
_checkSelection () {
if (this.focusSync && this.selectionStartNumber > -1 && this.selectionEndNumber > -1) {
this._field.selectionStart = this.selectionStartNumber
this._field.selectionEnd = this.selectionEndNumber
}
},
_checkCursor () {
if (this.focusSync && this.selectionStartNumber < 0 && this.selectionEndNumber < 0 && this.cursorNumber > -1) {
this._field.selectionEnd = this._field.selectionStart = this.cursorNumber
}
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册