-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Block library: reusable caption component util #56606
Conversation
Size Change: +513 B (0%) Total Size: 1.7 MB
ℹ️ View Unchanged
|
if ( ! isSelected && ! caption ) { | ||
setShowCaption( false ); | ||
} | ||
}, [ isSelected, caption ] ); |
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.
Note that I've also optimised these useEffect
and useCallback
calls. Previously these callbacks would get called whenever you type in the caption, now they're only called if emptiness changes.
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 definitely don't feel qualified to properly review this, but it looks really nice, and a good way to reduce our overall code overhead.
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.
Let's get it in use/testing!
import { createBlock, getDefaultBlockName } from '@wordpress/blocks'; | ||
|
||
export function Caption( { | ||
key = 'caption', |
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.
Can this really be used to make <Caption>
edit an attribute other than caption
? key
or ref
is a reserved prop, React won't really pass it down to the component. Let's find a better name for the prop.
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.
It was just an unfinished idea. See #59073
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, I see it's all fixed there 👍
placeholder={ placeholder } | ||
value={ caption } | ||
onChange={ ( value ) => | ||
setAttributes( { caption: value } ) |
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.
Should be setAttributes( { [ key ]: value } )
.
What?
Prep work for #43204
This is the same logic used by the Image, Gallery, Audio, and Video blocks. Let's make it reusable because it's a pain to change every instance.
Note that I've also optimised these
useEffect
anduseCallback
calls. Previously these callbacks would get called whenever you type in the caption, now they're only called if emptiness changes.Additionally emptiness checks check the length.
Why?
See #43204 (comment)
How?
Testing Instructions
Testing Instructions for Keyboard
Screenshots or screencast