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

Allow pressing ENTER to change Reusable Block name #3993

Merged
Merged
Changes from all 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
53 changes: 33 additions & 20 deletions blocks/library/block/edit-panel/index.js
Expand Up @@ -3,65 +3,78 @@
*/
import { Button } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { keycodes } from '@wordpress/utils';

/**
* Internal dependencies
*/
import './style.scss';

const { ESCAPE } = keycodes;

function ReusableBlockEditPanel( props ) {
const { isEditing, title, isSaving, onEdit, onDetach, onChangeTitle, onSave, onCancel } = props;

return (
<div className="reusable-block-edit-panel">
{ ! isEditing && ! isSaving && [
<span key="info" className="reusable-block-edit-panel__info">
return [
( ! isEditing && ! isSaving ) && (
<div key="view" className="reusable-block-edit-panel">
<span className="reusable-block-edit-panel__info">
<b>{ title }</b>
</span>,
</span>
<Button
key="edit"
isLarge
className="reusable-block-edit-panel__button"
onClick={ onEdit }>
{ __( 'Edit' ) }
</Button>,
</Button>
<Button
key="detach"
isLarge
className="reusable-block-edit-panel__button"
onClick={ onDetach }>
{ __( 'Detach' ) }
</Button>,
] }
{ ( isEditing || isSaving ) && [
</Button>
</div>
),
( isEditing || isSaving ) && (
<form
key="edit"
className="reusable-block-edit-panel"
onSubmit={ ( event ) => {
event.preventDefault();
onSave();
} }>
<input
key="title"
type="text"
disabled={ isSaving }
className="reusable-block-edit-panel__title"
value={ title }
onChange={ ( event ) => onChangeTitle( event.target.value ) } />,
onChange={ ( event ) => onChangeTitle( event.target.value ) }
onKeyDown={ ( event ) => {
if ( event.keyCode === ESCAPE ) {
event.stopPropagation();
onCancel();
}
} } />
<Button
key="save"
type="submit"
isPrimary
isLarge
isBusy={ isSaving }
disabled={ ! title || isSaving }
className="reusable-block-edit-panel__button"
onClick={ onSave }>
{ __( 'Save' ) }
</Button>,
</Button>
<Button
key="cancel"
isLarge
disabled={ isSaving }
className="reusable-block-edit-panel__button"
onClick={ onCancel }>
{ __( 'Cancel' ) }
</Button>,
] }
</div>
);
</Button>
</form>
),
];
}

export default ReusableBlockEditPanel;
Expand Down