@@ -47,7 +47,7 @@ export class ListKeyboardDelegate<T> implements KeyboardDelegate {
4747 this . collator = opts . collator ;
4848 this . disabledKeys = opts . disabledKeys || new Set ( ) ;
4949 this . disabledBehavior = opts . disabledBehavior || 'all' ;
50- this . orientation = opts . orientation || 'vertical' ;
50+ this . orientation = opts . orientation ;
5151 this . direction = opts . direction ;
5252 this . layout = opts . layout || 'stack' ;
5353 this . layoutDelegate = opts . layoutDelegate || new DOMLayoutDelegate ( opts . ref , this . orientation ) ;
@@ -57,17 +57,31 @@ export class ListKeyboardDelegate<T> implements KeyboardDelegate {
5757 this . ref = args [ 2 ] ;
5858 this . collator = args [ 3 ] ;
5959 this . layout = 'stack' ;
60- this . orientation = 'vertical' ;
6160 this . disabledBehavior = 'all' ;
62- this . layoutDelegate = new DOMLayoutDelegate ( this . ref , this . orientation ) ;
61+ this . layoutDelegate = new DOMLayoutDelegate ( this . ref ) ;
6362 }
6463
6564 // If this is a vertical stack, remove the left/right methods completely
66- // so they aren't called by useDroppableCollection.
67- if ( this . layout === 'stack' && this . orientation === 'vertical' ) {
68- this . getKeyLeftOf = undefined ;
69- this . getKeyRightOf = undefined ;
70- }
65+ // so they aren't called by useDroppableCollection or useAutocomplete.
66+ let getKeyRightOf = this . getKeyRightOf ;
67+ let getKeyLeftOf = this . getKeyLeftOf ;
68+
69+ Object . defineProperty ( this , 'getKeyRightOf' , {
70+ get ( ) { return this . layout === 'stack' && this . getOrientation ( ) === 'vertical' ? undefined : getKeyRightOf ; } ,
71+ configurable : true ,
72+ enumerable : false
73+ } ) ;
74+
75+ Object . defineProperty ( this , 'getKeyLeftOf' , {
76+ get ( ) { return this . layout === 'stack' && this . getOrientation ( ) === 'vertical' ? undefined : getKeyLeftOf ; } ,
77+ configurable : true ,
78+ enumerable : false
79+ } ) ;
80+ }
81+
82+ getOrientation ( ) : Orientation {
83+ // TODO: Should we log a warning if keyboard and layout delegate mismatch in orientation?
84+ return this . orientation || this . layoutDelegate . getOrientation ?.( ) || 'vertical' ;
7185 }
7286
7387 private isDisabled ( item : Node < unknown > ) {
@@ -133,15 +147,15 @@ export class ListKeyboardDelegate<T> implements KeyboardDelegate {
133147 }
134148
135149 getKeyBelow ( key : Key ) : Key | null {
136- if ( this . layout === 'grid' && this . orientation === 'vertical' ) {
150+ if ( this . layout === 'grid' && this . getOrientation ( ) === 'vertical' ) {
137151 return this . findKey ( key , ( key ) => this . getNextKey ( key ) , this . isSameRow ) ;
138152 } else {
139153 return this . getNextKey ( key ) ;
140154 }
141155 }
142156
143157 getKeyAbove ( key : Key ) : Key | null {
144- if ( this . layout === 'grid' && this . orientation === 'vertical' ) {
158+ if ( this . layout === 'grid' && this . getOrientation ( ) === 'vertical' ) {
145159 return this . findKey ( key , ( key ) => this . getPreviousKey ( key ) , this . isSameRow ) ;
146160 } else {
147161 return this . getPreviousKey ( key ) ;
@@ -162,12 +176,12 @@ export class ListKeyboardDelegate<T> implements KeyboardDelegate {
162176 }
163177
164178 if ( this . layout === 'grid' ) {
165- if ( this . orientation === 'vertical' ) {
179+ if ( this . getOrientation ( ) === 'vertical' ) {
166180 return this . getNextColumn ( key , this . direction === 'rtl' ) ;
167181 } else {
168182 return this . findKey ( key , ( key ) => this . getNextColumn ( key , this . direction === 'rtl' ) , this . isSameColumn ) ;
169183 }
170- } else if ( this . orientation === 'horizontal' ) {
184+ } else if ( this . getOrientation ( ) === 'horizontal' ) {
171185 return this . getNextColumn ( key , this . direction === 'rtl' ) ;
172186 }
173187
@@ -182,12 +196,12 @@ export class ListKeyboardDelegate<T> implements KeyboardDelegate {
182196 }
183197
184198 if ( this . layout === 'grid' ) {
185- if ( this . orientation === 'vertical' ) {
199+ if ( this . getOrientation ( ) === 'vertical' ) {
186200 return this . getNextColumn ( key , this . direction === 'ltr' ) ;
187201 } else {
188202 return this . findKey ( key , ( key ) => this . getNextColumn ( key , this . direction === 'ltr' ) , this . isSameColumn ) ;
189203 }
190- } else if ( this . orientation === 'horizontal' ) {
204+ } else if ( this . getOrientation ( ) === 'horizontal' ) {
191205 return this . getNextColumn ( key , this . direction === 'ltr' ) ;
192206 }
193207
@@ -216,7 +230,7 @@ export class ListKeyboardDelegate<T> implements KeyboardDelegate {
216230 }
217231
218232 let nextKey : Key | null = key ;
219- if ( this . orientation === 'horizontal' ) {
233+ if ( this . getOrientation ( ) === 'horizontal' ) {
220234 let pageX = Math . max ( 0 , itemRect . x + itemRect . width - this . layoutDelegate . getVisibleRect ( ) . width ) ;
221235
222236 while ( itemRect && itemRect . x > pageX && nextKey != null ) {
@@ -247,7 +261,7 @@ export class ListKeyboardDelegate<T> implements KeyboardDelegate {
247261 }
248262
249263 let nextKey : Key | null = key ;
250- if ( this . orientation === 'horizontal' ) {
264+ if ( this . getOrientation ( ) === 'horizontal' ) {
251265 let pageX = Math . min ( this . layoutDelegate . getContentSize ( ) . width , itemRect . y - itemRect . width + this . layoutDelegate . getVisibleRect ( ) . width ) ;
252266
253267 while ( itemRect && itemRect . x < pageX && nextKey != null ) {
0 commit comments