-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Introduce a way to manage focus on the RichText editor #9740
Comments
There are internal mechanisms with a block's context including Adding a Related: Maybe worth noting that there is an |
Related: #6419 |
Maybe Additionally there's no way currently to set the focus at the end of the field. |
I think this needs to be addressed before API freeze. I tried to make a block with multiple RichText fields and it is impossible to manage focus, even with |
Plus we are still using |
The use-cases here are quite vague, or I'm not sufficiently imaginative. What is such a block trying to achieve with programmatically managing focus? |
E.g. When you have multiple RichText fields in a block and you'd like to manage split and merge behaviour. Currently this is all possible, except for setting focus to the correct field. The block in question I was working on is the list blocks (with multiple RichText fields), but I can imaging this being useful for many kinds of blocks with Rich input fields. |
At the very least I would like to see our own blocks not using |
Or maybe it should be kept (call on This could also be revised as part of the focus setting we do currently in |
Yes, it was a quite complex use case. I need to refresh my memory to figure out what was blocking us from using |
This is my previous attempt #6871 to fix it without using
|
Quoting from the duplicate issue #12587
|
I think this is essential functionality for an editable field component, which RichText is. I understand the choice to not expose the TinyMCE instance, but focusing an editable field is core functionality. |
Does this relate to the situation where a RichText component within a block receives focus when a block is inserted? I'd love to have a flag to prevent that behavior (so the user has to explicitly select the RichText area to focus it) but I'm not sure if that counts as part of this issue, or in another issue :) Could look essentially like |
No this is unrelated. It's about introducing a way to set focus programmatically on the contenteditable. Currently, there's no way to get a block editor (TinyMCE) instance, see original description and linked references. |
A related issue for the table block is potentially #14904. I can think of a workaround using event handlers and At some point I also want to introduce the ability to navigate the table block using arrow keys, which might be another use case, but also something that could use |
Update: current state of the RichText component with regards to focus management after one year this issue was created:
To recap the nature of this issue: seems to me all these changes fit only with the internal needs of Gutenberg. They don't take into consideration custom usages of RichText outside of the Gutenberg ones. Instead, plugins may need to implement their own focus management mechanisms. Consider for example a block that uses multiple RichText components like the one below: each highlighted area is a RichText: One year ago, managing focus within such a block was pretty simple. Unfortunately, all the changes in the last year made it more and more challenging. At the point that providing basic keyboard accessibility is now very hard. To me, it appears clear that Gutenberg should provide a mechanism to manage focus on the RichText instances within a block. Gutenberg removed features that made this kind of focus management possible: now, it's a Gutenberg responsibility to provide equivalent features. |
@afercia Looking into focus and rich text right now as I'm refactoring things internally. What do you need?
What more do you need? If there's anything more, could you update the issue description or create a new issue? It's a bit outdated now. |
@mtias for history and documentation, can you please add a comment pointing to where this issue was fixed? |
I am also curious to know how this is resolved now, do we have a way to set focus to a RichText component? |
Given @ellatrix articulated how to focus rich text and there were no further comments on what else might be needed closing seemed appropriate to help keep the repository in shape. |
I'm not sure the feedback from @ellatrix is up to date, given Anyways, the point is more about process. This is an open source project. Please don't close issues without a comment to explain why you are closing it. Thanks. |
I believe onFocus has been made stable a long time ago and works like any other React event |
See discussion on Slack: https://wordpress.slack.com/archives/C02QB2JS7/p1536570671000100
In 4.0 the RichText
onSetup
prop will be deprecated and changed tounstableOnSetup
. To my understanding,unstableOnSetup
won't be removed so soon, see #9106, because it's still necessary in current implementations of core blocks.However, in the future there will still be the need to access the editor instance. Simple use case: managing focus. Imagine a custom block that uses one or more RichText components and needs to manage focus programmatically depending on specific workflows.
As mentioned in the Slack discussion, one option could be introducing a
focus
function to theRichText
component. Definitely not my area of expertise, there are probably other options and considerations to explore. /Cc @iseulde @aduthThe text was updated successfully, but these errors were encountered: