Skip to content

Commit ae9745d

Browse files
authored
Add onKeyPress event handler to capture e.shiftKey, unavailable in onChange (#3768)
1 parent f10745e commit ae9745d

File tree

5 files changed

+15
-3
lines changed

5 files changed

+15
-3
lines changed

Diff for: packages/@uppy/provider-views/src/Browser.jsx

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ function Browser (props) {
2121
showBreadcrumbs,
2222
isChecked,
2323
toggleCheckbox,
24+
recordShiftKeyPress,
2425
handleScroll,
2526
showTitles,
2627
i18n,
@@ -91,6 +92,7 @@ function Browser (props) {
9192
getItemIcon: () => folder.icon,
9293
isChecked: isChecked(folder),
9394
toggleCheckbox: (event) => toggleCheckbox(event, folder),
95+
recordShiftKeyPress,
9496
type: 'folder',
9597
isDisabled: isChecked(folder)?.loading,
9698
isCheckboxDisabled: folder.id === VIRTUAL_SHARED_DIR,
@@ -111,6 +113,7 @@ function Browser (props) {
111113
getItemIcon: () => file.icon,
112114
isChecked: isChecked(file),
113115
toggleCheckbox: (event) => toggleCheckbox(event, file),
116+
recordShiftKeyPress,
114117
columns,
115118
showTitles,
116119
viewType,

Diff for: packages/@uppy/provider-views/src/Item/components/GridLi.jsx

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ function GridListItem (props) {
1010
itemIconEl,
1111
showTitles,
1212
toggleCheckbox,
13+
recordShiftKeyPress,
1314
id,
1415
children,
1516
} = props
@@ -25,6 +26,7 @@ function GridListItem (props) {
2526
isChecked ? 'uppy-ProviderBrowserItem-checkbox--is-checked' : ''
2627
} uppy-ProviderBrowserItem-checkbox--grid`}
2728
onChange={toggleCheckbox}
29+
onKeyDown={recordShiftKeyPress}
2830
name="listitem"
2931
id={id}
3032
checked={isChecked}

Diff for: packages/@uppy/provider-views/src/Item/components/ListLi.jsx

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ function ListItem (props) {
1515
isCheckboxDisabled,
1616
isChecked,
1717
toggleCheckbox,
18+
recordShiftKeyPress,
1819
type,
1920
id,
2021
itemIconEl,
@@ -34,6 +35,7 @@ function ListItem (props) {
3435
type="checkbox"
3536
className={`uppy-u-reset uppy-ProviderBrowserItem-checkbox ${isChecked ? 'uppy-ProviderBrowserItem-checkbox--is-checked' : ''}`}
3637
onChange={toggleCheckbox}
38+
onKeyDown={recordShiftKeyPress}
3739
// for the <label/>
3840
name="listitem"
3941
id={id}

Diff for: packages/@uppy/provider-views/src/ProviderView/ProviderView.jsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ export default class ProviderView extends View {
332332

333333
const targetViewOptions = { ...this.opts, ...viewOptions }
334334
const { files, folders, filterInput, loading, currentSelection } = this.plugin.getPluginState()
335-
const { isChecked, toggleCheckbox, filterItems } = this.sharedHandler
335+
const { isChecked, toggleCheckbox, recordShiftKeyPress, filterItems } = this.sharedHandler
336336
const hasInput = filterInput !== ''
337337
const headerProps = {
338338
showBreadcrumbs: targetViewOptions.showBreadcrumbs,
@@ -348,6 +348,7 @@ export default class ProviderView extends View {
348348
const browserProps = {
349349
isChecked,
350350
toggleCheckbox,
351+
recordShiftKeyPress,
351352
currentSelection,
352353
files: hasInput ? filterItems(files) : files,
353354
folders: hasInput ? filterItems(folders) : folders,

Diff for: packages/@uppy/provider-views/src/SharedHandler.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export default class SharedHandler {
55
this.plugin = plugin
66
this.filterItems = this.filterItems.bind(this)
77
this.toggleCheckbox = this.toggleCheckbox.bind(this)
8+
this.recordShiftKeyPress = this.recordShiftKeyPress.bind(this)
89
this.isChecked = this.isChecked.bind(this)
910
this.loaderWrapper = this.loaderWrapper.bind(this)
1011
}
@@ -19,6 +20,10 @@ export default class SharedHandler {
1920
})
2021
}
2122

23+
recordShiftKeyPress (e) {
24+
this.isShiftKeyPressed = e.shiftKey
25+
}
26+
2227
/**
2328
* Toggles file/folder checkbox to on/off state while updating files list.
2429
*
@@ -32,10 +37,9 @@ export default class SharedHandler {
3237
e.currentTarget.focus()
3338
const { folders, files } = this.plugin.getPluginState()
3439
const items = this.filterItems(folders.concat(files))
35-
3640
// Shift-clicking selects a single consecutive list of items
3741
// starting at the previous click and deselects everything else.
38-
if (this.lastCheckbox && e.shiftKey) {
42+
if (this.lastCheckbox && this.isShiftKeyPressed) {
3943
const prevIndex = items.indexOf(this.lastCheckbox)
4044
const currentIndex = items.indexOf(file)
4145
const currentSelection = (prevIndex < currentIndex)

0 commit comments

Comments
 (0)