Skip to content

Media: Reset search query parameter in URL when search input is cleared#11938

Open
NoumaanAhamed wants to merge 1 commit into
WordPress:trunkfrom
NoumaanAhamed:fix/65298-clear-media-search-on-refresh
Open

Media: Reset search query parameter in URL when search input is cleared#11938
NoumaanAhamed wants to merge 1 commit into
WordPress:trunkfrom
NoumaanAhamed:fix/65298-clear-media-search-on-refresh

Conversation

@NoumaanAhamed
Copy link
Copy Markdown

Summary

Fixes an issue where the searched text is not cleared from the Library search bar URL and input field after the text is removed and the page is refreshed.

Root Cause

In src/js/media/views/frame/manage.js, the input event throttle handler only invoked this.gridRouter.navigate() when val was truthy (non-empty):

if ( val ) {
    url += '?search=' + val;
    this.gridRouter.navigate( this.gridRouter.baseUrl( url ), { replace: true } );
}

When a user completely deleted the search query, val became an empty string (falsy). The router never received the navigate command, meaning the browser's address bar was left stuck on ?search=some-term. Refreshing the page then re-parsed the search parameter from the URL and filled the input field back up.

Solution

  • Adjusted the throttle input handler to call this.gridRouter.navigate() unconditionally. When the search box is cleared, it correctly navigates back to the base URL (upload.php), removing the search query parameter from the URL.

Changes

src/js/media/views/frame/manage.js

  • Updated the search input callback to always invoke gridRouter.navigate() so clearing the input resets the URL query string back to the base upload.php page.

Testing

Test Case Expected / Result Status
Typing search queries in Media Library Grid View Browser URL updates to include ?search=val ✅ Passed
Clearing search input completely Browser URL resets from upload.php?search=test to upload.php ✅ Passed
Refreshing page after clearing search Search input remains empty ✅ Passed

Trac ticket: https://core.trac.wordpress.org/ticket/65298

Use of AI Tools

AI assistance: No

@github-actions
Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props mohamedahamed.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions
Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant