Skip to content

Commit d72790b

Browse files
Merge pull request #213 from Saifullah-dev/feat/178-onSelectionChange-callback
feat: add onSelectionChange callback for select and deselect events
2 parents 331e762 + 31d1bb8 commit d72790b

File tree

6 files changed

+108
-78
lines changed

6 files changed

+108
-78
lines changed

README.md

Lines changed: 37 additions & 36 deletions
Large diffs are not rendered by default.

frontend/CHANGELOG.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# [1.27.0](https://github.com/Saifullah-dev/react-file-manager/compare/v1.26.3...v1.27.0) (2025-09-12)
2+
3+
### ✨ Features
4+
5+
- **component:** add `onSelectionChange` callback to handle both select and deselect events
6+
([#213](https://github.com/Saifullah-dev/react-file-manager/pull/213))
7+
- This callback now triggers for **both selecting and deselecting** files, providing a unified way
8+
to react to any selection state change.
9+
10+
### ⚠️ Deprecations
11+
12+
- `onSelect` is now deprecated and will be removed in the next major release (`3.0.0`).
13+
14+
- Please migrate to `onSelectionChange`.
15+
- Example:
16+
17+
```tsx
18+
// Before
19+
<FileManager onSelect={(files) => console.log(files)} />
20+
21+
// After
22+
<FileManager onSelectionChange={(files) => console.log(files)} />
23+
```

frontend/README.md

Lines changed: 36 additions & 35 deletions
Large diffs are not rendered by default.

frontend/src/App.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ function App() {
131131
console.log("Copied Files", files);
132132
};
133133

134-
const handleSelect = (files) => {
134+
const handleSelectionChange = (files) => {
135135
console.log("Selected Files", files);
136136
};
137137

@@ -154,7 +154,7 @@ function App() {
154154
onLayoutChange={handleLayoutChange}
155155
onRefresh={handleRefresh}
156156
onFileOpen={handleFileOpen}
157-
onSelect={handleSelect}
157+
onSelectionChange={handleSelectionChange}
158158
onError={handleError}
159159
layout="grid"
160160
enableFilePreview

frontend/src/FileManager/FileManager.jsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const FileManager = ({
3636
onFileOpen = () => {},
3737
onFolderChange = () => {},
3838
onSelect,
39+
onSelectionChange,
3940
onError = () => {},
4041
layout = "grid",
4142
enableFilePreview = true,
@@ -75,7 +76,11 @@ const FileManager = ({
7576
<TranslationProvider language={language}>
7677
<FilesProvider filesData={files} onError={onError}>
7778
<FileNavigationProvider initialPath={initialPath} onFolderChange={onFolderChange}>
78-
<SelectionProvider onDownload={onDownload} onSelect={onSelect}>
79+
<SelectionProvider
80+
onDownload={onDownload}
81+
onSelect={onSelect}
82+
onSelectionChange={onSelectionChange}
83+
>
7984
<ClipBoardProvider onPaste={onPaste} onCut={onCut} onCopy={onCopy}>
8085
<LayoutProvider layout={layout}>
8186
<Toolbar
@@ -179,6 +184,7 @@ FileManager.propTypes = {
179184
onFileOpen: PropTypes.func,
180185
onFolderChange: PropTypes.func,
181186
onSelect: PropTypes.func,
187+
onSelectionChange: PropTypes.func,
182188
onError: PropTypes.func,
183189
layout: PropTypes.oneOf(["grid", "list"]),
184190
maxFileSize: PropTypes.number,

frontend/src/contexts/SelectionContext.jsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@ import { validateApiCallback } from "../utils/validateApiCallback";
33

44
const SelectionContext = createContext();
55

6-
export const SelectionProvider = ({ children, onDownload, onSelect }) => {
6+
export const SelectionProvider = ({ children, onDownload, onSelect, onSelectionChange }) => {
77
const [selectedFiles, setSelectedFiles] = useState([]);
88

99
useEffect(() => {
10-
if (selectedFiles.length && onSelect) {
11-
onSelect(selectedFiles);
12-
}
10+
onSelect?.(selectedFiles);
11+
onSelectionChange?.(selectedFiles);
1312
}, [selectedFiles]);
1413

1514
const handleDownload = () => {

0 commit comments

Comments
 (0)