Skip to content

Commit

Permalink
Исправляет обработку перехода к поиску по клавише '/' (#1300)
Browse files Browse the repository at this point in the history
  • Loading branch information
vitya-ne authored Aug 30, 2024
1 parent 612ef08 commit 63a4223
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
7 changes: 7 additions & 0 deletions src/scripts/modules/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ class Header extends BaseComponent {
this.checkSticky()
}

document.addEventListener('keydown', (event) => {
// Firefox при нажатии Slash открывает свой поиск по странице
if (document.activeElement !== this.refs.input && (event.code === 'Slash' || event.code === 'NumpadDivide')) {
event.preventDefault()
}
})

if (this.isMainPage) {
document.addEventListener('keyup', (event) => {
if (event.code === 'Slash' || event.code === 'NumpadDivide') {
Expand Down
11 changes: 5 additions & 6 deletions src/scripts/modules/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,14 +276,13 @@ function init() {
event.preventDefault()
})

document.addEventListener('keydown', (event) => {
// Блокировка показа встроенного поиска в Firefox
if ((event.code === 'Slash' || event.code === 'NumpadDivide') && document.activeElement !== searchField) {
event.preventDefault()
document.addEventListener('keyup', (event) => {
if (event.code === 'Slash' && document.activeElement !== searchField) {
queueMicrotask(() => {
searchField.focus()
})
}
})

document.addEventListener('keyup', (event) => {
if (event.code === 'Enter' && document.activeElement === searchField) {
queueMicrotask(() => {
document.querySelector(SEARCH_HIT_LINK_SELECTOR)?.focus()
Expand Down

0 comments on commit 63a4223

Please sign in to comment.