Skip to content

Commit

Permalink
fix(QInput/QSelect): Prevent composition on android when codepoint is…
Browse files Browse the repository at this point in the history
… below 256

close quasarframework#4578
  • Loading branch information
pdanpdan committed Jul 9, 2019
1 parent ee3db9f commit afeff6d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
10 changes: 10 additions & 0 deletions ui/src/components/input/QInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,12 @@ export default Vue.extend({
e.target.composing = true
},

__onCompositionUpdate (e) {
if (typeof e.data === 'string' && e.data.codePointAt(0) < 256) {
e.target.composing = false
}
},

__onCompositionEnd (e) {
if (e.target.composing !== true) { return }
e.target.composing = false
Expand Down Expand Up @@ -189,6 +195,10 @@ export default Vue.extend({
blur: stop
}

if (this.$q.platform.is.android === true) {
on.compositionupdate = this.__onCompositionUpdate
}

if (this.hasMask === true) {
on.keydown = this.__onMaskedKeydown
}
Expand Down
34 changes: 23 additions & 11 deletions ui/src/components/select/QSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,12 @@ export default Vue.extend({
e.target.composing = true
},

__onCompositionUpdate (e) {
if (typeof e.data === 'string' && e.data.codePointAt(0) < 256) {
e.target.composing = false
}
},

__onCompositionEnd (e) {
if (e.target.composing !== true) { return }
e.target.composing = false
Expand All @@ -806,6 +812,22 @@ export default Vue.extend({
},

__getInput (h) {
const on = {
input: this.__onInputValue,
// Safari < 10.2 & UIWebView doesn't fire compositionend when
// switching focus before confirming composition choice
// this also fixes the issue where some browsers e.g. iOS Chrome
// fires "change" instead of "input" on autocomplete.
change: this.__onCompositionEnd,
compositionstart: this.__onCompositionStart,
compositionend: this.__onCompositionEnd,
keydown: this.__onTargetKeydown
}

if (this.$q.platform.is.android === true) {
on.compositionupdate = this.__onCompositionUpdate
}

return h('input', {
ref: 'target',
staticClass: 'q-select__input q-placeholder col',
Expand All @@ -819,17 +841,7 @@ export default Vue.extend({
...this.$attrs,
disabled: this.editable !== true
},
on: {
input: this.__onInputValue,
// Safari < 10.2 & UIWebView doesn't fire compositionend when
// switching focus before confirming composition choice
// this also fixes the issue where some browsers e.g. iOS Chrome
// fires "change" instead of "input" on autocomplete.
change: this.__onCompositionEnd,
compositionstart: this.__onCompositionStart,
compositionend: this.__onCompositionEnd,
keydown: this.__onTargetKeydown
}
on
})
},

Expand Down

0 comments on commit afeff6d

Please sign in to comment.