udecode / plate

The rich-text editor for React.
https://platejs.org
Other
9.24k stars 612 forks source link

The placeholder remains visible when composing using an IME #3250

Open jijiseong opened 1 month ago

jijiseong commented 1 month ago

Description

I type Korean consonant in editor such as 'ㄱ', 'ㄴ', 'ㄷ' ... onChange does not work.

Steps to Reproduce

https://github.com/udecode/plate/assets/77661228/26918d2b-93d2-4f4c-95e9-73d57fedf02b

Sandbox

Expected Behavior

<Plate
  onChange={(value) => console.log(value[0].children[0].text)}
/>

The placeholder still exists when typing 'ㅈ'.

I type 'ㅈ', 'ㅣ', 'ㅅ', 'ㅓ', 'ㅇ'

exptected console

ㅈ
지
짓
지서
지성

But actually

지
지성

I tried to fix this error. But I don't know what is causing it.

Environment

Bounty

Click here to add a bounty via Algora.

Funding

Fund with Polar

12joan commented 1 month ago

It looks like there are two different issues here.

onChange not being called When typing using an IME, the browser doesn't send certain events until after composition has finished. You can detect when IME composition is taking place by adding compositionstart, compositionupdate and compositionend handlers to your editor. https://stackoverflow.com/a/37099672

Placeholder remaining visible Curiously, Slate's custom placeholder example doesn't have this problem.

https://github.com/udecode/plate/assets/4272090/4ca9542a-5c02-48ba-9eed-55a0465d7f70

As a temporary workaround, you could try using the placeholder prop on PlateContent rather than using Plate's custom placeholder component. If you're interested in working on a proper fix for this, you could try investigating Slate's code to see how it knows to hide the placeholder. I'm guessing it's using a boolean state variable that it sets on compositionstart and compositionend.

12joan commented 1 month ago

I found the logic that Slate uses to hide the placeholder during composition:

https://github.com/ianstormtaylor/slate/blob/main/packages/slate-react/src/components/editable.tsx#L859-L864

jijiseong commented 1 month ago

Thanks for your quick response!