Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
def5f01
add the filter and test
michalczaplinski Nov 13, 2024
2886139
remove
michalczaplinski Nov 14, 2024
c8b390b
Create instant search using `render_block_context` filter.
michalczaplinski Nov 14, 2024
00d90f3
Remove handling of inheritd query from `search/index.php`
michalczaplinski Nov 14, 2024
6214a72
Handle case when query is defined in block context in DB.
michalczaplinski Nov 14, 2024
cbb469c
Guard against queryId being undefined in block context
michalczaplinski Nov 18, 2024
571d851
Fix the e2e test suite
michalczaplinski Nov 19, 2024
f922695
Move the filter to `/experimental` folder.
michalczaplinski Nov 20, 2024
c1eb9de
Add an e2e test case if query.search attribute is present
michalczaplinski Nov 20, 2024
970908f
Remove the search button when instant search is enabled
michalczaplinski Nov 20, 2024
98a0e23
Use the query_loop_block_query_vars filter
michalczaplinski Nov 21, 2024
64d68da
Do not delete pages and templates in e2e tests
michalczaplinski Nov 21, 2024
2a89b6a
Set the pageId for Multiple Queries tests
michalczaplinski Nov 21, 2024
7cad091
Fix the block name via metadata when Seach is instant.
michalczaplinski Nov 25, 2024
7e1e27b
Remove stuff related to Default queries from `view.js`
michalczaplinski Nov 26, 2024
b4d16f7
Add `attributes.metadata` to useEffect dependency array
michalczaplinski Nov 27, 2024
9095031
Remove `attributes.metadata` & label from dependency array
michalczaplinski Nov 29, 2024
ca253ef
Don't use `Promise.withResolvers()` in search block's view.js
michalczaplinski Dec 3, 2024
cf27754
Explain why we disable the react-hooks/exhaustive-deps lint
michalczaplinski Nov 29, 2024
a5c2b17
Undo formatting changes
michalczaplinski Nov 29, 2024
2fc61fd
Create instant search using `render_block_context` filter.
michalczaplinski Nov 14, 2024
5846998
Undo formatting changes
michalczaplinski Nov 29, 2024
4b2f66d
Remove the `render_block_context` filter from blocks.php
michalczaplinski Dec 5, 2024
1bf3f4b
Merge branch 'trunk' into feature/search-query-using-vars-filter
michalczaplinski Dec 9, 2024
ee2739d
Fix how directives are added to the form in the search block.
michalczaplinski Dec 11, 2024
806c330
Add e2e test for renaming Search block to "Instant Search" in the Lis…
michalczaplinski Dec 12, 2024
2e7432d
Appease the PHP formatter
michalczaplinski Dec 12, 2024
049fc67
Merge remote-tracking branch 'origin/trunk' into feature/search-query…
michalczaplinski Dec 12, 2024
95a9647
Update lib/experimental/blocks.php
michalczaplinski Dec 12, 2024
ac750ae
Update the comment in Search block to clarify when Instant Search is …
michalczaplinski Dec 12, 2024
de34a1e
Merge branch 'trunk' into feature/search-query-using-vars-filter
michalczaplinski Dec 13, 2024
4ce8096
Merge branch 'trunk' into feature/search-query-using-vars-filter
michalczaplinski Dec 18, 2024
b1c11f4
Update e2e tests for Instant Search to verify block renaming in Inspe…
michalczaplinski Dec 18, 2024
3dd53b9
Simplify the logic for enqueuing `@wordpress/block-library/search/view`
michalczaplinski Dec 19, 2024
bdaaf2e
Put back the empty() calls that were erroneouslyreplaced with ternaries
michalczaplinski Dec 19, 2024
97b3c84
Only hide the search button if BOTH enhanced pagination & instant sea…
michalczaplinski Dec 19, 2024
2095706
Format PHP
michalczaplinski Dec 19, 2024
77e86d2
Removed redundant getter for `isSearchInputVisible` and simplified th…
michalczaplinski Dec 19, 2024
4fcb01b
Merge branch 'trunk' into feature/search-query-using-vars-filter
michalczaplinski Dec 19, 2024
15b80fe
Check presence of instant search experiment in addition to the checki…
michalczaplinski Dec 30, 2024
dd42f50
Simplify instant search and enhanced pagination checks.
michalczaplinski Jan 6, 2025
1d70719
Update comments
michalczaplinski Jan 6, 2025
e0dd93b
Refactor Instant Search tests to verify toolbar button visibility whe…
michalczaplinski Jan 6, 2025
2db363a
Update Search block label in ListView when it's an Instant Search
michalczaplinski Jan 6, 2025
c20526f
Enhance Instant Search e2e tests to verify List View label updates
michalczaplinski Jan 6, 2025
6b975c4
Update Search block label to default to 'Search' when no custom name …
michalczaplinski Jan 6, 2025
7ca6d27
Remove default label attribute from Search block in Instant Search tests
michalczaplinski Jan 6, 2025
af14ef2
Merge branch 'trunk' into feature/search-query-using-vars-filter
michalczaplinski Apr 24, 2025
82626f8
Update __experimentalLabel to conditionally display block label in li…
michalczaplinski Apr 24, 2025
9d6ccda
PHPCBF formatting
michalczaplinski Apr 25, 2025
a513013
Merge branch 'trunk' into feature/search-query-using-vars-filter
t-hamano Jun 30, 2025
da87ca8
Merge branch 'trunk' into feature/search-query-using-vars-filter
t-hamano Sep 26, 2025
9fe9df5
Remove custom playwright util
t-hamano Sep 26, 2025
5ecf480
e2e: Resttore original posts_per_page setting
t-hamano Sep 26, 2025
634e852
e2e: Use accesible selector
t-hamano Sep 26, 2025
25fb7f7
Refactor all E2E tests
t-hamano Sep 26, 2025
05938e0
Stabilize feature
t-hamano Sep 26, 2025
55e23aa
Remove unnecessary changes
t-hamano Sep 26, 2025
88176a6
Stabilize feature
t-hamano Sep 26, 2025
68edc65
Revert "Stabilize feature"
t-hamano Sep 26, 2025
0e7633b
Revert "Stabilize feature"
t-hamano Sep 26, 2025
3a780e9
Remove slashes from a URL string
t-hamano Sep 26, 2025
11ebed9
Debounce input event
t-hamano Sep 26, 2025
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
33 changes: 33 additions & 0 deletions lib/experimental/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,36 @@ function gutenberg_block_core_form_view_script_module( $data ) {
'script_module_data_@wordpress/block-library/form/view',
'gutenberg_block_core_form_view_script_module'
);

