Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 9 additions & 1 deletion packages/web-app-search/src/portals/SearchBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
@update:model-value="updateTerm"
@clear="onClear"
@click="showPreview"
@keyup.esc="hideOptionsDrop"
@keyup.esc="onKeyUpEsc"
@keyup.up="onKeyUpUp"
@keyup.down="onKeyUpDown"
@keyup.enter="onKeyUpEnter"
Expand Down Expand Up @@ -513,6 +513,14 @@ export default defineComponent({
onKeyUpDown() {
this.activePreviewIndex = this.findNextPreviewIndex(false)
},
onKeyUpEsc() {
if (this.term) {
this.updateTerm('')
return
}
const inputElement = this.$el.getElementsByTagName('input')[0] as HTMLElement
inputElement.blur()
Comment on lines +521 to +522
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather remove the blur and only keep clearing the term. It feels a bit weird to reset the focus on an input on esc. The blur works for GitHub because the search expands into this "overlay", which we don't have.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh no not that search button.. guess I should've been clearer. My reference point on esc unfocusing an input came from GDrive and this repo file finder:

img

I'll remove the blur later 🙂

},
getSearchResultForProvider(provider: SearchProvider) {
return this.searchResults.find(({ providerId }) => providerId === provider.id)?.result
},
Expand Down
16 changes: 16 additions & 0 deletions packages/web-app-search/tests/unit/portals/SearchBar.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,22 @@ describe('Search Bar portal component', () => {
wrapper.vm.onSearchShortcut(keyEvent)
textInput.remove()
})
test('clears search term on key press esc while input has focus', async () => {
const { wrapper } = getMountedWrapper()
wrapper.find(selectors.searchInput).setValue('albert')
await flushPromises()
wrapper.find(selectors.searchInput).trigger('keyup.esc')
expect(wrapper.vm.term).toBe('')
})
test('unfocuses search input on key press esc when search term is empty', () => {
const { wrapper } = getMountedWrapper()
const blurSpy = vi.spyOn(
wrapper.find(selectors.searchInput).element as HTMLInputElement,
'blur'
)
wrapper.find(selectors.searchInput).trigger('keyup.esc')
expect(blurSpy).toHaveBeenCalled()
})
})

function getMountedWrapper({
Expand Down