mirror of
https://github.com/He4eT/tabswitcher.git
synced 2026-05-05 01:17:23 +00:00
pages/search: searchbox: handle Enter
This commit is contained in:
parent
5b88d3538a
commit
3e770a0d65
1 changed files with 30 additions and 0 deletions
|
|
@ -33,6 +33,13 @@ export const attachInputHandlers = (store) => {
|
||||||
const searchBox = document.getElementById('searchbox')
|
const searchBox = document.getElementById('searchbox')
|
||||||
const actionbox = document.getElementById('actionbox')
|
const actionbox = document.getElementById('actionbox')
|
||||||
|
|
||||||
|
/* Switch to tab */
|
||||||
|
const switchToTab = (tabId) => {
|
||||||
|
store.actions.goToTab(parseInt(tabId))
|
||||||
|
window.close()
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Arrow keys */
|
||||||
document.addEventListener('keydown', (e) => {
|
document.addEventListener('keydown', (e) => {
|
||||||
focusButtonsWithArrows(e, () => {
|
focusButtonsWithArrows(e, () => {
|
||||||
searchBox.focus()
|
searchBox.focus()
|
||||||
|
|
@ -43,8 +50,31 @@ export const attachInputHandlers = (store) => {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
/* Buttons */
|
||||||
|
document.addEventListener('click', (event) => {
|
||||||
|
if (event.target.classList.contains('tab')) {
|
||||||
|
const tabId = event.target.dataset.id
|
||||||
|
switchToTab(tabId)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
/* Searchbox*/
|
||||||
|
|
||||||
searchBox.addEventListener('input', (e) => {
|
searchBox.addEventListener('input', (e) => {
|
||||||
store.actions.updateQuery(e.target.value)
|
store.actions.updateQuery(e.target.value)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
searchBox.addEventListener('keydown', (e) => {
|
||||||
|
if (e.key === 'Enter') {
|
||||||
|
let visibleTabs = store.getCurrentState().results
|
||||||
|
if (visibleTabs.length === 1) {
|
||||||
|
const tabId = visibleTabs[0].obj.id
|
||||||
|
switchToTab(tabId)
|
||||||
|
} else {
|
||||||
|
actionbox.focus()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
/* Actionbox */
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue