-
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
[WIP] Core blocks: Refactor Gallery and Image blocks to avoid RichText warnings #6871
Conversation
core-blocks/image/edit.js
Outdated
@@ -389,6 +363,11 @@ class ImageEdit extends Component { | |||
} | |||
|
|||
export default compose( [ | |||
withBlockEditContext( ( { setFocusedElement } ) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice trick, do you think this should be documented or recommended?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did the same for both BlockEdit
and Plugin
- it's more work to map context to props, but I like the fact that you don't need to navigate between files to discover how context is injected into a component.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, we could even create a factory for it :D
editor/components/index.js
Outdated
@@ -5,6 +5,7 @@ export { default as AlignmentToolbar } from './alignment-toolbar'; | |||
export { default as BlockAlignmentToolbar } from './block-alignment-toolbar'; | |||
export { default as BlockControls } from './block-controls'; | |||
export { default as BlockEdit } from './block-edit'; | |||
export { withBlockEditContext } from './block-edit/context'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still on the fence here, what's the difference between making this available to block authors and passing its content as props to edit
like we do for several other props :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @aduth Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can do prop drilling
for blocks, too :)
To be honest, I wasn't happy about exposing this HOC.
Should we just add default |
I added a kind of automated default There is a bigger issue with other components, which this PR unveiled. I'm leaning towards the solution proposed by @youknowriad to pass down |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious about the a11y of switching to onClick
but the code seems fine to me...
core-blocks/gallery/gallery-image.js
Outdated
<figure | ||
className={ className } | ||
tabIndex="-1" | ||
onClick={ this.props.onSelect } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Drive-by review, but does the change from onFocus
in the child RichText
component to the onClick
here present any accessibility issues? How does keyboard navigation work after this change (I didn't see it mentioned in the manual testing being done)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't tested it with the keyboard, I will double check if it should be updated to onFocus
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to use onFocus
. It looks like Gallery block isn't navigable with keyboard :( Related issue: #3836.
38f7978
to
6dc4397
Compare
I don't think it's been shown that we need to expose |
The issue is that sometimes RichText loses the focus but we still want to keep it selected. (Link modal, toolbar buttons), It's probably doable but not simple because of the fact that popovers show outside the RichText's node. |
I'm not sure I understand where we rely on this. Can you detail a simple set of steps to reproduce? |
Let me update PR so we could discover where it could fail. I think we can make it opt-in/out if necessary. |
When you click the "link" button in the RichText toolbar, the RichText loses the focus and it's transfered to the input in the link modal which is rendered outside the RichText which means the isSelected prop of the RichText will move to I did try this a long time ago :) |
9da4eb4
to
17603b2
Compare
Removed I will play with it a bit more tomorrow. As far as I understand, what we really need is to set |
We're approaching the 3.0 release and the proxy event handlers will be removed, should we add an explicit |
Yes, let’s go with explicit onFocus. I didn’t come up with anything that would handle it automatically. As you already noted, this seems like a very difficult use case to solve. I plan to play a bit more with .closest but it probably will fail as it operates on DOM nit React DOM 🙁 |
Note: The explicit |
@mcsf, the original issue is resolved but there are more issues to solve here as explained in my comment in here #7463 (comment). Let’s close this PR for now. We can reuse this code later when we have an idea how to improve focus handling for RichText component. |
Description
With #6286 we have deprecated event proxying.
@youknowriad discovered the following:
This PR tries to fix it.
How has this been tested?
Make sure that Image and Gallery blocks work like before and there are no warnings on JS console related to
RichText
component.Types of changes
Refactoring.
Checklist: