Skip to content

feat: add select only option to listbox toggle mode #8168

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
16 changes: 14 additions & 2 deletions packages/@react-aria/selection/src/useSelectableItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,23 @@ export function useSelectableItem(options: SelectableItemOptions): SelectableIte
}
} else if (e && e.shiftKey) {
manager.extendSelection(key);
} else if (manager.selectionBehavior === 'toggle' || (e && (isCtrlKeyPressed(e) || e.pointerType === 'touch' || e.pointerType === 'virtual'))) {
} else if (e && (e.pointerType === 'touch' || e.pointerType === 'virtual')) {
// if touch or virtual (VO) then we just want to toggle, otherwise it's impossible to multi select because they don't have modifier keys
manager.toggleSelection(key);
} else if (manager.selectionBehavior === 'toggle') {
// if ctrl is pressed in toggle mode, we want to replace selection
if (isCtrlKeyPressed(e)) {
manager.replaceSelection(key);
} else {
manager.toggleSelection(key);
}
} else {
manager.replaceSelection(key);
// if ctrl is pressed in replace mode, we want to toggle selection
if (isCtrlKeyPressed(e)) {
manager.toggleSelection(key);
} else {
manager.replaceSelection(key);
}
}
}
};
Expand Down