Skip to content

Commit

Permalink
Fix: Text Align block support inheritance
Browse files Browse the repository at this point in the history
  • Loading branch information
t-hamano committed May 2, 2024
1 parent ed67830 commit f1288ae
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/theme.json
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@
"fontWeight": true,
"letterSpacing": true,
"lineHeight": false,
"textAlign": false,
"textAlign": true,
"textColumns": false,
"textDecoration": true,
"textTransform": true,
Expand Down
25 changes: 23 additions & 2 deletions packages/block-editor/src/hooks/text-align.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { alignLeft, alignRight, alignCenter } from '@wordpress/icons';
*/
import { AlignmentControl, BlockControls } from '../components';
import { useBlockEditingMode } from '../components/block-editing-mode';
import { useSettings } from '../components/use-settings';
import { cleanEmptyObject, shouldSkipSerialization } from './utils';
import { TYPOGRAPHY_SUPPORT_KEY } from './typography';

Expand Down Expand Up @@ -70,11 +71,17 @@ function BlockEditTextAlignmentToolbarControlsPure( {
name: blockName,
setAttributes,
} ) {
const isDisabled = useIsTextAlignDisabled( blockName );
const blockEditingMode = useBlockEditingMode();

if ( isDisabled || blockEditingMode !== 'default' ) {
return null;
}

const validTextAlignments = getValidTextAlignments(
getBlockSupport( blockName, TEXT_ALIGN_SUPPORT_KEY )
);
const blockEditingMode = useBlockEditingMode();
if ( ! validTextAlignments.length || blockEditingMode !== 'default' ) {
if ( ! validTextAlignments.length ) {
return null;
}

Expand Down Expand Up @@ -176,3 +183,17 @@ export function addAssignedTextAlign( props, blockType, attributes ) {
}
return props;
}

/**
* Custom hook that checks if text-align settings have been disabled.
*
* @param {string} name The name of the block.
* @return {boolean} Whether setting is disabled.
*/
export function useIsTextAlignDisabled( { name: blockName } = {} ) {
const [ isEnabled ] = useSettings( TEXT_ALIGN_SUPPORT_KEY );
return (
! isEnabled ||
! hasBlockSupport( blockName, TEXT_ALIGN_SUPPORT_KEY, true )
);
}

0 comments on commit f1288ae

Please sign in to comment.