/**
* Passes the search query param to Query Loop blocks, if the instant search experiment is enabled.
*
* @param array $query The query variables.
* @param WP_Block $block Block instance.
* @return array Modified query variables.
*/
function gutenberg_block_core_query_add_url_filtering( $query, $block ) {
// Check if the instant search gutenberg experiment is enabled
$gutenberg_experiments = get_option( 'gutenberg-experiments' );
$instant_search_enabled = $gutenberg_experiments && array_key_exists( 'gutenberg-search-query-block', $gutenberg_experiments );
if ( ! $instant_search_enabled ) {
return $query;
}

// Make sure block has a queryId
if ( empty( $block->context['queryId'] ) ) {
return $query;
}

// Get the search key from the URL
$search_key = 'instant-search-' . $block->context['queryId'];
if ( ! isset( $_GET[ $search_key ] ) ) {
return $query;
}

// Add the search parameter to the query
$query['s'] = sanitize_text_field( $_GET[ $search_key ] );

return $query;
}
add_filter( 'query_loop_block_query_vars', 'gutenberg_block_core_query_add_url_filtering', 10, 2 );
6 changes: 6 additions & 0 deletions lib/experimental/editor-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ function gutenberg_enable_experiments() {
if ( gutenberg_is_experiment_enabled( 'gutenberg-no-tinymce' ) ) {
wp_add_inline_script( 'wp-block-library', 'window.__experimentalDisableTinymce = true', 'before' );
}
if ( gutenberg_is_experiment_enabled( 'gutenberg-full-page-client-side-navigation' ) ) {
wp_add_inline_script( 'wp-block-library', 'window.__experimentalFullPageClientSideNavigation = true', 'before' );
}
if ( $gutenberg_experiments && array_key_exists( 'gutenberg-search-query-block', $gutenberg_experiments ) ) {
wp_add_inline_script( 'wp-block-editor', 'window.__experimentalEnableSearchQueryBlock = true', 'before' );
}
if ( $gutenberg_experiments && array_key_exists( 'gutenberg-block-comment', $gutenberg_experiments ) ) {
wp_add_inline_script( 'wp-block-editor', 'window.__experimentalEnableBlockComment = true', 'before' );
}
Expand Down
12 changes: 12 additions & 0 deletions lib/experiments-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,18 @@ function gutenberg_initialize_experiments_settings() {
)
);

