@@ -76,6 +76,9 @@ export class ListboxPattern<V> {
76
76
/** Whether the listbox selection follows focus. */
77
77
followFocus = computed ( ( ) => this . inputs . selectionMode ( ) === 'follow' ) ;
78
78
79
+ /** Whether the listbox should wrap. */
80
+ wrap = signal ( true ) ;
81
+
79
82
/** The key used to navigate to the previous item in the list. */
80
83
prevKey = computed ( ( ) => {
81
84
if ( this . inputs . orientation ( ) === 'vertical' ) {
@@ -137,22 +140,26 @@ export class ListboxPattern<V> {
137
140
// index where the shift key begins being held down. Note that this is very different from
138
141
// selecting from the current active or focused index.
139
142
manager
140
- . on ( Modifier . Shift , 'Shift' , ( ) => this . shiftAnchorIndex . set ( this . inputs . activeIndex ( ) ) )
143
+ . on ( Modifier . Any , 'Shift' , ( ) => this . shiftAnchorIndex . set ( this . inputs . activeIndex ( ) ) )
141
144
. on ( Modifier . Shift , this . prevKey , ( ) => {
142
145
if ( this . inputs . activeIndex ( ) === this . shiftAnchorIndex ( ) ) {
143
146
this . selection . select ( ) ;
144
147
} else if ( this . inputs . activeIndex ( ) > this . shiftAnchorIndex ( ) ) {
145
148
this . selection . deselect ( ) ;
146
149
}
150
+ this . wrap . set ( false ) ;
147
151
this . prev ( { select : true } ) ;
152
+ this . wrap . set ( true ) ;
148
153
} )
149
154
. on ( Modifier . Shift , this . nextKey , ( ) => {
150
155
if ( this . inputs . activeIndex ( ) === this . shiftAnchorIndex ( ) ) {
151
156
this . selection . select ( ) ;
152
157
} else if ( this . inputs . activeIndex ( ) < this . shiftAnchorIndex ( ) ) {
153
158
this . selection . deselect ( ) ;
154
159
}
160
+ this . wrap . set ( false ) ;
155
161
this . next ( { select : true } ) ;
162
+ this . wrap . set ( true ) ;
156
163
} ) ;
157
164
158
165
manager
@@ -230,7 +237,10 @@ export class ListboxPattern<V> {
230
237
this . orientation = inputs . orientation ;
231
238
this . multi = inputs . multi ;
232
239
233
- this . navigation = new ListNavigation ( inputs ) ;
240
+ this . navigation = new ListNavigation ( {
241
+ ...inputs ,
242
+ wrap : computed ( ( ) => this . wrap ( ) && this . inputs . wrap ( ) ) ,
243
+ } ) ;
234
244
this . selection = new ListSelection ( { ...inputs , navigation : this . navigation } ) ;
235
245
this . typeahead = new ListTypeahead ( { ...inputs , navigation : this . navigation } ) ;
236
246
this . focusManager = new ListFocus ( { ...inputs , navigation : this . navigation } ) ;
0 commit comments