Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change navigation-mixin to avoid disabled options #742

Merged
merged 2 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
2023-11-18 - 37b5c67d67b24357d773210c952d3a899d60b008 - onKeypress changed to skip the disabled options when updating the pointer in navigation-mixin.

2023-10-11 - a06c8f9059ceb16ba00c4bf8bf0528ea2c9cee22 - Adding style support for working weekend calendar event

2023-09-04 - d72a759e6904d11d222b62a792aa8c5f622238cf - Update ListTable.vue component to show partial loading status.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export const navigationMixin = defineComponent({
onKeypress($e: KeyboardEvent) {
if ($e.key.length > 1) return; // Filter one letter keypress only
const filtered = this.computedOptions.flatMap((item: Option, i: number) =>
item.label.toLowerCase().startsWith($e.key) ? i : [],
item.label.toLowerCase().startsWith($e.key) && !item._disabled ? i : [],
);
if (filtered.length > 0) {
this.pointer = cycleIndexes(this.pointer, filtered);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const MockComponent = defineComponent({
{id: 2, label: 'banana'},
{id: 3, label: 'cherry'},
{id: 4, label: 'avocado'},
{id: 5, label: 'lime', _disabled: true},
];
},
},
Expand All @@ -41,6 +42,19 @@ describe('navigationMixin.ts', () => {
wrapper.vm.onKeypress(keydownEvent);
expect(wrapper.vm.pointer).toStrictEqual(1);
});
it('should not match pointer to keypress when the matching item is disabled', () => {
const wrapper = mount(MockComponent, {});
const keydownEvent = new KeyboardEvent('keydown', {key: 'l'});
wrapper.vm.onKeypress(keydownEvent);
expect(wrapper.vm.pointer).toStrictEqual(-1);
});
it('should not match pointer to keypress when the matching item is disabled - pointer should be in previous position', () => {
const wrapper = mount(MockComponent, {});
wrapper.vm.pointer = 1;
const keydownEvent = new KeyboardEvent('keydown', {key: 'l'});
wrapper.vm.onKeypress(keydownEvent);
expect(wrapper.vm.pointer).toStrictEqual(1);
});
it('should match pointer to keypress on repeat keypress', () => {
const wrapper = mount(MockComponent, {});
const keydownEvent = new KeyboardEvent('keydown', {key: 'a'});
Expand All @@ -53,9 +67,9 @@ describe('navigationMixin.ts', () => {
});
it('should not increment pointer beyond options length', () => {
const wrapper = mount(MockComponent, {});
wrapper.vm.pointer = 3;
wrapper.vm.pointer = 4;
wrapper.vm.onSelectDown();
expect(wrapper.vm.pointer).toStrictEqual(3);
expect(wrapper.vm.pointer).toStrictEqual(4);
});
it('should not decrement pointer beyond options length', () => {
const wrapper = mount(MockComponent, {});
Expand Down
Loading