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

Create a new Required component #234

Open
3 tasks
fabiankaegy opened this issue Jun 28, 2023 · 1 comment
Open
3 tasks

Create a new Required component #234

fabiankaegy opened this issue Jun 28, 2023 · 1 comment
Assignees
Labels

Comments

@fabiankaegy
Copy link
Member

fabiankaegy commented Jun 28, 2023

It would be great to have a simple react component mark any component as required. It should work similar to the <Optional> component we already have in that you pass it a value that needs to exist in order for the condition to be met.

If the condition is not met, but the block is in the document, the editor should be locked from saving anything using the core APIs.

const { lockPostSaving, unlockPostSaving } = useDispatch( 'core/editor' );

// we can then lock / unlock the editor using these functions here
lockPostSaving( 'title-empty-lock' );
unlockPostSaving( 'title-empty-lock' );

Removing the block should also unlock the editor.

Additionally, it would be great to show the reason why the editor is locked in a notice when the user tries to save the post & also something in the PrePublishCheck to show all the required fields that are empty would be great.

Tasks

I think we should be able to use the clean up function of a useEffect hook to handle the unlocking on removal for us.

useEffect( () => {

    if (!condition) {
        // lock the editor
    } else {
        // unlock the editor
    }

    return () => {
        // unlock the editor
    }

}, [condition] )
@Sidsector9 Sidsector9 self-assigned this Jun 28, 2023
@Sidsector9
Copy link
Member

@fabiankaegy I'll pick this up

@fabiankaegy fabiankaegy linked a pull request Jul 28, 2023 that will close this issue
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants