File tree Expand file tree Collapse file tree 2 files changed +16
-6
lines changed
src/aria/private/behaviors Expand file tree Collapse file tree 2 files changed +16
-6
lines changed Original file line number Diff line number Diff line change @@ -55,19 +55,29 @@ export class ListNavigation<T extends ListNavigationItem> {
5555
5656 /** Navigates to the first item in the list. */
5757 first ( opts ?: { focusElement ?: boolean } ) : boolean {
58- const item = this . inputs . items ( ) . find ( i => this . inputs . focusManager . isFocusable ( i ) ) ;
58+ const item = this . getFirstFocusableItem ( ) ;
5959 return item ? this . goto ( item , opts ) : false ;
6060 }
6161
6262 /** Navigates to the last item in the list. */
6363 last ( opts ?: { focusElement ?: boolean } ) : boolean {
64- const items = this . inputs . items ( ) ;
64+ const item = this . getLastFocusableItem ( ) ;
65+ return item ? this . goto ( item , opts ) : false ;
66+ }
67+
68+ /** Gets the first focusable item from the given list of items. */
69+ getFirstFocusableItem ( items : T [ ] = this . inputs . items ( ) ) : T | undefined {
70+ return items . find ( i => this . inputs . focusManager . isFocusable ( i ) ) ;
71+ }
72+
73+ /** Gets the last focusable item from the given list of items. */
74+ getLastFocusableItem ( items : T [ ] = this . inputs . items ( ) ) : T | undefined {
6575 for ( let i = items . length - 1 ; i >= 0 ; i -- ) {
6676 if ( this . inputs . focusManager . isFocusable ( items [ i ] ) ) {
67- return this . goto ( items [ i ] , opts ) ;
77+ return items [ i ] ;
6878 }
6979 }
70- return false ;
80+ return ;
7181 }
7282
7383 /** Advances to the next or previous focusable item in the list based on the given delta. */
Original file line number Diff line number Diff line change @@ -161,8 +161,8 @@ export class List<T extends ListItem<V>, V> {
161161 }
162162
163163 /** Deselects the currently active item in the list. */
164- deselect ( ) {
165- this . selectionBehavior . deselect ( ) ;
164+ deselect ( item ?: T ) {
165+ this . selectionBehavior . deselect ( item ) ;
166166 }
167167
168168 /** Deselects all items in the list. */
You can’t perform that action at this time.
0 commit comments