Skip to content

Commit c155cd3

Browse files
committed
refactor: Some minor code clean-ups
1 parent baea1ae commit c155cd3

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/components/combo/controllers/navigation.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export class ComboNavigationController<T extends object> {
7171
return await this.combo._show(true);
7272
}
7373

74-
public toggleSelect(index: number): void {
74+
protected _toggleSelection(index: number): void {
7575
// @ts-expect-error protected access
7676
this.combo.toggleSelect(index);
7777
}
@@ -88,7 +88,7 @@ export class ComboNavigationController<T extends object> {
8888

8989
const item = this.state.dataState[this._active];
9090
if (!item.header) {
91-
this.toggleSelect(this._active);
91+
this._toggleSelection(this._active);
9292
}
9393
};
9494

@@ -109,9 +109,11 @@ export class ComboNavigationController<T extends object> {
109109
}
110110
};
111111

112-
private _onTab = async (shiftKey?: boolean): Promise<void> => {
112+
private _onTab = async ({ shiftKey }: KeyboardEvent): Promise<void> => {
113113
if (this.combo.open) {
114114
if (shiftKey) {
115+
// Move focus to the main input of the combo
116+
// before the Shift+Tab behavior kicks in.
115117
this.combo.focus();
116118
}
117119
await this._hide();
@@ -122,6 +124,7 @@ export class ComboNavigationController<T extends object> {
122124
if (!this.combo.open) {
123125
this.combo.clearSelection();
124126
}
127+
125128
if (await this._hide()) {
126129
this.input.focus();
127130
}
@@ -213,8 +216,8 @@ export class ComboNavigationController<T extends object> {
213216

214217
// Combo
215218
addKeybindings(this.combo, { skip, bindingDefaults })
216-
.set(tabKey, () => this._onTab(), { preventDefault: false })
217-
.set([shiftKey, tabKey], () => this._onTab(true), {
219+
.set(tabKey, this._onTab, { preventDefault: false })
220+
.set([shiftKey, tabKey], this._onTab, {
218221
preventDefault: false,
219222
})
220223
.set(escapeKey, this._onEscape);

0 commit comments

Comments
 (0)