Skip to content

Commit

Permalink
Make HAS_BEFORE_INPUT_SUPPORT flag more generic. (#4118)
Browse files Browse the repository at this point in the history
* 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 <ian@ianstormtaylor.com>
  • Loading branch information
kamilkazmierczak and ianstormtaylor authored Apr 13, 2021
1 parent d79267c commit 6a13763
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/dirty-rabbits-speak.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'slate-react': patch
---

Improved detection of legacy browsers that don't have proper `beforeinput` support.
12 changes: 6 additions & 6 deletions packages/slate-react/src/components/editable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 6a13763

Please sign in to comment.