Last active
January 10, 2021 06:12
-
-
Save artzub/10c13fd53a54888b0374f28e94408f82 to your computer and use it in GitHub Desktop.
Revisions
-
artzub revised this gist
Jan 10, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,7 +8,7 @@ const onFocus = (event) => { && current !== event.target ) { // skip anchors and areas without href and disabled items if (!checkHref(event.target) || event.target.disabled) { return; } current = event.target; -
artzub revised this gist
Jan 10, 2021 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,8 +7,8 @@ const onFocus = (event) => { event?.target?.tabIndex > -1 && current !== event.target ) { // skip anchors and areas without href and disabled items if (!checkHref(event.target) || element.disabled) { return; } current = event.target; -
artzub created this gist
Jan 10, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,38 @@ const checkHref = (element) => { const tag = element.tagName; return !(tag === 'A' || tag === 'AREA') || element.href; }; const onFocus = (event) => { if ( event?.target?.tabIndex > -1 && current !== event.target ) { // skip anchors and area without href if (!checkHref(event.target)) { return; } current = event.target; show(current); } }; const onBlur = (event) => { if (event?.target?.tabIndex > -1) { // find parent item that can be focusable current = current?.parentNode; while (current && current.tabIndex < 0) { current = current.parentNode; } if (current === document) { current = null; } // return focus to activeElement if (!current && document.activeElement && document.activeElement !== document.body) { current = document.activeElement; } if (current) { show(current); } else { hide(); } } };