Skip to content
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

User can scroll PDF by using the down/up arrow of keyboard #24363

Merged
merged 5 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
puneetlath marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* 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
Loading