-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
useRef doesn’t work for widgets in editor.BlockEdit #62266
Comments
The
I’m wondering what adding some styles looks like. I'd expected you were intending to reference the block’s DOM element and perhaps add inline styles but (where this works) the reference is to a component. Maybe you're intending to add If you’re wanting a reference to blocks’s element from the filter workarounds are possible and I could post an example. |
I add a container after the
However, I now just use a check whether |
I'm glad to know you were able to keep progressing. Perhaps you might agree that this isn’t an bug and we can close the issue?
Just an idea but would it work to only add your container when the block is selected? ( |
I’m not sure if I’m convinced that it’s no bug, since it works at least in the current block editor used in core in the post editor. 🤷🏻♂️
Unfortunately, no. It has to be visible all the time. |
I see your point about it being available in a release. Yet it doesn’t seem like it was intentional and perhaps more a bug that it became available (as in previous versions I tested it was not). Besides that, I could be missing something but I’m failing to see its utility in your use case. In testing, I found the ref is available as long as the filtered block is present in the editor. Therefore a conditional for it will always have the same result. Well, other than the first render as expected the ref will not have been attached. |
Description
I’m trying to do something based on a given block via the
editor.BlockEdit
filter. Since I need add some styles based on the givenBlockEdit
object, I useuseRef()
to get this object. While this is working fine in the regular block editor, it doesn’t work in the widget area. Instead of returning a proper reference of theBlockEdit
, it always returnsundefined
.This is a code example:
In the block editor, the console log will return the proper reference, while in the widget area, it doesn’t.
Step-by-step reproduction instructions
Screenshots, screen recording, code snippet
No response
Environment info
– WordPress 6.5.3
Please confirm that you have searched existing issues in the repo.
Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Yes
The text was updated successfully, but these errors were encountered: