Maybe take `document.activeElement` and check whether it lies under `.search-container`?