@wordpress/block-library
Version:
Block library for the WordPress editor.
24 lines (23 loc) • 1.17 kB
JavaScript
import { useSelect } from "@wordpress/data";
import { store } from "@wordpress/block-editor";
// packages/block-library/src/navigation-link/shared/use-enable-link-status-validation.js
/**
* Hook to determine if link status validation should be enabled.
*
* Link status validation is enabled when the root Navigation block is selected
* or any of its inner blocks are selected. This ensures validation only runs
* when the user is actively working within the navigation structure.
*
* @param {string} clientId The client ID of the current block.
* @return {boolean} Whether link status validation should be enabled.
*/
function useEnableLinkStatusValidation(clientId) {
return useSelect((select) => {
const { getSelectedBlockClientId, hasSelectedInnerBlock, getBlockParentsByBlockName } = select(store);
const selectedBlockId = getSelectedBlockClientId();
const rootNavigationId = getBlockParentsByBlockName(clientId, "core/navigation")[0];
return selectedBlockId === rootNavigationId || hasSelectedInnerBlock(rootNavigationId, true);
}, [clientId]);
}
export { useEnableLinkStatusValidation };
//# sourceMappingURL=use-enable-link-status-validation.mjs.map