Skip to content

Commit ce25eb9

Browse files
committed
feat(aria/tree): adds rtl keyboard functionality for tree
Updates aria tree keyboard functionality to have RightArrow collapse and LeftArrow expand for rtl.
1 parent 0d83d65 commit ce25eb9

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/aria/private/tree/tree.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ export interface TreeInputs<V> extends Omit<ListInputs<TreeItemPattern<V>, V>, '
168168

169169
/** The aria-current type. */
170170
currentType: SignalLike<'page' | 'step' | 'location' | 'date' | 'time' | 'true' | 'false'>;
171+
172+
/** The text direction of the tree. */
173+
textDirection: SignalLike<'ltr' | 'rtl'>;
171174
}
172175

173176
export interface TreePattern<V> extends TreeInputs<V> {}
@@ -205,36 +208,39 @@ export class TreePattern<V> {
205208
/** Whether the tree selection follows focus. */
206209
readonly followFocus = computed(() => this.inputs.selectionMode() === 'follow');
207210

211+
/** Whether the tree direction is RTL. */
212+
readonly isRtl = computed(() => this.inputs.textDirection() === 'rtl');
213+
208214
/** The key for navigating to the previous item. */
209215
readonly prevKey = computed(() => {
210216
if (this.inputs.orientation() === 'vertical') {
211217
return 'ArrowUp';
212218
}
213-
return this.inputs.textDirection() === 'rtl' ? 'ArrowRight' : 'ArrowLeft';
219+
return this.isRtl() ? 'ArrowRight' : 'ArrowLeft';
214220
});
215221

216222
/** The key for navigating to the next item. */
217223
readonly nextKey = computed(() => {
218224
if (this.inputs.orientation() === 'vertical') {
219225
return 'ArrowDown';
220226
}
221-
return this.inputs.textDirection() === 'rtl' ? 'ArrowLeft' : 'ArrowRight';
227+
return this.isRtl() ? 'ArrowLeft' : 'ArrowRight';
222228
});
223229

224230
/** The key for collapsing an item or moving to its parent. */
225231
readonly collapseKey = computed(() => {
226232
if (this.inputs.orientation() === 'horizontal') {
227233
return 'ArrowUp';
228234
}
229-
return this.inputs.textDirection() === 'rtl' ? 'ArrowRight' : 'ArrowLeft';
235+
return this.isRtl() ? 'ArrowRight' : 'ArrowLeft';
230236
});
231237

232238
/** The key for expanding an item or moving to its first child. */
233239
readonly expandKey = computed(() => {
234240
if (this.inputs.orientation() === 'horizontal') {
235241
return 'ArrowDown';
236242
}
237-
return this.inputs.textDirection() === 'rtl' ? 'ArrowLeft' : 'ArrowRight';
243+
return this.isRtl() ? 'ArrowLeft' : 'ArrowRight';
238244
});
239245

240246
/** Represents the space key. Does nothing when the user is actively using typeahead. */

0 commit comments

Comments
 (0)