Skip to content

Commit 5703018

Browse files
committed
fixup! fix(cdk-experimental/listbox): change shift+nav behavior
1 parent a40bb1a commit 5703018

File tree

1 file changed

+26
-11
lines changed

1 file changed

+26
-11
lines changed

src/cdk-experimental/ui-patterns/listbox/listbox.spec.ts

+26-11
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const home = (mods?: ModifierKeys) => createKeyboardEvent('keydown', 36, 'Home',
2424
const end = (mods?: ModifierKeys) => createKeyboardEvent('keydown', 35, 'End', mods);
2525
const space = (mods?: ModifierKeys) => createKeyboardEvent('keydown', 32, ' ', mods);
2626
const enter = (mods?: ModifierKeys) => createKeyboardEvent('keydown', 13, 'Enter', mods);
27+
const shift = () => createKeyboardEvent('keydown', 16, 'Shift', {shift: true});
2728

2829
describe('Listbox Pattern', () => {
2930
function getListbox(inputs: Partial<TestInputs> & Pick<TestInputs, 'items'>) {
@@ -279,18 +280,25 @@ describe('Listbox Pattern', () => {
279280
expect(listbox.inputs.value()).toEqual(['Apple', 'Apricot']);
280281
});
281282

282-
it('should toggle the selected state of the next option on Shift + ArrowDown', () => {
283+
it('should select a range of options on Shift + ArrowDown/ArrowUp', () => {
284+
listbox.onKeydown(shift());
283285
listbox.onKeydown(down({shift: true}));
286+
expect(listbox.inputs.value()).toEqual(['Apple', 'Apricot']);
284287
listbox.onKeydown(down({shift: true}));
285-
expect(listbox.inputs.value()).toEqual(['Apricot', 'Banana']);
288+
expect(listbox.inputs.value()).toEqual(['Apple', 'Apricot', 'Banana']);
289+
listbox.onKeydown(up({shift: true}));
290+
expect(listbox.inputs.value()).toEqual(['Apple', 'Apricot']);
291+
listbox.onKeydown(up({shift: true}));
292+
expect(listbox.inputs.value()).toEqual(['Apple']);
286293
});
287294

288-
it('should toggle the selected state of the next option on Shift + ArrowUp', () => {
289-
listbox.onKeydown(down());
290-
listbox.onKeydown(down());
295+
it('should not allow wrapping while Shift is held down', () => {
296+
listbox.onKeydown(shift());
297+
listbox.onKeydown(up({shift: true}));
291298
listbox.onKeydown(up({shift: true}));
292299
listbox.onKeydown(up({shift: true}));
293-
expect(listbox.inputs.value()).toEqual(['Apricot', 'Apple']);
300+
listbox.onKeydown(up({shift: true}));
301+
expect(listbox.inputs.value()).toEqual(['Apple']);
294302
});
295303

296304
it('should select contiguous items from the most recently selected item to the focused item on Shift + Space (or Enter)', () => {
@@ -385,18 +393,25 @@ describe('Listbox Pattern', () => {
385393
expect(listbox.inputs.value()).toEqual(['Apple', 'Banana']);
386394
});
387395

388-
it('should toggle the selected state of the next option on Shift + ArrowDown', () => {
396+
it('should select a range of options on Shift + ArrowDown/ArrowUp', () => {
397+
listbox.onKeydown(shift());
389398
listbox.onKeydown(down({shift: true}));
399+
expect(listbox.inputs.value()).toEqual(['Apple', 'Apricot']);
390400
listbox.onKeydown(down({shift: true}));
391401
expect(listbox.inputs.value()).toEqual(['Apple', 'Apricot', 'Banana']);
402+
listbox.onKeydown(up({shift: true}));
403+
expect(listbox.inputs.value()).toEqual(['Apple', 'Apricot']);
404+
listbox.onKeydown(up({shift: true}));
405+
expect(listbox.inputs.value()).toEqual(['Apple']);
392406
});
393407

394-
it('should toggle the selected state of the next option on Shift + ArrowUp', () => {
395-
listbox.onKeydown(down());
396-
listbox.onKeydown(down());
408+
it('should not allow wrapping while Shift is held down', () => {
409+
listbox.onKeydown(shift());
410+
listbox.onKeydown(up({shift: true}));
397411
listbox.onKeydown(up({shift: true}));
398412
listbox.onKeydown(up({shift: true}));
399-
expect(listbox.inputs.value()).toEqual(['Banana', 'Apricot', 'Apple']);
413+
listbox.onKeydown(up({shift: true}));
414+
expect(listbox.inputs.value()).toEqual(['Apple']);
400415
});
401416

402417
it('should select contiguous items from the most recently selected item to the focused item on Shift + Space (or Enter)', () => {

0 commit comments

Comments
 (0)