-
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
Social Link: Add contentOnly editing support #66622
Changes from all commits
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 |
---|---|---|
|
@@ -10,18 +10,22 @@ import { DELETE, BACKSPACE } from '@wordpress/keycodes'; | |
import { useDispatch } from '@wordpress/data'; | ||
|
||
import { | ||
BlockControls, | ||
InspectorControls, | ||
URLPopover, | ||
URLInput, | ||
useBlockEditingMode, | ||
useBlockProps, | ||
store as blockEditorStore, | ||
} from '@wordpress/block-editor'; | ||
import { useState } from '@wordpress/element'; | ||
import { | ||
Button, | ||
Dropdown, | ||
PanelBody, | ||
PanelRow, | ||
TextControl, | ||
ToolbarButton, | ||
__experimentalInputControlSuffixWrapper as InputControlSuffixWrapper, | ||
} from '@wordpress/components'; | ||
import { __ } from '@wordpress/i18n'; | ||
|
@@ -122,6 +126,7 @@ const SocialLinkEdit = ( { | |
// Use internal state instead of a ref to make sure that the component | ||
// re-renders when the popover's anchor updates. | ||
const [ popoverAnchor, setPopoverAnchor ] = useState( null ); | ||
const isContentOnlyMode = useBlockEditingMode() === 'contentOnly'; | ||
|
||
const IconComponent = getIconBySite( service ); | ||
const socialLinkName = getNameBySite( service ); | ||
|
@@ -141,6 +146,41 @@ const SocialLinkEdit = ( { | |
|
||
return ( | ||
<> | ||
{ isContentOnlyMode && showLabels && ( | ||
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. When using the block normally (not in contentOnly), it's possible to always edit the text in the inspector, and the text is used for screen readers, so I wonder if it's worth considering making it always show in content only mode too. 🤔 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. |
||
// Add an extra control to modify the label attribute when content only mode is active. | ||
// With content only mode active, the inspector is hidden, so users need another way | ||
// to edit this attribute. | ||
<BlockControls group="other"> | ||
<Dropdown | ||
popoverProps={ { position: 'bottom right' } } | ||
renderToggle={ ( { isOpen, onToggle } ) => ( | ||
<ToolbarButton | ||
onClick={ onToggle } | ||
aria-haspopup="true" | ||
aria-expanded={ isOpen } | ||
> | ||
{ __( 'Text' ) } | ||
</ToolbarButton> | ||
) } | ||
renderContent={ () => ( | ||
<TextControl | ||
__next40pxDefaultSize | ||
__nextHasNoMarginBottom | ||
className="wp-block-social-link__toolbar_content_text" | ||
label={ __( 'Text' ) } | ||
help={ __( | ||
'Provide a text label or use the default.' | ||
) } | ||
value={ label } | ||
onChange={ ( value ) => | ||
setAttributes( { label: value } ) | ||
} | ||
placeholder={ socialLinkName } | ||
/> | ||
Comment on lines
+166
to
+179
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. I'd consider it out of scope for this PR, but in usage it feels like the text should be editable inline (as RichText) when showLabels is active. It probably becomes more obvious in contentOnly mode. Maybe there are reasons it wasn't done like that 😄 |
||
) } | ||
/> | ||
</BlockControls> | ||
) } | ||
<InspectorControls> | ||
<PanelBody title={ __( 'Settings' ) }> | ||
<PanelRow> | ||
|
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.
So the button block has
rel
asrole: content
, but the image block doesn't, which is a bit of a quandry. I think it maybe makes sense for it to have acontent
role, as it's part of the url which is also content. If the user can edit a url, they may want to also setrel
andopenInNewTab
, so those have to becontentOnly
too.On the social link block, the rel can't be edited in contentOnly mode (it's in the inspector > advanced area), so perhaps it should be a follow-up issue to make that work in addition to adding the role.