From 6a1376332bbd2567336c444c57c1e64fdf706feb Mon Sep 17 00:00:00 2001 From: kamilkazmierczak Date: Tue, 13 Apr 2021 17:20:09 +0200 Subject: [PATCH] Make HAS_BEFORE_INPUT_SUPPORT flag more generic. (#4118) * Change "HAS_BEFORE_INPUT_SUPPORT" flag to more generic. * Fix patterns and styles issues. * Fix lint issues. * Create dirty-rabbits-speak.md * Update dirty-rabbits-speak.md * Update editable.tsx Co-authored-by: Ian Storm Taylor --- .changeset/dirty-rabbits-speak.md | 5 +++++ packages/slate-react/src/components/editable.tsx | 12 ++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) create mode 100644 .changeset/dirty-rabbits-speak.md diff --git a/.changeset/dirty-rabbits-speak.md b/.changeset/dirty-rabbits-speak.md new file mode 100644 index 000000000..764554cd0 --- /dev/null +++ b/.changeset/dirty-rabbits-speak.md @@ -0,0 +1,5 @@ +--- +'slate-react': patch +--- + +Improved detection of legacy browsers that don't have proper `beforeinput` support. diff --git a/packages/slate-react/src/components/editable.tsx b/packages/slate-react/src/components/editable.tsx index 1abc1a95e..c76446a34 100644 --- a/packages/slate-react/src/components/editable.tsx +++ b/packages/slate-react/src/components/editable.tsx @@ -21,7 +21,6 @@ import { IS_SAFARI, IS_EDGE_LEGACY, IS_CHROME_LEGACY, - IS_FIREFOX_LEGACY, } from '../utils/environment' import { ReactEditor } from '..' import { ReadOnlyContext } from '../hooks/use-read-only' @@ -50,11 +49,12 @@ import { // COMPAT: Firefox/Edge Legacy don't support the `beforeinput` event // Chrome Legacy doesn't support `beforeinput` correctly -const HAS_BEFORE_INPUT_SUPPORT = !( - IS_FIREFOX_LEGACY || - IS_EDGE_LEGACY || - IS_CHROME_LEGACY -) +const HAS_BEFORE_INPUT_SUPPORT = + !IS_CHROME_LEGACY && + !IS_EDGE_LEGACY && + globalThis.InputEvent && + // @ts-ignore The `getTargetRanges` property isn't recognized. + typeof globalThis.InputEvent.prototype.getTargetRanges === 'function' /** * `RenderElementProps` are passed to the `renderElement` handler.