From 6ccad53796f4f570df00247e8e38608fcdff127c Mon Sep 17 00:00:00 2001 From: Ed Schiebel Date: Wed, 7 Aug 2019 16:19:35 -0400 Subject: [PATCH] return focus to the status bar buttons when the kb shortcut dialog or the a11y checker tray close, return focus to the button that opened it. closes COREFE-108 test plan: - in rce, click on the kb short cutton in the status bar - close the kb shortcut dialog > expect focus to return to the button - repeat for the a11y checker - tab until the show-on-focus kb shortcut button above the RCE appears, click it, then close the dialog > expect focus to return to the button Change-Id: I27ea79930e643d9908a784fbcb89900918d3be01 Reviewed-on: https://gerrit.instructure.com/204283 Tested-by: Jenkins Reviewed-by: Clay Diffrient QA-Review: Clay Diffrient Product-Review: Ed Schiebel --- package.json | 4 +++- packages/canvas-rce/src/rce/RCEWrapper.js | 20 +++++++++++-------- packages/canvas-rce/src/rce/StatusBar.js | 2 +- .../canvas-rce/test/module/RCEWrapper.test.js | 10 ++++++---- yarn.lock | 6 +++--- 5 files changed, 25 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index 2dc63db9c60..988e9cf2d57 100644 --- a/package.json +++ b/package.json @@ -233,7 +233,9 @@ "optionalDependencies": { "inspect-process": "^0.5" }, - "browserslist": ["extends @instructure/browserslist-config-canvas-lms"], + "browserslist": [ + "extends @instructure/browserslist-config-canvas-lms" + ], "jest-junit": { "output": "./coverage-js/junit-reports/jest.xml" }, diff --git a/packages/canvas-rce/src/rce/RCEWrapper.js b/packages/canvas-rce/src/rce/RCEWrapper.js index 706e6ba5c37..a2a64ad3a37 100644 --- a/packages/canvas-rce/src/rce/RCEWrapper.js +++ b/packages/canvas-rce/src/rce/RCEWrapper.js @@ -137,6 +137,7 @@ class RCEWrapper extends React.Component { this.indicator = false; this._elementRef = null; + this._showOnFocusButton = null; injectTinySkin() @@ -278,14 +279,14 @@ class RCEWrapper extends React.Component { return editors.filter(ed => ed.id === this.props.textareaId)[0]; } - onTinyMCEInstance(command) { - if (command == "mceRemoveEditor") { - let editor = this.mceInstance(); - if (editor) { + onTinyMCEInstance(command, args) { + const editor = this.mceInstance(); + if (editor) { + if (command == "mceRemoveEditor") { editor.execCommand("mceNewDocument"); } // makes sure content can't persist past removal + editor.execCommand(command, false, this.props.textareaId, args); } - this.props.tinymce.execCommand(command, false, this.props.textareaId); } destroy() { @@ -552,7 +553,7 @@ class RCEWrapper extends React.Component { } onA11yChecker = () => { - this.onTinyMCEInstance('openAccessibilityChecker', {'data-canvas-component': true}) + this.onTinyMCEInstance('openAccessibilityChecker', {skip_focus: true}) } handleShortcutKeyShortcut = (event) => { @@ -572,8 +573,10 @@ class RCEWrapper extends React.Component { } KBShortcutModalClosed = () => { - if(Bridge.activeEditor() === this) { - Bridge.focusActiveEditor(false) + // when the modal is opened from the showOnFocus button, focus doesn't + // get automatically returned to the button like it should. + if (this._showOnFocusButton && document.activeElement === document.body) { + this._showOnFocusButton.focus() } } @@ -710,6 +713,7 @@ class RCEWrapper extends React.Component { icon: IconKeyboardShortcutsLine, margin: 'xx-small' }} + ref={el => this._showOnFocusButton = el} > {{formatMessage('View keyboard shortcuts')}} diff --git a/packages/canvas-rce/src/rce/StatusBar.js b/packages/canvas-rce/src/rce/StatusBar.js index 2de2c480a51..71ca273592f 100644 --- a/packages/canvas-rce/src/rce/StatusBar.js +++ b/packages/canvas-rce/src/rce/StatusBar.js @@ -111,7 +111,7 @@ export default function StatusBar(props) { > {kbshortcut} -