@@ -963,6 +963,49 @@ var NAVIGATION_KEYS = [
963
963
'Esc'
964
964
] ;
965
965
966
+ var FOCUS_COMPONENTS = [
967
+ 'assetlist' ,
968
+ 'button' ,
969
+ 'calendar' ,
970
+ 'card' ,
971
+ 'closebutton' ,
972
+ 'colorarea' ,
973
+ 'colorhandle' ,
974
+ 'colorslider' ,
975
+ 'colorwheel' ,
976
+ 'combobox' ,
977
+ 'menu' ,
978
+ 'picker' ,
979
+ 'pickerbutton' ,
980
+ 'rating' ,
981
+ 'sidenav' ,
982
+ 'slider' ,
983
+ 'steplist' ,
984
+ 'stepper' ,
985
+ 'table' ,
986
+ 'tag' ,
987
+ 'tooltip'
988
+ ] ;
989
+
990
+ var KEYBOARD_FOCUS_COMPONENTS = [
991
+ 'closebutton' ,
992
+ 'combobox' ,
993
+ 'datepicker' ,
994
+ 'pickerbutton' ,
995
+ 'sidenav' ,
996
+ 'stepper' ,
997
+ 'table' ,
998
+ ] ;
999
+
1000
+ // If pathname matches a component in the focus or keyboard focus arrays,
1001
+ // we know that component should get/is setup to handle the focus class
1002
+ function getsFocusClasses ( componentArray ) {
1003
+ return componentArray . some ( ( componentPath ) => {
1004
+ const currentPath = window . location . pathname ;
1005
+ return currentPath . includes ( componentPath ) ;
1006
+ } ) ;
1007
+ }
1008
+
966
1009
var keyboardFocus = false ;
967
1010
968
1011
function onKeydownHandler ( event ) {
@@ -971,25 +1014,26 @@ function onKeydownHandler(event) {
971
1014
}
972
1015
keyboardFocus = true ;
973
1016
974
- if ( document . activeElement &&
975
- document . activeElement !== document . body ) {
976
- document . activeElement . classList . add ( 'is-keyboardFocused' ) ;
1017
+ if ( getsFocusClasses ( KEYBOARD_FOCUS_COMPONENTS )
1018
+ && document . activeElement
1019
+ && document . activeElement !== document . body ) {
1020
+ document . activeElement . classList . add ( 'is-keyboardFocused' ) ;
977
1021
}
978
1022
}
979
1023
980
1024
function onMousedownHandler ( ) {
981
1025
keyboardFocus = false ;
982
1026
983
- if ( document . activeElement &&
984
- document . activeElement !== document . body ) {
985
- document . activeElement . classList . add ( 'is-focused' ) ;
1027
+ if ( getsFocusClasses ( FOCUS_COMPONENTS )
1028
+ && document . activeElement
1029
+ && document . activeElement !== document . body ) {
1030
+ document . activeElement . classList . add ( 'is-focused' ) ;
986
1031
}
987
1032
}
988
1033
989
- // Programmatic focus
990
1034
function onFocusHandler ( event ) {
991
1035
var classList = event . target . classList ;
992
- if ( classList && keyboardFocus ) {
1036
+ if ( classList && keyboardFocus && getsFocusClasses ( KEYBOARD_FOCUS_COMPONENTS ) ) {
993
1037
classList . add ( 'is-keyboardFocused' ) ;
994
1038
}
995
1039
}
0 commit comments