Skip to content

Commit

Permalink
Ensure all instances of the ToolsPanel uses the useToolsPanelDropdown…
Browse files Browse the repository at this point in the history
…MenuProps hook for placement (#68019)

Co-authored-by: im3dabasia <[email protected]>
Co-authored-by: fabiankaegy <[email protected]>
  • Loading branch information
3 people authored Dec 17, 2024
1 parent 6294216 commit 0fdd0a6
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/block-library/src/button/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import clsx from 'clsx';
import { NEW_TAB_TARGET, NOFOLLOW_REL } from './constants';
import { getUpdatedLinkAttributes } from './get-updated-link-attributes';
import removeAnchorTag from '../utils/remove-anchor-tag';
import { useToolsPanelDropdownMenuProps } from '../utils/hooks';

/**
* WordPress dependencies
Expand Down Expand Up @@ -115,10 +116,13 @@ function useEnter( props ) {
}

function WidthPanel( { selectedWidth, setAttributes } ) {
const dropdownMenuProps = useToolsPanelDropdownMenuProps();

return (
<ToolsPanel
label={ __( 'Settings' ) }
resetAll={ () => setAttributes( { width: undefined } ) }
dropdownMenuProps={ dropdownMenuProps }
>
<ToolsPanelItem
label={ __( 'Button width' ) }
Expand Down
7 changes: 7 additions & 0 deletions packages/block-library/src/column/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,24 @@ import {
import { useSelect, useDispatch } from '@wordpress/data';
import { sprintf, __ } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import { useToolsPanelDropdownMenuProps } from '../utils/hooks';

function ColumnInspectorControls( { width, setAttributes } ) {
const [ availableUnits ] = useSettings( 'spacing.units' );
const units = useCustomUnits( {
availableUnits: availableUnits || [ '%', 'px', 'em', 'rem', 'vw' ],
} );
const dropdownMenuProps = useToolsPanelDropdownMenuProps();
return (
<ToolsPanel
label={ __( 'Settings' ) }
resetAll={ () => {
setAttributes( { width: undefined } );
} }
dropdownMenuProps={ dropdownMenuProps }
>
<ToolsPanelItem
hasValue={ () => width !== undefined }
Expand Down
4 changes: 4 additions & 0 deletions packages/block-library/src/columns/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {
getRedistributedColumnWidths,
toWidthPrecision,
} from './utils';
import { useToolsPanelDropdownMenuProps } from '../utils/hooks';

const DEFAULT_BLOCK = {
name: 'core/column',
Expand Down Expand Up @@ -145,6 +146,8 @@ function ColumnInspectorControls( {
replaceInnerBlocks( clientId, innerBlocks );
}

const dropdownMenuProps = useToolsPanelDropdownMenuProps();

return (
<ToolsPanel
label={ __( 'Settings' ) }
Expand All @@ -154,6 +157,7 @@ function ColumnInspectorControls( {
isStackedOnMobile: true,
} );
} }
dropdownMenuProps={ dropdownMenuProps }
>
{ canInsertColumnBlock && (
<ToolsPanelItem
Expand Down
7 changes: 7 additions & 0 deletions packages/block-library/src/details/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ import {
} from '@wordpress/components';
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import { useToolsPanelDropdownMenuProps } from '../utils/hooks';

const TEMPLATE = [
[
'core/paragraph',
Expand All @@ -32,6 +37,7 @@ function DetailsEdit( { attributes, setAttributes, clientId } ) {
template: TEMPLATE,
__experimentalCaptureToolbars: true,
} );
const dropdownMenuProps = useToolsPanelDropdownMenuProps();

// Check if either the block or the inner blocks are selected.
const hasSelection = useSelect(
Expand All @@ -57,6 +63,7 @@ function DetailsEdit( { attributes, setAttributes, clientId } ) {
showContent: false,
} );
} }
dropdownMenuProps={ dropdownMenuProps }
>
<ToolsPanelItem
isShownByDefault
Expand Down
8 changes: 7 additions & 1 deletion packages/block-library/src/post-excerpt/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ import { useSelect } from '@wordpress/data';
/**
* Internal dependencies
*/
import { useCanEditEntity } from '../utils/hooks';
import {
useCanEditEntity,
useToolsPanelDropdownMenuProps,
} from '../utils/hooks';

const ELLIPSIS = '…';

Expand All @@ -46,6 +49,8 @@ export default function PostExcerptEditor( {
{ rendered: renderedExcerpt, protected: isProtected } = {},
] = useEntityProp( 'postType', postType, 'excerpt', postId );

const dropdownMenuProps = useToolsPanelDropdownMenuProps();

/**
* Check if the post type supports excerpts.
* Add an exception and return early for the "page" post type,
Expand Down Expand Up @@ -232,6 +237,7 @@ export default function PostExcerptEditor( {
excerptLength: 55,
} );
} }
dropdownMenuProps={ dropdownMenuProps }
>
<ToolsPanelItem
hasValue={ () => showMoreOnNewLine !== true }
Expand Down
3 changes: 3 additions & 0 deletions packages/block-library/src/social-link/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { keyboardReturn } from '@wordpress/icons';
* Internal dependencies
*/
import { getIconBySite, getNameBySite } from './social-list';
import { useToolsPanelDropdownMenuProps } from '../utils/hooks';

const SocialLinkURLPopover = ( {
url,
Expand Down Expand Up @@ -109,6 +110,7 @@ const SocialLinkEdit = ( {
clientId,
} ) => {
const { url, service, label = '', rel } = attributes;
const dropdownMenuProps = useToolsPanelDropdownMenuProps();
const {
showLabels,
iconColor,
Expand Down Expand Up @@ -200,6 +202,7 @@ const SocialLinkEdit = ( {
resetAll={ () => {
setAttributes( { label: undefined } );
} }
dropdownMenuProps={ dropdownMenuProps }
>
<ToolsPanelItem
isShownByDefault
Expand Down
8 changes: 8 additions & 0 deletions packages/block-library/src/social-links/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ import { __ } from '@wordpress/i18n';
import { check } from '@wordpress/icons';
import { useSelect } from '@wordpress/data';

/**
* Internal dependencies
*/
import { useToolsPanelDropdownMenuProps } from '../utils/hooks';

const sizeOptions = [
{ name: __( 'Small' ), value: 'has-small-icon-size' },
{ name: __( 'Normal' ), value: 'has-normal-icon-size' },
Expand Down Expand Up @@ -69,6 +74,8 @@ export function SocialLinksEdit( props ) {

const logosOnly = attributes.className?.includes( 'is-style-logos-only' );

const dropdownMenuProps = useToolsPanelDropdownMenuProps();

// Remove icon background color when logos only style is selected or
// restore it when any other style is selected.
const backgroundBackupRef = useRef( {} );
Expand Down Expand Up @@ -207,6 +214,7 @@ export function SocialLinksEdit( props ) {
showLabels: false,
} );
} }
dropdownMenuProps={ dropdownMenuProps }
>
<ToolsPanelItem
isShownByDefault
Expand Down
4 changes: 4 additions & 0 deletions packages/block-library/src/table/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import {
isEmptyTableSection,
} from './state';
import { Caption } from '../utils/caption';
import { useToolsPanelDropdownMenuProps } from '../utils/hooks';

const ALIGNMENT_CONTROLS = [
{
Expand Down Expand Up @@ -109,6 +110,8 @@ function TableEdit( {
const tableRef = useRef();
const [ hasTableCreated, setHasTableCreated ] = useState( false );

const dropdownMenuProps = useToolsPanelDropdownMenuProps();

/**
* Updates the initial column count used for table creation.
*
Expand Down Expand Up @@ -483,6 +486,7 @@ function TableEdit( {
foot: [],
} );
} }
dropdownMenuProps={ dropdownMenuProps }
>
<ToolsPanelItem
hasValue={ () => hasFixedLayout !== true }
Expand Down
7 changes: 7 additions & 0 deletions packages/block-library/src/tag-cloud/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ import {
import ServerSideRender from '@wordpress/server-side-render';
import { store as coreStore } from '@wordpress/core-data';

/**
* Internal dependencies
*/
import { useToolsPanelDropdownMenuProps } from '../utils/hooks';

/**
* Minimum number of tags a user can show using this block.
*
Expand Down Expand Up @@ -51,6 +56,7 @@ function TagCloudEdit( { attributes, setAttributes } ) {
} = attributes;

const [ availableUnits ] = useSettings( 'spacing.units' );
const dropdownMenuProps = useToolsPanelDropdownMenuProps();

// The `pt` unit is used as the default value and is therefore
// always considered an available unit.
Expand Down Expand Up @@ -129,6 +135,7 @@ function TagCloudEdit( { attributes, setAttributes } ) {
largestFontSize: '22pt',
} );
} }
dropdownMenuProps={ dropdownMenuProps }
>
<ToolsPanelItem
hasValue={ () => taxonomy !== 'post_tag' }
Expand Down

1 comment on commit 0fdd0a6

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in 0fdd0a6.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/12371593655
📝 Reported issues:

Please sign in to comment.