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

Fix: Keyboard navigation should only focus meaningful elements #970

Merged
merged 3 commits into from
Apr 1, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions src/lib/ThumbnailsSidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,9 @@ class ThumbnailsSidebar {
* @return {HTMLElement} - thumbnail anchor element
*/
createThumbnailNav() {
const thumbnailNav = document.createElement('a');
const thumbnailNav = document.createElement('button');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does button work better than a in this case?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anchors without an href attribute are considered placeholders rather than links and aren't included in the tab order (source). Since we just want to response to a user action rather than navigating, a button seems more semantically correct and also obviates the need for tabindex="0"

thumbnailNav.className = CLASS_BOX_PREVIEW_THUMBNAIL_NAV;
thumbnailNav.tabIndex = '0';
thumbnailNav.type = 'button';
return thumbnailNav;
}

Expand Down
4 changes: 2 additions & 2 deletions src/lib/shell.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
</div>
</div>
</div>
<div class="bp" tabindex="0" data-testid="bp">
<div class="bp-content" tabindex="0" data-testid="bp-content">
<div class="bp" data-testid="bp" tabindex="-1">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do both of these need to be programmatically focusable? It looks like BaseViewer focuses on .bp-content when autoFocus is enabled.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ContentPreview Element auto-focuses on .bp and the Preview SDK auto-focuses on .bp-content.

<div class="bp-content" data-testid="bp-content" tabindex="-1">
<div class="bp-loading-wrapper">
<div class="bp-loading">
<div class="bp-icon bp-icon-file"></div>
Expand Down
8 changes: 7 additions & 1 deletion src/lib/viewers/doc/DocBaseViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1347,21 +1347,27 @@ class DocBaseViewer extends BaseViewer {

let metricName;
let eventName;
let style;
if (!this.thumbnailsSidebar.isOpen) {
this.rootEl.classList.remove(CLASS_BOX_PREVIEW_THUMBNAILS_OPEN);
metricName = USER_DOCUMENT_THUMBNAIL_EVENTS.CLOSE;
eventName = 'thumbnailsClose';
style = 'display: none';
} else {
this.rootEl.classList.add(CLASS_BOX_PREVIEW_THUMBNAILS_OPEN);
metricName = USER_DOCUMENT_THUMBNAIL_EVENTS.OPEN;
eventName = 'thumbnailsOpen';
style = '';
}

this.emitMetric({ name: metricName, data: pagesCount });
this.emit(eventName);

// Resize after the CSS animation to toggle the sidebar is complete
setTimeout(() => this.resize(), THUMBNAILS_SIDEBAR_TRANSITION_TIME);
setTimeout(() => {
this.resize();
this.thumbnailsSidebarEl.style = style;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like setting style directly as a string is discouraged (https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style#Setting_styles).

Also, does this affect the animation transition at all?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does appear to affect the hidden -> visible transition. I'll update it to remove the display: none immediately rather than via setTimeout for that case. Good catch!

}, THUMBNAILS_SIDEBAR_TRANSITION_TIME);
}

/**
Expand Down