Skip to content
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

More block: Match the design in the editor with the front, resolve the undo/redo issue #61131

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/block-library/src/editor.scss
Expand Up @@ -25,7 +25,6 @@
@import "./image/editor.scss";
@import "./latest-posts/editor.scss";
@import "./media-text/editor.scss";
@import "./more/editor.scss";
@import "./navigation/editor.scss";
@import "./navigation-link/editor.scss";
@import "./navigation-submenu/editor.scss";
Expand Down
48 changes: 21 additions & 27 deletions packages/block-library/src/more/edit.js
Expand Up @@ -3,41 +3,27 @@
*/
import { __ } from '@wordpress/i18n';
import { PanelBody, ToggleControl } from '@wordpress/components';
import { InspectorControls, useBlockProps } from '@wordpress/block-editor';
import { ENTER } from '@wordpress/keycodes';
import {
InspectorControls,
useBlockProps,
RichText,
} from '@wordpress/block-editor';
import { getDefaultBlockName, createBlock } from '@wordpress/blocks';

const DEFAULT_TEXT = __( 'Read more' );
const DEFAULT_TEXT = __( '(more…)' );

export default function MoreEdit( {
attributes: { customText, noTeaser },
insertBlocksAfter,
setAttributes,
} ) {
const onChangeInput = ( event ) => {
setAttributes( {
customText:
event.target.value !== '' ? event.target.value : undefined,
} );
};

const onKeyDown = ( { keyCode } ) => {
if ( keyCode === ENTER ) {
insertBlocksAfter( [ createBlock( getDefaultBlockName() ) ] );
}
};

const getHideExcerptHelp = ( checked ) =>
checked
? __( 'The excerpt is hidden.' )
: __( 'The excerpt is visible.' );

const toggleHideExcerpt = () => setAttributes( { noTeaser: ! noTeaser } );

const style = {
width: `${ ( customText ? customText : DEFAULT_TEXT ).length + 1.2 }em`,
};

return (
<>
<InspectorControls>
Expand All @@ -54,14 +40,22 @@ export default function MoreEdit( {
</PanelBody>
</InspectorControls>
<div { ...useBlockProps() }>
<input
aria-label={ __( '“Read more” link text' ) }
type="text"
value={ customText }
<RichText
tagName="a"
aria-label={ __( '“more” link text' ) }
value={ customText || DEFAULT_TEXT }
placeholder={ DEFAULT_TEXT }
onChange={ onChangeInput }
onKeyDown={ onKeyDown }
style={ style }
onChange={ ( value ) =>
setAttributes( { customText: value } )
}
allowedFormats={ [] }
carolinan marked this conversation as resolved.
Show resolved Hide resolved
withoutInteractiveFormatting
disableLineBreaks
__unstableOnSplitAtEnd={ () =>
insertBlocksAfter(
createBlock( getDefaultBlockName() )
)
}
/>
</div>
</>
Expand Down
46 changes: 0 additions & 46 deletions packages/block-library/src/more/editor.scss

This file was deleted.