alphagov / tech-docs-gem

Gem to distribute the tech docs project
https://tdt-documentation.london.cloudapps.digital/
MIT License
15 stars 38 forks source link

Keep search results when opening in new tabs #86

Closed ChrisBAshton closed 5 years ago

ChrisBAshton commented 5 years ago
Before After
new tab behaviour hides search result new tab behaviour keeps search results in place

Fixes an issue whereby if you 'CMD + Click' on search results, the search results are closed.

(This made it difficult to line up several useful looking results in new tabs; you'd either have to click on the search input again and re-trigger the search to re-show the results and enable opening a result in a new tab, or give up on tabs altogether and navigate in your current window).

The selector '.toc' contains the search input, the sidebar and the search results themselves. So calling 'hideResults' when '.toc a' is clicked meant that the search results were hidden the moment you click on a search result.

The selector '#toc' contains only the search input and sidebar - NOT the search results, so we can safely call 'hideResults' when '#toc a' is clicked. This means we can right-click on search results and open them in new tabs, without the results being cleared. It also means we haven't broken the existing behaviour (which is that if a navigation link in the sidebar is clicked, the search results should be hidden - as the search results are overlayed on top).

benthorner commented 5 years ago

I'm wondering (somewhat lazily) what the behaviour is when you simply click on a search result now? I guess it'll try to render the page, but will the search results still be shown on top?

ChrisBAshton commented 5 years ago

It works like a normal link, i.e. loads a new page (so the whole page is re-rendered, without search results).

ChrisBAshton commented 5 years ago

Thanks! Although I can't merge because "Only reviews by reviewers with write access count toward mergeability" (I also wasn't able to push up a branch, had to do a fork).

I wonder if the permissions are borked since the GitHub team deletion last week? 🤔

tijmenb commented 5 years ago

👍 I've added this repo to the GOV.UK team, so feel free to merge.

ChrisBAshton commented 5 years ago

Done 👍