Skip to content

Commit 4d238b5

Browse files
mlogsdon18castastrophe
authored andcommitted
fix: update javascript for site to account for removal of focus-ring
1 parent 4448447 commit 4d238b5

File tree

1 file changed

+71
-3
lines changed

1 file changed

+71
-3
lines changed

site/resources/js/enhancement.js

Lines changed: 71 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ governing permissions and limitations under the License.
160160
// Textfield
161161
(function () {
162162
function setFocus(textfield, input, focused) {
163-
var focusClass = input.classList.contains("focus-ring")
163+
var focusClass = input.classList.contains("is-keyboardFocused")
164164
? "is-keyboardFocused"
165165
: "is-focused";
166166
if (focused) {
@@ -194,7 +194,7 @@ governing permissions and limitations under the License.
194194
var textfields = inputgroup.querySelectorAll(".spectrum-Textfield");
195195
var inputs = inputgroup.querySelectorAll(".spectrum-InputGroup-input");
196196
var input = inputs[0];
197-
var focusClass = event.target.classList.contains("focus-ring")
197+
var focusClass = event.target.classList.contains("is-keyboardFocused")
198198
? "is-keyboardFocused"
199199
: "is-focused";
200200
var pickerButton = inputgroup.querySelector(".spectrum-PickerButton");
@@ -246,7 +246,7 @@ governing permissions and limitations under the License.
246246
// Stepper
247247
(function () {
248248
function setFocus(stepper, input, focused) {
249-
var focusClass = input.classList.contains("focus-ring")
249+
var focusClass = input.classList.contains("is-keyboardFocused")
250250
? "is-keyboardFocused"
251251
: "is-focused";
252252
if (focused) {
@@ -989,6 +989,74 @@ function enhanceAll() {
989989
);
990990
}
991991

992+
// Focus Indicator Classes
993+
var NAVIGATION_KEYS = [
994+
'Tab',
995+
'ArrowUp',
996+
'ArrowRight',
997+
'ArrowDown',
998+
'ArrowLeft',
999+
'Home',
1000+
'End',
1001+
'PageUp',
1002+
'PageDown',
1003+
'Enter',
1004+
' ',
1005+
'Escape',
1006+
1007+
/* IE9 and Firefox < 37 */
1008+
'Up',
1009+
'Right',
1010+
'Down',
1011+
'Left',
1012+
'Esc'
1013+
];
1014+
var TEXT_INPUT_TYPES = [
1015+
'text',
1016+
'date',
1017+
'datetime-local',
1018+
'email',
1019+
'month',
1020+
'number',
1021+
'password',
1022+
'search',
1023+
'tel',
1024+
'time',
1025+
'url',
1026+
'week'
1027+
];
1028+
var keyboardFocus = false;
1029+
var elements = document.getElementsByClassName('is-keyboardFocused');
1030+
1031+
function onKeydownHandler(event) {
1032+
if (event.ctrlKey || event.altKey || event.metaKey || NAVIGATION_KEYS.indexOf(event.key) === -1) {
1033+
return;
1034+
}
1035+
keyboardFocus = true;
1036+
1037+
console.log(document.activeElement);
1038+
if (document.activeElement &&
1039+
document.activeElement !== document.body) {
1040+
document.activeElement.classList.add('is-keyboardFocused');
1041+
}
1042+
}
1043+
1044+
function onFocusHandler(event) {
1045+
var classList = event.target.classList;
1046+
if (classList && keyboardFocus) {
1047+
classList.add('is-keyboardFocused');
1048+
}
1049+
}
1050+
1051+
function onBlurHandler(event) {
1052+
var classList = event.target.classList;
1053+
classList && classList.remove('is-keyboardFocused');
1054+
}
1055+
1056+
window.addEventListener('keydown', onKeydownHandler, true);
1057+
window.addEventListener('focus', onFocusHandler, true);
1058+
window.addEventListener('blur', onBlurHandler, true);
1059+
9921060
animateCircleLoaders();
9931061
window.addEventListener("PageFastLoaded", enhanceAll);
9941062
window.addEventListener("DOMContentLoaded", enhanceAll);

0 commit comments

Comments
 (0)