Skip to content

Commit

Permalink
Merge pull request #24363 from rezkiy37/fix/24326-pdf-keyboard-scroll
Browse files Browse the repository at this point in the history
User can scroll PDF by using the down/up arrow of keyboard

(cherry picked from commit 3f037a9)
  • Loading branch information
puneetlath authored and OSBotify committed Aug 10, 2023
1 parent e698363 commit 4446d56
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/components/PDFView/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class PDFView extends Component {
this.calculatePageHeight = this.calculatePageHeight.bind(this);
this.calculatePageWidth = this.calculatePageWidth.bind(this);
this.renderPage = this.renderPage.bind(this);
this.setListAttributes = this.setListAttributes.bind(this);

const workerBlob = new Blob([pdfWorkerSource], {type: 'text/javascript'});
pdfjs.GlobalWorkerOptions.workerSrc = URL.createObjectURL(workerBlob);
Expand Down Expand Up @@ -97,6 +98,22 @@ class PDFView extends Component {
});
}

/**
* Sets attributes to list container.
* It unblocks a default scroll by keyboard of browsers.
* @param {Object|undefined} ref
*/
setListAttributes(ref) {
if (!ref) {
return;
}

// Useful for elements that should not be navigated to directly using the "Tab" key,
// but need to have keyboard focus set to them.
// eslint-disable-next-line no-param-reassign
ref.tabIndex = -1;
}

/**
* Calculates a proper page height. The method should be called only when there are page viewports.
* It is based on a ratio between the specific page viewport width and provided page width.
Expand Down Expand Up @@ -237,6 +254,7 @@ class PDFView extends Component {
>
{this.state.pageViewports.length > 0 && (
<List
outerRef={this.setListAttributes}
style={styles.PDFViewList}
width={this.props.isSmallScreenWidth ? pageWidth : this.state.containerWidth}
height={this.state.containerHeight}
Expand Down
3 changes: 3 additions & 0 deletions src/styles/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -2109,6 +2109,9 @@ const styles = {

PDFViewList: {
overflowX: 'hidden',
// There properties disable "focus" effect on list
boxShadow: 'none',
outline: 'none',
},

pdfPasswordForm: {
Expand Down

0 comments on commit 4446d56

Please sign in to comment.