microsoft-search / pnp-modern-search

Home of PnP Modern Search solutions, helping you move from classic to modern SharePoint and beyond
https://microsoft-search.github.io/pnp-modern-search
Other
386 stars 339 forks source link

Search box not clearing when search suggestions enabled #2643

Open Fringie opened 1 year ago

Fringie commented 1 year ago

Version used 4.8 Describe the bug When you empty/clear the search box, the search results webpart does not update with the default value if you have query suggestions enabled, if you disable query suggestions the functionality works. I think query suggestions disables the search box if there is no input which is causing the bug. Video example - https://www.youtube.com/watch?v=rBEOMPZMmOY

For example:

My webparts are configured to display everything via the * wildcard, so if there is nothing in the search box, everything should be displayed. But if i turn on query suggestions, it will stop working:

  1. I load up the page and all the search results are displayed due to the * wildcard
  2. I search for "divorce" because I'm looking for documents that use that keyword
  3. I delete "divorce" because I want to reset my search
  4. I expect the default search results to appear, but nothing changes. It appears that the onchange event isn't running

To Reproduce (one time setup)

  1. Create a page
  2. Add the search box webpart to the page
  3. Add the search results webpart to the page
  4. Configure the search results webpart with the following settings: Data source: SharePoint Search Use input query text: On Toggle the "Dynamic value" to
    • Connect to source: PnP - Search Box
    • PnP - Search Box's properties: Search query
    • Default value: *
  5. Configure the search box webpart with the following settings: Send the query to a new page: on Reset query on clear: on Enable query suggestions: on Enable custom search providers: toggle on SharePoint Static search suggestions
  6. Publish the page (debug steps)
  7. Search for anything i.e. the name of a document
  8. delete the search keywords
  9. At this point, the search should return to the default query because there is nothing in the search box, but it does not

Expected behavior I expect that the default search results will be displayed when the search box is empty.

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information): Windows 11. Chrome

Additional context This issue only happens when you try to use custom search suggestions, if you turn that feature off the functionality works as expected. Video example - https://www.youtube.com/watch?v=rBEOMPZMmOY

Fringie commented 1 year ago

I may have managed to resolve the issue on my local code. I'm still testing it but it seems to be working. The problem is the _onSearch event, I removed the if statement that stops it running if there's no queryText.

I don't know how to do pull requests on github

Edit: my fix worked. Seems to be no issues in my testing.

wobba commented 1 year ago

@Fringie here's one guide https://opensource.com/article/19/7/create-pull-request-github, and you should be able to find many on the interwebs.

Fringie commented 1 year ago

@Fringie here's one guide https://opensource.com/article/19/7/create-pull-request-github, and you should be able to find many on the interwebs.

Thank you, I will give it a try just now.

wobba commented 1 year ago

Tried on the dev branch and seems to reset ok when using "*" as the default query. Both with suggestions on and off.

If you have the search box and result web part on the same page, why do you enable "Send the query to a new page"? You can probably turn off "Reset query on clear" as well, as the static query takes effect.