@@ -14,37 +14,29 @@ export const useFocusTrap = (
1414 )
1515 return
1616
17- const focusableStreamButtons : HTMLButtonElement [ ] = Array . from (
17+ const focusableElements : HTMLButtonElement [ ] = Array . from (
1818 document . querySelectorAll (
1919 'button.streamfeed, .navigation, .footer, .remove-button'
2020 )
2121 )
2222
23- const focusableNavigationButtons = Array . from (
24- document . querySelectorAll ( '.navigation' )
25- )
26-
2723 if (
2824 ! document . activeElement ||
29- ! focusableStreamButtons . includes (
25+ ! focusableElements . includes (
3026 document . activeElement as HTMLButtonElement
3127 )
3228 )
3329 return
3430
3531 const firstFocusableElement =
36- focusableStreamButtons [ 0 ] as HTMLButtonElement
37-
38- const firstStreamFeedFocusableElement = focusableStreamButtons [
39- focusableNavigationButtons . length
40- ] as HTMLButtonElement
32+ focusableElements [ 0 ] as HTMLButtonElement
4133
42- const lastFocusableElement = focusableStreamButtons [
43- focusableStreamButtons . length - 1
34+ const lastFocusableElement = focusableElements [
35+ focusableElements . length - 1
4436 ] as HTMLButtonElement
4537
4638 const findCurrentButtonIndex = ( button : HTMLButtonElement ) => {
47- return focusableStreamButtons . indexOf ( button )
39+ return focusableElements . indexOf ( button )
4840 }
4941
5042 if ( e . shiftKey && e . key === 'Tab' ) {
@@ -56,76 +48,72 @@ export const useFocusTrap = (
5648 const currentIndex = findCurrentButtonIndex (
5749 document . activeElement as HTMLButtonElement
5850 )
59- focusableStreamButtons [ currentIndex - 1 ] ?. focus ( )
51+ focusableElements [ currentIndex - 1 ] ?. focus ( )
6052 }
6153 } else if ( ! e . shiftKey && e . key === 'Tab' ) {
6254 if ( document . activeElement === lastFocusableElement ) {
6355 e . preventDefault ( )
64- firstStreamFeedFocusableElement ?. focus ( )
56+ firstFocusableElement ?. focus ( )
6557 } else {
6658 e . preventDefault ( )
6759 const currentIndex = findCurrentButtonIndex (
6860 document . activeElement as HTMLButtonElement
6961 )
70- focusableStreamButtons [ currentIndex + 1 ] ?. focus ( )
62+ focusableElements [ currentIndex + 1 ] ?. focus ( )
7163 }
7264 } else if ( e . key === 'ArrowRight' ) {
73- const upcommingFocusableStreamButtons =
74- focusableStreamButtons . splice (
75- findCurrentButtonIndex (
76- document . activeElement as HTMLButtonElement
77- ) + 1
78- )
65+ const upcomingFocusableElements = focusableElements . splice (
66+ findCurrentButtonIndex (
67+ document . activeElement as HTMLButtonElement
68+ ) + 1
69+ )
7970
80- const previousFocusableStreamButtons =
81- focusableStreamButtons . splice (
82- 0 ,
83- findCurrentButtonIndex (
84- document . activeElement as HTMLButtonElement
85- )
71+ const previousFocusableElements = focusableElements . splice (
72+ 0 ,
73+ findCurrentButtonIndex (
74+ document . activeElement as HTMLButtonElement
8675 )
76+ )
8777
8878 const category = Array . from ( document . activeElement . classList ) [
8979 Array . from ( document . activeElement . classList ) . length - 1
9080 ]
9181
9282 const upcomingElement =
93- upcommingFocusableStreamButtons . filter ( ( item ) =>
83+ upcomingFocusableElements . filter ( ( item ) =>
9484 Array . from ( item . classList ) . includes ( category )
9585 ) [ 0 ] ??
96- previousFocusableStreamButtons . filter ( ( item ) =>
86+ previousFocusableElements . filter ( ( item ) =>
9787 Array . from ( item . classList ) . includes ( category )
9888 ) [ 0 ] ??
9989 undefined
10090
10191 upcomingElement && upcomingElement . focus ( )
10292 } else if ( e . key === 'ArrowLeft' ) {
103- const upcommingFocusableStreamButtons =
104- focusableStreamButtons . splice (
105- findCurrentButtonIndex (
106- document . activeElement as HTMLButtonElement
107- ) + 1
108- )
93+ const upcomingFocusableElements = focusableElements . splice (
94+ findCurrentButtonIndex (
95+ document . activeElement as HTMLButtonElement
96+ ) + 1
97+ )
10998
110- const previousFocusableStreamButtons =
111- focusableStreamButtons . splice (
112- 0 ,
113- findCurrentButtonIndex (
114- document . activeElement as HTMLButtonElement
115- )
99+ const previousFocusableElements = focusableElements . splice (
100+ 0 ,
101+ findCurrentButtonIndex (
102+ document . activeElement as HTMLButtonElement
116103 )
104+ )
117105
118106 const category = Array . from ( document . activeElement . classList ) [
119107 Array . from ( document . activeElement . classList ) . length - 1
120108 ]
121109
122110 const previousElement =
123- previousFocusableStreamButtons
111+ previousFocusableElements
124112 . reverse ( )
125113 . filter ( ( item ) =>
126114 Array . from ( item . classList ) . includes ( category )
127115 ) [ 0 ] ??
128- upcommingFocusableStreamButtons
116+ upcomingFocusableElements
129117 . reverse ( )
130118 . filter ( ( item ) =>
131119 Array . from ( item . classList ) . includes ( category )
0 commit comments