Reset data when the field is cleared

That’s not how that component works.

onRemove is called when the link is unlinked, via a button that only appears when certain conditions are met:

                { onRemove && value && ! isEditingLink && ! isCreatingPage && (
                    <Button
                        className="block-editor-link-control__unlink"
                        isDestructive
                        variant="link"
                        onClick={ onRemove }
                    >
                        { __( 'Unlink' ) }
                    </Button>
                ) }

https://github.com/WordPress/gutenberg/blob/6eac4a26f143c7378c3b39b5a83271538f36dfa9/packages/block-editor/src/components/link-control/index.js#L270

When an onRemove props is given, and the value is not empty, the link is not being edited, and you’re not currently using the control to create a page.

This isn’t so that you can erase or reset the value of the link, this is so that you can remove it completely. It is possible to have <a href="">, but unlink would remove the anchor completely, so it does not make sense for you to use.

Instead, to catch the blank URL use case, you should watch the change event

Leave a Comment