diff --git a/packages/editor/src/components/post-status/index.js b/packages/editor/src/components/post-status/index.js index c2bf038875354d..441b37ffda743b 100644 --- a/packages/editor/src/components/post-status/index.js +++ b/packages/editor/src/components/post-status/index.js @@ -109,6 +109,7 @@ export default function PostStatus() { ); const { editEntityRecord } = useDispatch( coreStore ); const [ popoverAnchor, setPopoverAnchor ] = useState( null ); + const [ error, setError ] = useState( '' ); // Memoize popoverProps to avoid returning a new object every time. const popoverProps = useMemo( () => ( { @@ -163,6 +164,21 @@ export default function PostStatus() { } ); }; + const handlePassword = ( { password: newPassword = password } ) => { + if ( newPassword.length > 255 ) { + setError( __( 'Password cannot exceed 255 characters.' ) ); + } else { + setError( '' ); + updatePost( { password: newPassword } ); + } + }; + + const handleFocusOut = () => { + if ( password.trim() === '' ) { + handleTogglePassword( false ); + } + }; + return ( { canEdit ? ( @@ -171,6 +187,7 @@ export default function PostStatus() { contentClassName="editor-change-status__content" popoverProps={ popoverProps } focusOnMount + onToggle={ handleFocusOut } renderToggle={ ( { onToggle, isOpen } ) => (