Skip to content

fix(list): multiple selection by keyboard on macos (#DS-2908) #314

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

Merged
merged 1 commit into from
Sep 26, 2024
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: 1 addition & 1 deletion packages/components-dev/list/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ <h2>Multiple selection: Keyboard</h2>
multiple="keyboard"
style="height: 100px; overflow-y: scroll"
[autoSelect]="true"
[disabled]="true"
[disabled]="false"
[(ngModel)]="multipleSelected"
(selectionChange)="onSelectionChange($event)"
>
Expand Down
12 changes: 8 additions & 4 deletions packages/components/list/list-selection.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,8 @@ export class KbqListSelection
}
}

onKeyDown(event: KeyboardEvent) {
/** Handles keydown events on the list. */
onKeyDown(event: KeyboardEvent): void {
const keyCode = event.keyCode;

if ([SPACE, ENTER, LEFT_ARROW, RIGHT_ARROW].includes(keyCode) || isVerticalMovement(event)) {
Expand Down Expand Up @@ -508,7 +509,8 @@ export class KbqListSelection
this.setSelectedOptionsByKey(
this.keyManager.activeItem as KbqListOption,
hasModifierKey(event, 'shiftKey'),
hasModifierKey(event, 'ctrlKey')
// ctrlKey is for Windows, metaKey is for MacOS
hasModifierKey(event, 'ctrlKey') || hasModifierKey(event, 'metaKey')
);
}
}
Expand Down Expand Up @@ -825,15 +827,17 @@ export class KbqListOption implements OnDestroy, OnInit, IFocusableOption, KbqTi
return clientRects.length ? clientRects[0].height : 0;
}

handleClick($event) {
/** Handles click events on the list option. */
handleClick($event: MouseEvent): void {
if (this.disabled) {
return;
}

this.listSelection.setSelectedOptionsByClick(
this,
hasModifierKey($event, 'shiftKey'),
hasModifierKey($event, 'ctrlKey')
// ctrlKey is for Windows, metaKey is for MacOS
hasModifierKey($event, 'ctrlKey') || hasModifierKey($event, 'metaKey')
);
}

Expand Down
4 changes: 1 addition & 3 deletions tools/public_api_guard/components/list.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ export class KbqListOption implements OnDestroy, OnInit, IFocusableOption, KbqTi
getLabel(): any;
// (undocumented)
readonly group: KbqOptgroup;
// (undocumented)
handleClick($event: any): void;
handleClick($event: MouseEvent): void;
// (undocumented)
hasFocus: boolean;
// (undocumented)
Expand Down Expand Up @@ -215,7 +214,6 @@ export class KbqListSelection extends KbqListSelectionMixinBase implements CanDi
set noUnselectLast(value: boolean);
// (undocumented)
readonly onCopy: EventEmitter<KbqListCopyEvent<KbqListOption>>;
// (undocumented)
onKeyDown(event: KeyboardEvent): void;
// (undocumented)
readonly onSelectAll: EventEmitter<KbqListSelectAllEvent<KbqListOption>>;
Expand Down
Loading