-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Try: hide search block label when contained #35688
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ import { | |
__experimentalUseBorderProps as useBorderProps, | ||
__experimentalUnitControl as UnitControl, | ||
__experimentalUseColorProps as useColorProps, | ||
store as blockEditorStore, | ||
} from '@wordpress/block-editor'; | ||
import { | ||
ToolbarDropdownMenu, | ||
|
@@ -27,6 +28,8 @@ import { | |
__experimentalUseCustomUnits as useCustomUnits, | ||
} from '@wordpress/components'; | ||
import { useInstanceId } from '@wordpress/compose'; | ||
import { useSelect } from '@wordpress/data'; | ||
import { useRef } from '@wordpress/element'; | ||
import { Icon, search } from '@wordpress/icons'; | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
|
@@ -54,6 +57,8 @@ const DEFAULT_INNER_PADDING = '4px'; | |
|
||
export default function SearchEdit( { | ||
className, | ||
clientId, | ||
context, | ||
attributes, | ||
setAttributes, | ||
toggleSelection, | ||
|
@@ -76,6 +81,24 @@ export default function SearchEdit( { | |
const borderColor = style?.border?.color; | ||
const borderProps = useBorderProps( attributes ); | ||
|
||
const isNewBlock = useSelect( ( select ) => { | ||
const { wasBlockJustInserted } = select( blockEditorStore ); | ||
|
||
return wasBlockJustInserted( clientId ); | ||
} ); | ||
|
||
// Save a ref to this value, as it would become outdated | ||
// if any other blocks are added. | ||
const isNewBlockRef = useRef( isNewBlock ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure I understand why we need to use a ref here. Could you elaborate a bit on the problem? |
||
|
||
if ( | ||
'undefined' !== typeof context.searchBlockLabel && | ||
true === isNewBlockRef.current | ||
) { | ||
setAttributes( { showLabel: context.searchBlockLabel } ); | ||
isNewBlockRef.current = false; | ||
} | ||
|
||
// Check for old deprecated numerical border radius. Done as a separate | ||
// check so that a borderRadius style won't overwrite the longhand | ||
// per-corner styles. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't feel right to have this as an attribute of the Navigation block, because it's not configurable within Navigation. Block attributes should be related to the block itself, usually as settings that affect the block or its children, but in this case we're trying to configure an attribute that only exists in the child block. The parent block shouldn't really need to know about it.
There's a precedent for this type of situation in Page List, where we check for a block parent directly from its edit function. This seems a more appropriate approach for the search label, and has the advantage that we can make it apply to other parent blocks without having to add attributes and context to each individual block (though I'm not sure if in this case we'd want this behaviour when Search is nested in any other block apart from Navigation)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update: #31670 changed Page List to extrapolate its parent from context, but that works because Page List already uses context from Navigation, which Search doesn't.