Skip to content

Commit c6381ce

Browse files
authored
fix(input): IME composition mode (#24735)
Resolves #24669
1 parent 4ff9524 commit c6381ce

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

core/src/components/input/input.tsx

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export class Input implements ComponentInterface {
2222
private inputId = `ion-input-${inputIds++}`;
2323
private didBlurAfterEdit = false;
2424
private inheritedAttributes: { [k: string]: any } = {};
25+
private isComposing = false;
2526

2627
/**
2728
* This is required for a WebKit bug which requires us to
@@ -231,7 +232,7 @@ export class Input implements ComponentInterface {
231232
*/
232233
@Watch('value')
233234
protected valueChanged() {
234-
if (this.nativeInput) {
235+
if (this.nativeInput && !this.isComposing) {
235236
/**
236237
* Assigning the native input's value on attribute
237238
* value change, allows `ionInput` implementations
@@ -264,12 +265,27 @@ export class Input implements ComponentInterface {
264265
}
265266
}
266267

268+
componentDidLoad() {
269+
const nativeInput = this.nativeInput;
270+
if (nativeInput) {
271+
// TODO: FW-729 Update to JSX bindings when Stencil resolves bug with:
272+
// https://github.com/ionic-team/stencil/issues/3235
273+
nativeInput.addEventListener('compositionstart', this.onCompositionStart);
274+
nativeInput.addEventListener('compositionend', this.onCompositionEnd);
275+
}
276+
}
277+
267278
disconnectedCallback() {
268279
if (Build.isBrowser) {
269280
document.dispatchEvent(new CustomEvent('ionInputDidUnload', {
270281
detail: this.el
271282
}));
272283
}
284+
const nativeInput = this.nativeInput;
285+
if (nativeInput) {
286+
nativeInput.removeEventListener('compositionstart', this.onCompositionStart);
287+
nativeInput.removeEventListener('compositionEnd', this.onCompositionEnd);
288+
}
273289
}
274290

275291
/**
@@ -368,6 +384,14 @@ export class Input implements ComponentInterface {
368384
}
369385
}
370386

387+
private onCompositionStart = () => {
388+
this.isComposing = true;
389+
}
390+
391+
private onCompositionEnd = () => {
392+
this.isComposing = false;
393+
}
394+
371395
private clearTextOnEnter = (ev: KeyboardEvent) => {
372396
if (ev.key === 'Enter') { this.clearTextInput(ev); }
373397
}

0 commit comments

Comments
 (0)