Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update caption UI when element caption property changes #3287

Merged
merged 3 commits into from
Jun 15, 2024

Conversation

TyMick
Copy link
Contributor

@TyMick TyMick commented Jun 14, 2024

Currently, the caption plugin is using an internal React state variable as the source of truth for the caption value. While it is updating the Slate element's caption property when the caption value changes, it is only reading the element caption property to set the initial value of the aforementioned React state. So after the caption mounts, external changes to the element's caption property do not get reflected in the caption textarea.

In my app, this bug is most apparent when using undo/redo. After typing some text into a caption textarea, the undo action will revert one character at a time in the caption property on the element itself, but the caption textarea will remain unchanged.

This PR removes the internal React state variable and uses the element's caption property as the source of truth for the caption value. This change fixes the bug in my own app.

TyMick added 3 commits June 14, 2024 15:14
This happened when I ran `yarn` in my local repo using Node.js v18.20.3
and Yarn v4.1.0. Not sure if the problem's in my local environment or
the repo itself.
Copy link

changeset-bot bot commented Jun 14, 2024

🦋 Changeset detected

Latest commit: f805c83

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@udecode/plate-caption Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Jun 14, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
plate ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 14, 2024 11:16pm

@felixfeng33
Copy link
Collaborator

Thank you for your PR.You are right.But I found when we focus the textarea we can not redo.Are you interested in fixing this together?It might just require calling the editor.redo/editor.undo on the keyDown event of textarea.Hide the caption if the character is empty when undoing.

@felixfeng33
Copy link
Collaborator

I will fixes these later thanks again @TyMick

@felixfeng33 felixfeng33 merged commit 9d1b552 into udecode:main Jun 15, 2024
6 checks passed
@TyMick
Copy link
Contributor Author

TyMick commented Jun 17, 2024

Wow, thanks for the quick response! 🚀

Good point on losing the Slate undo/redo shortcuts when the textarea's focused. I did notice that, but it's not a priority for our team right now for a couple of reasons. First, the browser undo/redo will at least affect what's been typed in the textarea when the textarea's focused, and the caption plugin still syncs those contents with the Slate document. And second, we're including undo/redo buttons in our fixed editor toolbar, so those will still give our users access to Slate undo/redo functionality when they have a caption focused. Overriding the browser undo/redo in caption textareas would be a nice enhancement for the future, though!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants