-
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
Framework: Drop the focus/setFocus props from block edit functions #4872
Changes from all commits
922cb6c
ccd42a1
7fc8cb5
18b75b5
2645710
280e1b8
98e6026
78891a3
6b3bf14
83c42e5
80d0a4c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -131,10 +131,10 @@ function getEmbedBlockSettings( { title, icon, category = 'embed', transforms, k | |||||||||||||||||||||||||||||||||||||||||
render() { | ||||||||||||||||||||||||||||||||||||||||||
const { html, type, error, fetching } = this.state; | ||||||||||||||||||||||||||||||||||||||||||
const { align, url, caption } = this.props.attributes; | ||||||||||||||||||||||||||||||||||||||||||
const { setAttributes, focus, setFocus } = this.props; | ||||||||||||||||||||||||||||||||||||||||||
const { setAttributes, isSelected } = this.props; | ||||||||||||||||||||||||||||||||||||||||||
const updateAlignment = ( nextAlign ) => setAttributes( { align: nextAlign } ); | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
const controls = focus && ( | ||||||||||||||||||||||||||||||||||||||||||
const controls = isSelected && ( | ||||||||||||||||||||||||||||||||||||||||||
<BlockControls key="controls"> | ||||||||||||||||||||||||||||||||||||||||||
<BlockAlignmentToolbar | ||||||||||||||||||||||||||||||||||||||||||
value={ align } | ||||||||||||||||||||||||||||||||||||||||||
|
@@ -200,18 +200,16 @@ function getEmbedBlockSettings( { title, icon, category = 'embed', transforms, k | |||||||||||||||||||||||||||||||||||||||||
html={ html } | ||||||||||||||||||||||||||||||||||||||||||
title={ iframeTitle } | ||||||||||||||||||||||||||||||||||||||||||
type={ type } | ||||||||||||||||||||||||||||||||||||||||||
onFocus={ () => setFocus() } | ||||||||||||||||||||||||||||||||||||||||||
/> | ||||||||||||||||||||||||||||||||||||||||||
</div> | ||||||||||||||||||||||||||||||||||||||||||
) } | ||||||||||||||||||||||||||||||||||||||||||
{ ( caption && caption.length > 0 ) || !! focus ? ( | ||||||||||||||||||||||||||||||||||||||||||
{ ( caption && caption.length > 0 ) || isSelected ? ( | ||||||||||||||||||||||||||||||||||||||||||
<RichText | ||||||||||||||||||||||||||||||||||||||||||
tagName="figcaption" | ||||||||||||||||||||||||||||||||||||||||||
placeholder={ __( 'Write caption…' ) } | ||||||||||||||||||||||||||||||||||||||||||
value={ caption } | ||||||||||||||||||||||||||||||||||||||||||
focus={ focus } | ||||||||||||||||||||||||||||||||||||||||||
onFocus={ setFocus } | ||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change regressed on the fix introduced by #4011, where in that case I explicitly wanted to handle focus within the iframe. Can we otherwise expose manually setting a block as selected? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You mean like a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could see about generalizing the gutenberg/components/sandbox/index.js Lines 54 to 73 in 98d6c7e
|
||||||||||||||||||||||||||||||||||||||||||
onChange={ ( value ) => setAttributes( { caption: value } ) } | ||||||||||||||||||||||||||||||||||||||||||
isSelected={ isSelected } | ||||||||||||||||||||||||||||||||||||||||||
inlineToolbar | ||||||||||||||||||||||||||||||||||||||||||
/> | ||||||||||||||||||||||||||||||||||||||||||
) : null } | ||||||||||||||||||||||||||||||||||||||||||
|
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.
Do you think it's worth looking for availability of
window.Proxy
and, if so, return an instance of it?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 like it 👍
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.
On a second thought, we'd have to proxify the props object to do so, which I think is not really possible :(
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 I guess it's fine, it seems supported where we need it.
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.
What do you mean by this? I was just thinking of the following pseudo-code:
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 was trying to find a way to proxy any access to
props.focus
(and notfocus.*
) because the main use-case for this prop is just checking truthiness to show the block toolbar/inspectorThere 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.
Gotcha.