Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 131410b

Browse files
committed
docs(search): make sure the forward slash doesn't focus on search while on another input element
Closes #5969
1 parent ca6b7d0 commit 131410b

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

docs/src/templates/js/docs.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,19 @@ docsApp.directive.docsSearchInput = ['$document',function($document) {
145145
var ESCAPE_KEY_KEYCODE = 27,
146146
FORWARD_SLASH_KEYCODE = 191;
147147
angular.element($document[0].body).bind('keydown', function(event) {
148-
var input = element[0];
149-
if(event.keyCode == FORWARD_SLASH_KEYCODE && document.activeElement != input) {
150-
event.stopPropagation();
151-
event.preventDefault();
152-
input.focus();
148+
if(event.keyCode == FORWARD_SLASH_KEYCODE && document.activeElement) {
149+
var activeElement = document.activeElement;
150+
var activeTagName = activeElement.nodeName.toLowerCase();
151+
var hasInputFocus = activeTagName == 'input' || activeTagName == 'select' ||
152+
activeTagName == 'option' || activeTagName == 'textarea' ||
153+
activeElement.hasAttribute('contenteditable');
154+
if(!hasInputFocus) {
155+
event.stopPropagation();
156+
event.preventDefault();
157+
158+
var input = element[0];
159+
input.focus();
160+
}
153161
}
154162
});
155163

0 commit comments

Comments
 (0)