From 2508797ff151195f64a8befc0dcb3812fc68c1c1 Mon Sep 17 00:00:00 2001 From: Ben Gotow Date: Mon, 1 Jul 2019 13:41:18 -0500 Subject: [PATCH] Do not jump to next field when pressing Tab during IME composition #1531 --- app/src/components/tab-group-region.tsx | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/app/src/components/tab-group-region.tsx b/app/src/components/tab-group-region.tsx index c1e81eded..ca7dde47d 100644 --- a/app/src/components/tab-group-region.tsx +++ b/app/src/components/tab-group-region.tsx @@ -9,16 +9,24 @@ import React from 'react'; import ReactDOM from 'react-dom'; import PropTypes from 'prop-types'; +let compositionActive = false; +document.addEventListener('compositionstart', () => { + compositionActive = true; +}); +document.addEventListener('compositionend', () => { + compositionActive = false; +}); + export class TabGroupRegion extends React.Component> { static childContextTypes = { parentTabGroup: PropTypes.object }; _onKeyDown = event => { - if (event.key === 'Tab' && !event.defaultPrevented) { - const dir = event.shiftKey ? -1 : 1; - this.shiftFocus(dir); - event.preventDefault(); - event.stopPropagation(); - } + if (event.key !== 'Tab' || event.defaultPrevented) return; + if (compositionActive) return; + const dir = event.shiftKey ? -1 : 1; + this.shiftFocus(dir); + event.preventDefault(); + event.stopPropagation(); }; shiftFocus = dir => {