diff --git a/packages/block-library/src/image/editor.scss b/packages/block-library/src/image/editor.scss index ded3768dfa7d38..d3fafcfcab4eca 100644 --- a/packages/block-library/src/image/editor.scss +++ b/packages/block-library/src/image/editor.scss @@ -181,3 +181,8 @@ figure.wp-block-image:not(.wp-block) { padding-right: 0; } } + +.wp-block-image__toolbar_content_textarea { + // Corresponds to the size of the textarea in the block inspector. + width: 250px; +} diff --git a/packages/block-library/src/image/image.js b/packages/block-library/src/image/image.js index f188f8eaaf3101..c941f9cc741047 100644 --- a/packages/block-library/src/image/image.js +++ b/packages/block-library/src/image/image.js @@ -10,6 +10,7 @@ import { TextControl, ToolbarButton, ToolbarGroup, + Dropdown, __experimentalToolsPanel as ToolsPanel, __experimentalToolsPanelItem as ToolsPanelItem, __experimentalUseCustomUnits as useCustomUnits, @@ -30,6 +31,7 @@ import { } from '@wordpress/block-editor'; import { useEffect, useMemo, useState, useRef } from '@wordpress/element'; import { __, _x, sprintf, isRTL } from '@wordpress/i18n'; +import { DOWN } from '@wordpress/keycodes'; import { getFilename } from '@wordpress/url'; import { switchToBlockType } from '@wordpress/blocks'; import { crop, overlayText, upload } from '@wordpress/icons'; @@ -177,6 +179,7 @@ export default function Image( { const [ externalBlob, setExternalBlob ] = useState(); const clientWidth = useClientWidth( containerRef, [ align ] ); const hasNonContentControls = blockEditingMode === 'default'; + const isContentOnlyMode = blockEditingMode === 'contentOnly'; const isResizable = allowResize && hasNonContentControls && @@ -514,6 +517,113 @@ export default function Image( { ) } + { isContentOnlyMode && ( + // Add some extra controls for content attributes when content only mode is active. + // With content only mode active, the inspector is hidden, so users need another way + // to edit these attributes. + + ( + { + if ( ! isOpen && event.keyCode === DOWN ) { + event.preventDefault(); + onToggle(); + } + } } + > + { _x( + 'Alt', + 'Alternative text for an image. Block toolbar label, a low character count is preferred.' + ) } + + ) } + renderContent={ () => ( + + { __( + 'Connected to a custom field' + ) } + + ) : ( + <> + + { __( + 'Describe the purpose of the image.' + ) } + +
+ { __( + 'Leave empty if decorative.' + ) } + + ) + } + __nextHasNoMarginBottom + /> + ) } + /> + ( + { + if ( ! isOpen && event.keyCode === DOWN ) { + event.preventDefault(); + onToggle(); + } + } } + > + { __( 'Title' ) } + + ) } + renderContent={ () => ( + + { __( + 'Connected to a custom field' + ) } + + ) : ( + <> + { __( + 'Describe the role of this image on the page.' + ) } + + { __( + '(Note: many devices and browsers do not display this text.)' + ) } + + + ) + } + /> + ) } + /> +
+ ) }