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: Button Only style creates unnecessary undo history #53174

Open
t-hamano opened this issue Jul 31, 2023 · 2 comments · May be fixed by #52519
Open

Search Block: Button Only style creates unnecessary undo history #53174

t-hamano opened this issue Jul 31, 2023 · 2 comments · May be fixed by #52519
Labels
[Block] Search Affects the Search Block - used to display a search field [Feature] Block Validation/Deprecation Handling block validation to determine accuracy and deprecation [Feature] History History, undo, redo, revisions, autosave. [Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended

Comments

@t-hamano
Copy link
Contributor

t-hamano commented Jul 31, 2023

Description

When a search block is "Button only" style, clicking on the block will create an unnecessary undo history. This is because the attribute isSearchFieldHidden is updated via useEffect when isSelected prop is changed:

useEffect( () => {
if ( hasOnlyButton && ! isSelected ) {
setAttributes( {
isSearchFieldHidden: true,
} );
}
}, [ hasOnlyButton, isSelected, setAttributes ] );
// Show the search field when width changes.
useEffect( () => {
if ( ! hasOnlyButton || ! isSelected ) {
return;
}
setAttributes( {
isSearchFieldHidden: false,
} );
}, [ hasOnlyButton, isSelected, setAttributes, width ] );

This attribute is referenced only by the Edit component and appears to be used only to control the class name. In such cases, attributes should not be used and should be able to be determined by a combination of state or existing props.

Screenshots, screen recording, code snippet

8abf14b35da11f232f341dcbfd1978b9.mp4
@t-hamano t-hamano added [Type] Bug An existing feature does not function as intended Good First Issue An issue that's suitable for someone looking to contribute for the first time [Feature] Block Validation/Deprecation Handling block validation to determine accuracy and deprecation [Block] Search Affects the Search Block - used to display a search field labels Jul 31, 2023
@Mamaduka
Copy link
Member

Should be resolved via #52519.

@t-hamano
Copy link
Contributor Author

Oh, thanks for letting me know 😅

@t-hamano t-hamano linked a pull request Jul 31, 2023 that will close this issue
@Mamaduka Mamaduka added [Status] In Progress Tracking issues with work in progress and removed Good First Issue An issue that's suitable for someone looking to contribute for the first time labels Jul 31, 2023
@ellatrix ellatrix added the [Feature] History History, undo, redo, revisions, autosave. label Aug 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Search Affects the Search Block - used to display a search field [Feature] Block Validation/Deprecation Handling block validation to determine accuracy and deprecation [Feature] History History, undo, redo, revisions, autosave. [Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants