Skip to content

Commit

Permalink
PostTitle: exit early when post type doesn't support titles (WordPres…
Browse files Browse the repository at this point in the history
…s#67086)

Unlinked contributors: mijan-xs.

Co-authored-by: jsnajdr <[email protected]>
Co-authored-by: Mamaduka <[email protected]>
Co-authored-by: t-hamano <[email protected]>
Co-authored-by: ndiego <[email protected]>
Co-authored-by: gziolo <[email protected]>
Co-authored-by: SantosGuillamot <[email protected]>
Co-authored-by: getdave <[email protected]>
Co-authored-by: youknowriad <[email protected]>
Co-authored-by: Tropicalista <[email protected]>
  • Loading branch information
10 people authored Nov 18, 2024
1 parent f6e6e45 commit d5e7bca
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions packages/editor/src/components/post-title/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import usePostTitleFocus from './use-post-title-focus';
import usePostTitle from './use-post-title';
import PostTypeSupportCheck from '../post-type-support-check';

function PostTitle( _, forwardedRef ) {
const PostTitle = forwardRef( ( _, forwardedRef ) => {
const { placeholder } = useSelect( ( select ) => {
const { getSettings } = select( blockEditorStore );
const { titlePlaceholder } = getSettings();
Expand Down Expand Up @@ -171,23 +171,21 @@ function PostTitle( _, forwardedRef ) {

return (
/* eslint-disable jsx-a11y/heading-has-content, jsx-a11y/no-noninteractive-element-to-interactive-role */
<PostTypeSupportCheck supportKeys="title">
<h1
ref={ useMergeRefs( [ richTextRef, focusRef ] ) }
contentEditable
className={ className }
aria-label={ decodedPlaceholder }
role="textbox"
aria-multiline="true"
onFocus={ onSelect }
onBlur={ onUnselect }
onKeyDown={ onKeyDown }
onPaste={ onPaste }
/>
</PostTypeSupportCheck>
<h1
ref={ useMergeRefs( [ richTextRef, focusRef ] ) }
contentEditable
className={ className }
aria-label={ decodedPlaceholder }
role="textbox"
aria-multiline="true"
onFocus={ onSelect }
onBlur={ onUnselect }
onKeyDown={ onKeyDown }
onPaste={ onPaste }
/>
/* eslint-enable jsx-a11y/heading-has-content, jsx-a11y/no-noninteractive-element-to-interactive-role */
);
}
} );

/**
* Renders the `PostTitle` component.
Expand All @@ -197,4 +195,8 @@ function PostTitle( _, forwardedRef ) {
*
* @return {Component} The rendered PostTitle component.
*/
export default forwardRef( PostTitle );
export default forwardRef( ( _, forwardedRef ) => (
<PostTypeSupportCheck supportKeys="title">
<PostTitle ref={ forwardedRef } />
</PostTypeSupportCheck>
) );

0 comments on commit d5e7bca

Please sign in to comment.