Skip to content

Commit dabc564

Browse files
committed
refactor: remove js for inputgroup and update focus out
add logic to remove classes on click
1 parent cd716ed commit dabc564

File tree

1 file changed

+17
-55
lines changed

1 file changed

+17
-55
lines changed

site/resources/js/enhancement.js

Lines changed: 17 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -188,61 +188,6 @@ governing permissions and limitations under the License.
188188
});
189189
})();
190190

191-
// Inputgroup
192-
(function () {
193-
function setFocus(inputgroup, focused, event) {
194-
var textfields = inputgroup.querySelectorAll(".spectrum-Textfield");
195-
var inputs = inputgroup.querySelectorAll(".spectrum-InputGroup-input");
196-
var input = inputs[0];
197-
var focusClass = event.target.classList.contains("is-keyboardFocused")
198-
? "is-keyboardFocused"
199-
: "is-focused";
200-
var pickerButton = inputgroup.querySelector(".spectrum-PickerButton");
201-
if (focused) {
202-
inputgroup.classList.add(focusClass);
203-
if (pickerButton) pickerButton.classList.add(focusClass);
204-
if (event.target.tagName !== "INPUT") {
205-
input.focus();
206-
}
207-
208-
Array.prototype.forEach.call(textfields, (textfield) => {
209-
textfield.classList.add(focusClass);
210-
});
211-
} else {
212-
if (pickerButton) pickerButton.classList.remove("is-keyboardFocused");
213-
if (pickerButton) pickerButton.classList.remove("is-focused");
214-
inputgroup.classList.remove("is-keyboardFocused");
215-
inputgroup.classList.remove("is-focused");
216-
217-
Array.prototype.forEach.call(textfields, (textfield) => {
218-
textfield.classList.remove("is-focused");
219-
textfield.classList.remove("is-keyboardFocused");
220-
});
221-
}
222-
}
223-
224-
document.addEventListener("focusin", function (event) {
225-
var inputgroup = event.target.closest(".spectrum-InputGroup");
226-
227-
if (event.target.closest(".spectrum-Menu")) {
228-
// Don't mess with focus on menuitems
229-
return;
230-
}
231-
232-
if (inputgroup) {
233-
setFocus(inputgroup, true, event);
234-
}
235-
});
236-
237-
document.addEventListener("focusout", function (event) {
238-
var inputgroup = event.target.closest(".spectrum-InputGroup");
239-
240-
if (inputgroup) {
241-
setFocus(inputgroup, false, event);
242-
}
243-
});
244-
})();
245-
246191
// Stepper
247192
(function () {
248193
function setFocus(stepper, input, focused) {
@@ -1026,6 +971,22 @@ function onKeydownHandler(event) {
1026971
}
1027972
}
1028973

974+
function onMousedownHandler() {
975+
keyboardFocus = false;
976+
var elements = document.getElementsByClassName('is-keyboardFocused');
977+
978+
for (var i = 0; i < elements.length; i++) {
979+
elements[i].classList.remove('is-keyboardFocused');
980+
}
981+
982+
if (document.activeElement &&
983+
document.activeElement !== document.body) {
984+
document.activeElement.classList.add('is-focused');
985+
}
986+
987+
988+
}
989+
1029990
function onFocusHandler(event) {
1030991
var classList = event.target.classList;
1031992
if (classList && keyboardFocus) {
@@ -1035,6 +996,7 @@ function onFocusHandler(event) {
1035996

1036997
window.addEventListener('keydown', onKeydownHandler, true);
1037998
window.addEventListener('focus', onFocusHandler, true);
999+
window.addEventListener('mousedown', onMousedownHandler, true);
10381000

10391001
animateCircleLoaders();
10401002
window.addEventListener("PageFastLoaded", enhanceAll);

0 commit comments

Comments
 (0)