Skip to content

Commit d5bd379

Browse files
983059: Updated comments index.js
1 parent e11dbcd commit d5bd379

File tree

1 file changed

+21
-7
lines changed
  • How to/Disable Default Hotkeys and Implement Custom Actions/src

1 file changed

+21
-7
lines changed

How to/Disable Default Hotkeys and Implement Custom Actions/src/index.js

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
// Import necessary modules and styles
12
import { createRoot } from 'react-dom/client';
23
import './index.css';
34
import * as React from 'react';
45
import { useEffect } from 'react';
6+
7+
// Import required modules from Syncfusion PDF Viewer
58
import {
69
PdfViewerComponent,
710
Toolbar,
@@ -20,18 +23,22 @@ import {
2023
Inject,
2124
} from '@syncfusion/ej2-react-pdfviewer';
2225

26+
// Define the main component
2327
function Default() {
24-
let viewer;
28+
let viewer; // Reference to the PDF Viewer component
2529

30+
// useEffect hook to add keyboard event listeners
2631
useEffect(() => {
2732
const handleKeyDown = (e) => {
2833
const viewerElement = document.querySelector('.e-pv-viewer-container');
2934

35+
// Exit if viewer container is not found
3036
if (!viewerElement) return;
3137

32-
// Check if the active element is inside the viewer container
38+
// Exit if the active element is not inside the viewer container
3339
if (!viewerElement.contains(document.activeElement)) return;
3440

41+
// Handle Ctrl + key combinations
3542
if (e.ctrlKey) {
3643
switch (e.key.toLowerCase()) {
3744
case 's':
@@ -65,25 +72,29 @@ function Default() {
6572
}
6673
};
6774

75+
// Add the keydown event listener
6876
document.addEventListener('keydown', handleKeyDown, true);
6977

78+
// Cleanup the event listener on component unmount
7079
return () => {
7180
document.removeEventListener('keydown', handleKeyDown);
7281
};
7382
}, []);
83+
7484
return (
7585
<div>
7686
<div className="control-section">
77-
{/* Render the PDF Viewer */}
87+
{/* Render the Syncfusion PDF Viewer */}
7888
<PdfViewerComponent
7989
ref={(scope) => {
80-
viewer = scope;
90+
viewer = scope; // Assign the viewer reference
8191
}}
8292
id="container"
83-
documentPath="https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf"
84-
resourceUrl="https://cdn.syncfusion.com/ej2/31.1.17/dist/ej2-pdfviewer-lib"
85-
style={{ height: '640px' }}
93+
documentPath="https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf" // PDF file to load
94+
resourceUrl="https://cdn.syncfusion.com/ej2/31.1.17/dist/ej2-pdfviewer-lib" // Resource URL for viewer assets
95+
style={{ height: '640px' }} // Viewer height
8696
>
97+
{/* Inject required services into the viewer */}
8798
<Inject
8899
services={[
89100
Toolbar,
@@ -106,7 +117,10 @@ function Default() {
106117
</div>
107118
);
108119
}
120+
121+
// Export the component as default
109122
export default Default;
110123

124+
// Render the component into the DOM
111125
const root = createRoot(document.getElementById('sample'));
112126
root.render(<Default />);

0 commit comments

Comments
 (0)