1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-24 07:52:50 +02:00

Apply placeholder delay only on Android devices (#5564)

This commit is contained in:
Joe Anderson
2023-11-22 13:22:40 +00:00
committed by GitHub
parent 9db2bd2c9b
commit 9aa573e9b8
2 changed files with 11 additions and 2 deletions

View File

@@ -0,0 +1,5 @@
---
'slate-react': patch
---
Apply 300ms placeholder delay only on Android devices

View File

@@ -16,7 +16,11 @@ import {
} from '../utils/weak-maps' } from '../utils/weak-maps'
import { RenderLeafProps, RenderPlaceholderProps } from './editable' import { RenderLeafProps, RenderPlaceholderProps } from './editable'
import { useSlateStatic } from '../hooks/use-slate-static' import { useSlateStatic } from '../hooks/use-slate-static'
import { IS_WEBKIT } from '../utils/environment' import { IS_WEBKIT, IS_ANDROID } from '../utils/environment'
// Delay the placeholder on Android to prevent the keyboard from closing.
// (https://github.com/ianstormtaylor/slate/pull/5368)
const PLACEHOLDER_DELAY = IS_ANDROID ? 300 : 0
function disconnectPlaceholderResizeObserver( function disconnectPlaceholderResizeObserver(
placeholderResizeObserver: MutableRefObject<ResizeObserver | null>, placeholderResizeObserver: MutableRefObject<ResizeObserver | null>,
@@ -104,7 +108,7 @@ const Leaf = (props: {
showPlaceholderTimeoutRef.current = setTimeout(() => { showPlaceholderTimeoutRef.current = setTimeout(() => {
setShowPlaceholder(true) setShowPlaceholder(true)
showPlaceholderTimeoutRef.current = null showPlaceholderTimeoutRef.current = null
}, 300) }, PLACEHOLDER_DELAY)
} }
} else { } else {
clearTimeoutRef(showPlaceholderTimeoutRef) clearTimeoutRef(showPlaceholderTimeoutRef)