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

Home Link: Render Home text if there is no attribute label present #58387

Merged
merged 4 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 3 additions & 17 deletions packages/block-library/src/home-link/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,10 @@ import classnames from 'classnames';
/**
* WordPress dependencies
*/
import {
RichText,
useBlockProps,
store as blockEditorStore,
} from '@wordpress/block-editor';
import { RichText, useBlockProps } from '@wordpress/block-editor';
import { __ } from '@wordpress/i18n';
import { useSelect, useDispatch } from '@wordpress/data';
import { useSelect } from '@wordpress/data';
import { store as coreStore } from '@wordpress/core-data';
import { useEffect } from '@wordpress/element';

const preventDefault = ( event ) => event.preventDefault();

Expand All @@ -27,8 +22,6 @@ export default function HomeEdit( { attributes, setAttributes, context } ) {
homeUrl: getUnstableBase()?.home,
};
}, [] );
const { __unstableMarkNextChangeAsNotPersistent } =
useDispatch( blockEditorStore );

const { textColor, backgroundColor, style } = context;
const blockProps = useBlockProps( {
Expand All @@ -46,13 +39,6 @@ export default function HomeEdit( { attributes, setAttributes, context } ) {

const { label } = attributes;

useEffect( () => {
if ( label === undefined ) {
__unstableMarkNextChangeAsNotPersistent();
setAttributes( { label: __( 'Home' ) } );
}
}, [ label ] );

return (
<>
<div { ...blockProps }>
Expand All @@ -64,7 +50,7 @@ export default function HomeEdit( { attributes, setAttributes, context } ) {
<RichText
identifier="label"
className="wp-block-home-link__label"
value={ label }
value={ label || __( 'Home' ) }
tjcafferkey marked this conversation as resolved.
Show resolved Hide resolved
onChange={ ( labelValue ) => {
setAttributes( { label: labelValue } );
} }
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/home-link/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ function block_core_home_link_build_li_wrapper_attributes( $context ) {
*/
function render_block_core_home_link( $attributes, $content, $block ) {
if ( empty( $attributes['label'] ) ) {
return '';
$attributes['label'] = __( 'Home' );
tjcafferkey marked this conversation as resolved.
Show resolved Hide resolved
}
$aria_current = '';

Expand Down
Loading