Skip to content

Commit 37589ec

Browse files
committed
feat(multiple): add focusable attr to list items
1 parent 385da11 commit 37589ec

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

src/aria/private/behaviors/list-focus/list-focus.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {ListFocus, ListFocusInputs, ListFocusItem} from './list-focus';
1111

1212
type TestItem = ListFocusItem & {
1313
disabled: WritableSignalLike<boolean>;
14+
focusable: WritableSignalLike<boolean>;
1415
};
1516

1617
type TestInputs = Partial<ListFocusInputs<ListFocusItem>> & {
@@ -37,6 +38,7 @@ function getItems(length: number): SignalLike<ListFocusItem[]> {
3738
id: signal(`${i}`),
3839
disabled: signal(false),
3940
element: signal({focus: () => {}} as HTMLElement),
41+
focusable: signal(true),
4042
index: signal(i),
4143
};
4244
}),
@@ -135,5 +137,14 @@ describe('List Focus', () => {
135137
expect(focusManager.isFocusable(items[1])).toBeTrue();
136138
expect(focusManager.isFocusable(items[2])).toBeTrue();
137139
});
140+
141+
it('should return false if focusable is false', () => {
142+
const focusManager = getListFocus({softDisabled: signal(true)});
143+
const items = focusManager.inputs.items() as TestItem[];
144+
items[1].focusable.set(false);
145+
146+
expect(focusManager.isFocusable(items[0])).toBeTrue();
147+
expect(focusManager.isFocusable(items[1])).toBeFalse();
148+
});
138149
});
139150
});

src/aria/private/behaviors/list-focus/list-focus.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ export interface ListFocusItem {
1919
/** Whether an item is disabled. */
2020
disabled: SignalLike<boolean>;
2121

22+
/** Whether an item is focusable. */
23+
focusable?: SignalLike<boolean>;
24+
2225
/** The index of the item in the list. */
2326
index: SignalLike<number>;
2427
}
@@ -115,6 +118,9 @@ export class ListFocus<T extends ListFocusItem> {
115118

116119
/** Returns true if the given item can be navigated to. */
117120
isFocusable(item: T): boolean {
121+
if (item.focusable && !item.focusable()) {
122+
return false;
123+
}
118124
return !item.disabled() || this.inputs.softDisabled();
119125
}
120126
}

src/aria/private/behaviors/list/list.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ describe('List Behavior', () => {
4646
disabled: signal(false),
4747
selectable: signal(true),
4848
searchTerm: signal(String(value)),
49+
focusable: signal(true),
4950
index: signal(index),
5051
}));
5152
}

0 commit comments

Comments
 (0)