(
focusMode: 'roving' | 'activedescendant',
isFocused: (index: number) => boolean,
)
| 760 | }); |
| 761 | |
| 762 | function runNavigationTests( |
| 763 | focusMode: 'roving' | 'activedescendant', |
| 764 | isFocused: (index: number) => boolean, |
| 765 | ) { |
| 766 | describe(`keyboard navigation (focusMode="${focusMode}")`, () => { |
| 767 | it('should move focus to the last focusable option on End', async () => { |
| 768 | await setupListbox({focusMode, disabledOptions: [4]}); |
| 769 | await end(); |
| 770 | expect(isFocused(4)).toBe(true); |
| 771 | }); |
| 772 | |
| 773 | it('should move focus to the first focusable option on Home', async () => { |
| 774 | await setupListbox({focusMode, disabledOptions: [0]}); |
| 775 | await end(); |
| 776 | await home(); |
| 777 | expect(isFocused(0)).toBe(true); |
| 778 | }); |
| 779 | |
| 780 | it('should allow keyboard navigation if the group is readonly', async () => { |
| 781 | await setupListbox({focusMode, orientation: 'horizontal', readonly: true}); |
| 782 | await right(); |
| 783 | expect(isFocused(1)).toBe(true); |
| 784 | }); |
| 785 | |
| 786 | it('should wrap focus from last to first with ArrowDown when wrap is true (vertical)', async () => { |
| 787 | await setupListbox({focusMode, orientation: 'vertical', wrap: true}); |
| 788 | for (let i = 0; i < optionElements.length - 1; i++) await down(); |
| 789 | await down(); |
| 790 | expect(isFocused(0)).toBe(true); |
| 791 | }); |
| 792 | |
| 793 | it('should not wrap focus from last to first with ArrowDown when wrap is false (vertical)', async () => { |
| 794 | await setupListbox({focusMode, orientation: 'vertical', wrap: false}); |
| 795 | for (let i = 0; i < optionElements.length - 1; i++) await down(); |
| 796 | await down(); |
| 797 | expect(isFocused(optionElements.length - 1)).toBe(true); |
| 798 | }); |
| 799 | |
| 800 | describe('vertical orientation', () => { |
| 801 | it('should move focus to the next option on ArrowDown', async () => { |
| 802 | await setupListbox({focusMode, orientation: 'vertical'}); |
| 803 | await down(); |
| 804 | expect(isFocused(1)).toBe(true); |
| 805 | }); |
| 806 | |
| 807 | it('should skip disabled options with ArrowDown (softDisabled="false")', async () => { |
| 808 | await setupListbox({ |
| 809 | focusMode, |
| 810 | orientation: 'vertical', |
| 811 | softDisabled: false, |
| 812 | disabledOptions: [1, 2], |
| 813 | }); |
| 814 | await down(); |
| 815 | expect(isFocused(3)).toBe(true); |
| 816 | }); |
| 817 | |
| 818 | it('should not skip disabled options with ArrowDown (softDisabled="true")', async () => { |
| 819 | await setupListbox({ |
no test coverage detected