-
Notifications
You must be signed in to change notification settings - Fork 1.3k
fix: Support range selection with grid/table checkboxes #7839
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -4,6 +4,7 @@ import {GridState} from '@react-stately/grid'; | |||||
// @ts-ignore | ||||||
import intlMessages from '../intl/*.json'; | ||||||
import {Key} from '@react-types/shared'; | ||||||
import {useEffect, useRef} from 'react'; | ||||||
import {useId} from '@react-aria/utils'; | ||||||
import {useLocalizedStringFormatter} from '@react-aria/i18n'; | ||||||
|
||||||
|
@@ -31,8 +32,30 @@ export function useGridSelectionCheckbox<T, C extends GridCollection<T>>(props: | |||||
let isDisabled = !state.selectionManager.canSelectItem(key); | ||||||
let isSelected = state.selectionManager.isSelected(key); | ||||||
|
||||||
let isShiftDown = useRef(false); | ||||||
useEffect(() => { | ||||||
let trackKeyDown = (e: KeyboardEvent) => { | ||||||
if (e.key === 'Shift') { | ||||||
isShiftDown.current = true; | ||||||
} | ||||||
}; | ||||||
let trackKeyUp = (e: KeyboardEvent) => { | ||||||
if (e.key === 'Shift') { | ||||||
isShiftDown.current = false; | ||||||
} | ||||||
}; | ||||||
|
||||||
document.addEventListener('keydown', trackKeyDown); | ||||||
document.addEventListener('keyup', trackKeyUp); | ||||||
|
||||||
return () => { | ||||||
document.removeEventListener('keydown', trackKeyDown); | ||||||
document.removeEventListener('keyup', trackKeyUp); | ||||||
}; | ||||||
}); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
We don't want to re-run this every time we render, only on mount/unmount There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh my... no idea how I missed that. added. |
||||||
|
||||||
// Checkbox should always toggle selection, regardless of selectionBehavior. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will need to discuss with the team if the proposed change conflicts with this intent There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to add some background here: I have a table with |
||||||
let onChange = () => manager.toggleSelection(key); | ||||||
let onChange = () => isShiftDown.current ? manager.extendSelection(key) : manager.toggleSelection(key); | ||||||
|
||||||
const stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/grid'); | ||||||
|
||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these should be capturing listeners, don't want to miss it should something call stopPropagation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes sense, added