@@ -74,32 +74,27 @@ export class ListKeyboardDelegate<T> implements KeyboardDelegate {
74
74
return this . disabledBehavior === 'all' && ( item . props ?. isDisabled || this . disabledKeys . has ( item . key ) ) ;
75
75
}
76
76
77
- getNextKey ( key : Key ) {
78
- key = this . collection . getKeyAfter ( key ) ;
77
+ private findNextNonDisabled ( key : Key , getNext : ( key : Key ) => Key | null ) : Key | null {
79
78
while ( key != null ) {
80
79
let item = this . collection . getItem ( key ) ;
81
- if ( item . type === 'item' && ! this . isDisabled ( item ) ) {
80
+ if ( item ? .type === 'item' && ! this . isDisabled ( item ) ) {
82
81
return key ;
83
82
}
84
83
85
- key = this . collection . getKeyAfter ( key ) ;
84
+ key = getNext ( key ) ;
86
85
}
87
86
88
87
return null ;
89
88
}
90
89
90
+ getNextKey ( key : Key ) {
91
+ key = this . collection . getKeyAfter ( key ) ;
92
+ return this . findNextNonDisabled ( key , key => this . collection . getKeyAfter ( key ) ) ;
93
+ }
94
+
91
95
getPreviousKey ( key : Key ) {
92
96
key = this . collection . getKeyBefore ( key ) ;
93
- while ( key != null ) {
94
- let item = this . collection . getItem ( key ) ;
95
- if ( item . type === 'item' && ! this . isDisabled ( item ) ) {
96
- return key ;
97
- }
98
-
99
- key = this . collection . getKeyBefore ( key ) ;
100
- }
101
-
102
- return null ;
97
+ return this . findNextNonDisabled ( key , key => this . collection . getKeyBefore ( key ) ) ;
103
98
}
104
99
105
100
private findKey (
@@ -151,6 +146,14 @@ export class ListKeyboardDelegate<T> implements KeyboardDelegate {
151
146
}
152
147
153
148
getKeyRightOf ( key : Key ) {
149
+ // This is a temporary solution for CardView until we refactor useSelectableCollection.
150
+ // https://github.com/orgs/adobe/projects/19/views/32?pane=issue&itemId=77825042
151
+ let layoutDelegateMethod = this . direction === 'ltr' ? 'getKeyRightOf' : 'getKeyLeftOf' ;
152
+ if ( this . layoutDelegate [ layoutDelegateMethod ] ) {
153
+ key = this . layoutDelegate [ layoutDelegateMethod ] ( key ) ;
154
+ return this . findNextNonDisabled ( key , key => this . layoutDelegate [ layoutDelegateMethod ] ( key ) ) ;
155
+ }
156
+
154
157
if ( this . layout === 'grid' ) {
155
158
if ( this . orientation === 'vertical' ) {
156
159
return this . getNextColumn ( key , this . direction === 'rtl' ) ;
@@ -165,6 +168,12 @@ export class ListKeyboardDelegate<T> implements KeyboardDelegate {
165
168
}
166
169
167
170
getKeyLeftOf ( key : Key ) {
171
+ let layoutDelegateMethod = this . direction === 'ltr' ? 'getKeyLeftOf' : 'getKeyRightOf' ;
172
+ if ( this . layoutDelegate [ layoutDelegateMethod ] ) {
173
+ key = this . layoutDelegate [ layoutDelegateMethod ] ( key ) ;
174
+ return this . findNextNonDisabled ( key , key => this . layoutDelegate [ layoutDelegateMethod ] ( key ) ) ;
175
+ }
176
+
168
177
if ( this . layout === 'grid' ) {
169
178
if ( this . orientation === 'vertical' ) {
170
179
return this . getNextColumn ( key , this . direction === 'ltr' ) ;
@@ -180,30 +189,12 @@ export class ListKeyboardDelegate<T> implements KeyboardDelegate {
180
189
181
190
getFirstKey ( ) {
182
191
let key = this . collection . getFirstKey ( ) ;
183
- while ( key != null ) {
184
- let item = this . collection . getItem ( key ) ;
185
- if ( item ?. type === 'item' && ! this . isDisabled ( item ) ) {
186
- return key ;
187
- }
188
-
189
- key = this . collection . getKeyAfter ( key ) ;
190
- }
191
-
192
- return null ;
192
+ return this . findNextNonDisabled ( key , key => this . collection . getKeyAfter ( key ) ) ;
193
193
}
194
194
195
195
getLastKey ( ) {
196
196
let key = this . collection . getLastKey ( ) ;
197
- while ( key != null ) {
198
- let item = this . collection . getItem ( key ) ;
199
- if ( item . type === 'item' && ! this . isDisabled ( item ) ) {
200
- return key ;
201
- }
202
-
203
- key = this . collection . getKeyBefore ( key ) ;
204
- }
205
-
206
- return null ;
197
+ return this . findNextNonDisabled ( key , key => this . collection . getKeyBefore ( key ) ) ;
207
198
}
208
199
209
200
getKeyPageAbove ( key : Key ) {
@@ -280,7 +271,7 @@ export class ListKeyboardDelegate<T> implements KeyboardDelegate {
280
271
return key ;
281
272
}
282
273
283
- key = this . getKeyBelow ( key ) ;
274
+ key = this . getNextKey ( key ) ;
284
275
}
285
276
286
277
return null ;
0 commit comments