From b8a14c2917529f1343459a832a05c1920c7a87d1 Mon Sep 17 00:00:00 2001 From: Jack Lukic Date: Fri, 23 Sep 2016 14:37:11 -0400 Subject: [PATCH] Fix bug in search related to DOM fragment removed from document --- RELEASE-NOTES.md | 1 + src/definitions/modules/search.js | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 8de4bbfd4..d4d1b1910 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -4,6 +4,7 @@ **Bugs** - **Search** - Fixed issue where pressing "up" key when no results selected would cause bottom result to be selected +- **Search** - Fixed issue where input may attempt to refocus when element is immediately removed from browser's DOM after a result is clicked **Enhancements** - **Checkbox** - Adds additional variables for styling toggle checkbox on/off state diff --git a/src/definitions/modules/search.js b/src/definitions/modules/search.js index 12ecb5597..cf5c84ad1 100644 --- a/src/definitions/modules/search.js +++ b/src/definitions/modules/search.js @@ -366,7 +366,14 @@ $.fn.search = function(parameters) { return $results.hasClass(className.hidden); }, inMessage: function(event) { - return (event.target && $(event.target).closest(selector.message).length > 0); + if(!event.target) { + return; + } + var + $target = $(event.target), + isInDOM = $.contains(document.documentElement, event.target) + ; + return (isInDOM && $target.closest(selector.message).length > 0); }, empty: function() { return ($results.html() === '');