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

Search block: Remove unnecessary useEffects #52519

Open
wants to merge 3 commits into
base: trunk
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Remove attribute
  • Loading branch information
scruffian committed Aug 1, 2023
commit 739289e3ea05aae007a26a354a35ccc5538e252c
19 changes: 5 additions & 14 deletions packages/block-library/src/search/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
useSetting,
} from '@wordpress/block-editor';
import { useDispatch, useSelect } from '@wordpress/data';
import { useEffect, useRef } from '@wordpress/element';
import { useEffect, useRef, useState } from '@wordpress/element';
import {
ToolbarDropdownMenu,
ToolbarGroup,
Expand Down Expand Up @@ -80,10 +80,8 @@ export default function SearchEdit( {
buttonPosition,
buttonUseIcon,
buttonBehavior,
isSearchFieldHidden,
style,
} = attributes;

const insertedInNavigationBlock = useSelect(
( select ) => {
const { getBlockParentsByBlockName, wasBlockJustInserted } =
Expand Down Expand Up @@ -137,16 +135,15 @@ export default function SearchEdit( {
const hasOnlyButton = 'button-only' === buttonPosition;
const searchFieldRef = useRef();
const buttonRef = useRef();
const [ isSearchFieldHidden, setIsSearchFieldHidden ] = useState(
hasOnlyButton && ! isSelected
);

const units = useCustomUnits( {
availableUnits: [ '%', 'px' ],
defaultValues: { '%': PC_WIDTH_DEFAULT, px: PX_WIDTH_DEFAULT },
} );

setAttributes( {
isSearchFieldHidden: hasOnlyButton && ! isSelected,
} );

const getBlockClassNames = () => {
return classnames(
className,
Expand Down Expand Up @@ -182,7 +179,6 @@ export default function SearchEdit( {
onClick: () => {
setAttributes( {
buttonPosition: 'button-outside',
isSearchFieldHidden: false,
} );
},
},
Expand All @@ -194,7 +190,6 @@ export default function SearchEdit( {
onClick: () => {
setAttributes( {
buttonPosition: 'button-inside',
isSearchFieldHidden: false,
} );
},
},
Expand All @@ -206,7 +201,6 @@ export default function SearchEdit( {
onClick: () => {
setAttributes( {
buttonPosition: 'no-button',
isSearchFieldHidden: false,
} );
},
},
Expand All @@ -218,7 +212,6 @@ export default function SearchEdit( {
onClick: () => {
setAttributes( {
buttonPosition: 'button-only',
isSearchFieldHidden: true,
} );
},
},
Expand Down Expand Up @@ -303,9 +296,7 @@ export default function SearchEdit( {
};
const handleButtonClick = () => {
if ( hasOnlyButton && BUTTON_BEHAVIOR_EXPAND === buttonBehavior ) {
setAttributes( {
isSearchFieldHidden: ! isSearchFieldHidden,
} );
setIsSearchFieldHidden( ! isSearchFieldHidden );
}
};

Expand Down