add_settings_field(
'gutenberg-search-query-block',
__( 'Instant Search and Query Block', 'gutenberg' ),
'gutenberg_display_experiment_field',
'gutenberg-experiments',
'gutenberg_experiments_section',
array(
'label' => __( 'Enable instant search functionality of the Search + Query blocks.', 'gutenberg' ),
'id' => 'gutenberg-search-query-block',
)
);

register_setting(
'gutenberg-experiments',
'gutenberg-experiments'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,12 @@ export default function useBlockDisplayTitle( {
}

const attributes = getBlockAttributes( clientId );
const label = getBlockLabel( blockType, attributes, context );
const label = getBlockLabel(
blockType,
attributes,
context,
clientId
);
// If the label is defined we prioritize it over a possible block variation title match.
if ( label !== blockType.title ) {
return label;
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/search/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"default": false
}
},
"usesContext": [ "enhancedPagination", "query", "queryId" ],
"supports": {
"align": [ "left", "center", "right" ],
"color": {
Expand Down
128 changes: 74 additions & 54 deletions packages/block-library/src/search/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export default function SearchEdit( {
toggleSelection,
isSelected,
clientId,
context,
} ) {
const {
label,
Expand All @@ -74,6 +75,13 @@ export default function SearchEdit( {
style,
} = attributes;

// Check if the block is inside a Query block with enhanced pagination enabled
// and if the `__experimentalEnableSearchQueryBlock` flag is enabled.
const hasInstantSearch = !! (
context?.enhancedPagination &&
window?.__experimentalEnableSearchQueryBlock
);

const wasJustInsertedIntoNavigationBlock = useSelect(
( select ) => {
const { getBlockParentsByBlockName, wasBlockJustInserted } =
Expand Down Expand Up @@ -377,54 +385,60 @@ export default function SearchEdit( {
}
/>
</ToolsPanelItem>
<ToolsPanelItem
hasValue={ () => buttonPosition !== 'button-outside' }
label={ __( 'Button position' ) }
onDeselect={ () => {
setAttributes( {
buttonPosition: 'button-outside',
isSearchFieldHidden: false,
} );
} }
isShownByDefault
>
<SelectControl
value={ buttonPosition }
__next40pxDefaultSize
__nextHasNoMarginBottom
label={ __( 'Button position' ) }
onChange={ ( value ) => {
setAttributes( {
buttonPosition: value,
isSearchFieldHidden:
value === 'button-only',
} );
} }
options={ buttonPositionControls }
/>
</ToolsPanelItem>
{ buttonPosition !== 'no-button' && (
<ToolsPanelItem
hasValue={ () => !! buttonUseIcon }
label={ __( 'Use button with icon' ) }
onDeselect={ () => {
setAttributes( {
buttonUseIcon: false,
} );
} }
isShownByDefault
>
<ToggleControl
__nextHasNoMarginBottom
checked={ buttonUseIcon }
label={ __( 'Use button with icon' ) }
onChange={ ( value ) =>
setAttributes( {
buttonUseIcon: value,
} )
{ ! hasInstantSearch && (
<>
<ToolsPanelItem
hasValue={ () =>
buttonPosition !== 'button-outside'
}
/>
</ToolsPanelItem>
label={ __( 'Button position' ) }
onDeselect={ () => {
setAttributes( {
buttonPosition: 'button-outside',
isSearchFieldHidden: false,
} );
} }
isShownByDefault
>
<SelectControl
value={ buttonPosition }
__next40pxDefaultSize
__nextHasNoMarginBottom
label={ __( 'Button position' ) }
onChange={ ( value ) => {
setAttributes( {
buttonPosition: value,
isSearchFieldHidden:
value === 'button-only',
} );
} }
options={ buttonPositionControls }
/>
</ToolsPanelItem>
{ buttonPosition !== 'no-button' && (
<ToolsPanelItem
hasValue={ () => !! buttonUseIcon }
label={ __( 'Use button with icon' ) }
onDeselect={ () => {
setAttributes( {
buttonUseIcon: false,
} );
} }
isShownByDefault
>
<ToggleControl
__nextHasNoMarginBottom
checked={ buttonUseIcon }
label={ __( 'Use button with icon' ) }
onChange={ ( value ) =>
setAttributes( {
buttonUseIcon: value,
} )
}
/>
</ToolsPanelItem>
) }
</>
) }
<ToolsPanelItem
hasValue={ () => !! width }
Expand Down Expand Up @@ -641,16 +655,22 @@ export default function SearchEdit( {
} }
showHandle={ isSelected }
>
{ ( isButtonPositionInside ||
isButtonPositionOutside ||
hasOnlyButton ) && (
{ hasInstantSearch ? (
renderTextField()
) : (
<>
{ renderTextField() }
{ renderButton() }
{ ( isButtonPositionInside ||
isButtonPositionOutside ||
hasOnlyButton ) && (
<>
{ renderTextField() }
{ renderButton() }
</>
) }

{ hasNoButton && renderTextField() }
</>
) }

{ hasNoButton && renderTextField() }
</ResizableBox>
</div>
);
Expand Down
44 changes: 43 additions & 1 deletion packages/block-library/src/search/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { __, sprintf } from '@wordpress/i18n';
import { search as icon } from '@wordpress/icons';
import { select } from '@wordpress/data';
import { store as blockEditorStore } from '@wordpress/block-editor';

/**
* Internal dependencies
Expand All @@ -18,6 +20,46 @@ export { metadata, name };

export const settings = {
icon,
__experimentalLabel( attributes, { clientId, context } ) {
// Only show the label in list view.
if ( context !== 'list-view' ) {
return;
}

// Check if the block is inside a Query Loop block.
const queryLoopBlockIds = select(
blockEditorStore
).getBlockParentsByBlockName( clientId, 'core/query' );

const blockTitle = __( 'Search' );
const customName = attributes?.metadata?.name;

// If the block is not inside a Query Loop block, return the block label.
if ( ! queryLoopBlockIds.length ) {
return customName || blockTitle;
}

const queryLoopBlock = select( blockEditorStore ).getBlock(
queryLoopBlockIds[ 0 ]
);

// Check if the Query Loop block has enhanced pagination enabled and
// if the `__experimentalEnableSearchQueryBlock` flag is enabled.
const hasInstantSearch = !! (
queryLoopBlock?.attributes?.enhancedPagination &&
window?.__experimentalEnableSearchQueryBlock
);

if ( ! hasInstantSearch ) {
return customName || blockTitle;
}

return sprintf(
/* translators: %s: The block label */
__( '%s (Instant search enabled)' ),
customName || blockTitle
);
},
example: {
attributes: { buttonText: __( 'Search' ), label: __( 'Search' ) },
viewportWidth: 400,
Expand Down
Loading
Loading