Skip to content

Commit

Permalink
Focus on the close button of keyboard help screen (#4479)
Browse files Browse the repository at this point in the history
* Focus on the close button

* Add entry

* Transpile bent to ES5

* Make SVGs non-focusable in IE11

* Add entry

* Update comment

* Update snapshot
  • Loading branch information
compulim authored Nov 15, 2022
1 parent 4e87e38 commit b544650
Show file tree
Hide file tree
Showing 34 changed files with 358 additions and 13 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fixes [#4472](https://github.com/microsoft/BotFramework-WebChat/issues/4472). Removed `role` attributes for notification bar and use `<div>` instead of `<ul>`/`<li>`, by [@compulim](https://github.com/compulim) in PR [#4475](https://github.com/microsoft/BotFramework-WebChat/pull/4475)
- Fixes [#4393](https://github.com/microsoft/BotFramework-WebChat/issues/4393). Renders `<section role="feed">` only if there are one or more activities contained within, by [@beyackle2](https://github.com/beyackle2) and [@compulim](https://github.com/compulim), in PR [#4420](https://github.com/microsoft/BotFramework-WebChat/pull/4420)
- Fixes [#4473](https://github.com/microsoft/BotFramework-WebChat/issues/4473). Bumped `strip-ansi@6.0.1` for `test-harness` as `@^7` does not support CommonJS project, by [@compulim](https://github.com/compulim) in PR [#4474](https://github.com/microsoft/BotFramework-WebChat/pull/4474)
- Fixes [#4476](https://github.com/microsoft/BotFramework-WebChat/issues/4476). When focus on the keyboard help screen, it should focus on the close button, by [@compulim](https://github.com/compulim) in PR [#4479](https://github.com/microsoft/BotFramework-WebChat/pull/4479)
- Fixes [#4442](https://github.com/microsoft/BotFramework-WebChat/issues/4442). Change the keyboard help screen string "Leave message" to "Exit message", by [@compulim](https://github.com/compulim) in PR [#4479](https://github.com/microsoft/BotFramework-WebChat/pull/4479)

### Changed

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
64 changes: 64 additions & 0 deletions __tests__/html/accessibility.keyboardHelp.clickCloseButton.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<!DOCTYPE html>
<html lang="en-US">
<head>
<link href="/assets/index.css" rel="stylesheet" type="text/css" />
<script crossorigin="anonymous" src="/test-harness.js"></script>
<script crossorigin="anonymous" src="/test-page-object.js"></script>
<script crossorigin="anonymous" src="/__dist__/webchat-es5.js"></script>
</head>
<body>
<div id="webchat"></div>
<script>
run(async function () {
const store = testHelpers.createStore();

const directLine = testHelpers.createDirectLineEmulator(store);

WebChat.renderWebChat({ directLine, store }, document.getElementById('webchat'));

await pageConditions.uiConnected();

// SETUP: With 2 bot messages.
await directLine.emulateIncomingActivity('Hello, World!');
await directLine.emulateIncomingActivity('Aloha!');
await pageConditions.numActivitiesShown(2);

// THEN: The focus should be on `document.body` initially.
await pageConditions.focusOn(document.body, 'document body');

// THEN: The keyboard help screeen should not be visible initially.
await host.snapshot();

// ---

// WHEN: TAB key is pressed.
await host.sendTab();

// THEN: It should focus on the close button.
await pageConditions.focusOn(pageElements.keyboardHelpScreenCloseButton(), 'keyboard help screen close button');

// THEN: The keyboard help screeen show be visible.
await host.snapshot();

// ---

// WHEN: SPACE BAR is pressed while the focus is on the close button.
await host.sendKeys(' ');

// THEN: It should focus on the chat history.
await pageConditions.focusOn(pageElements.transcript(), 'chat history');

// THEN: It should focus on the last message in the chat history.
await pageConditions.became(
'focus on the last message',
() => pageElements.focusedActivity() === pageElements.activities()[1],
1000
);

// THEN: The keyboard help screeen show be closed (not visible).
// The chat history and the last message should be focused.
await host.snapshot();
});
</script>
</body>
</html>
6 changes: 6 additions & 0 deletions __tests__/html/accessibility.keyboardHelp.clickCloseButton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/** @jest-environment ./packages/test/harness/src/host/jest/WebDriverEnvironment.js */

describe('keyboard help screen', () => {
test('should close when the close button is clicked', () =>
runHTML('accessibility.keyboardHelp.clickCloseButton'));
});
74 changes: 74 additions & 0 deletions __tests__/html/accessibility.keyboardHelp.clickThru.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<!DOCTYPE html>
<html lang="en-US">
<head>
<link href="/assets/index.css" rel="stylesheet" type="text/css" />
<script crossorigin="anonymous" src="/test-harness.js"></script>
<script crossorigin="anonymous" src="/test-page-object.js"></script>
<script crossorigin="anonymous" src="/__dist__/webchat-es5.js"></script>
</head>
<body>
<div id="webchat"></div>
<script>
run(async function () {
const store = testHelpers.createStore();

const directLine = testHelpers.createDirectLineEmulator(store);

WebChat.renderWebChat({ directLine, store }, document.getElementById('webchat'));

await pageConditions.uiConnected();

// SETUP: With 2 bot messages.
await directLine.emulateIncomingActivity('Hello, World!');
await directLine.emulateIncomingActivity('Aloha!');
await pageConditions.numActivitiesShown(2);

// THEN: The focus should be on `document.body` initially.
await pageConditions.focusOn(document.body, 'document body');

// THEN: The keyboard help screeen should not be visible initially.
await host.snapshot();

// ---

// WHEN: TAB key is pressed.
await host.sendTab();

// THEN: It should focus on the close button.
await pageConditions.focusOn(pageElements.keyboardHelpScreenCloseButton(), 'keyboard help screen close button');

// THEN: The keyboard help screeen show be visible.
await host.snapshot();

// ---

// WHEN: Click to focus on the send box text box.
await host.click(pageElements.sendBoxTextBox());
await pageConditions.focusOn(pageElements.sendBoxTextBox(), 'send box text box');

// THEN: The keyboard help screen should not be visible.
await host.snapshot();

// ---

// WHEN: Click on the first message.
await host.click(pageElements.activities()[0]);

// THEN: It should focus on the chat history.
// The invisible keyboard help screen should not block clicks.
await pageConditions.focusOn(pageElements.transcript(), 'chat history');

// THEN: It should focus on the first message in the chat history.
await pageConditions.became(
'focus on the first activity',
() => pageElements.focusedActivity() === pageElements.activities()[0],
1000
);

// THEN: The keyboard help screeen should not be visible.
// The chat history and the first message should be focused.
await host.snapshot();
});
</script>
</body>
</html>
6 changes: 6 additions & 0 deletions __tests__/html/accessibility.keyboardHelp.clickThru.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/** @jest-environment ./packages/test/harness/src/host/jest/WebDriverEnvironment.js */

describe('keyboard help screen', () => {
test('should not interfere when clicking on activities', () =>
runHTML('accessibility.keyboardHelp.clickThru'));
});
57 changes: 57 additions & 0 deletions __tests__/html/accessibility.keyboardHelp.escapeKey.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<!DOCTYPE html>
<html lang="en-US">
<head>
<link href="/assets/index.css" rel="stylesheet" type="text/css" />
<script crossorigin="anonymous" src="/test-harness.js"></script>
<script crossorigin="anonymous" src="/test-page-object.js"></script>
<script crossorigin="anonymous" src="/__dist__/webchat-es5.js"></script>
</head>
<body>
<div id="webchat"></div>
<script>
run(async function () {
const store = testHelpers.createStore();

const directLine = testHelpers.createDirectLineEmulator(store);

WebChat.renderWebChat({ directLine, store }, document.getElementById('webchat'));

await pageConditions.uiConnected();

// SETUP: With 2 bot messages.
await directLine.emulateIncomingActivity('Hello, World!');
await directLine.emulateIncomingActivity('Aloha!');
await pageConditions.numActivitiesShown(2);

// THEN: The focus should be on `document.body` initially.
await pageConditions.focusOn(document.body, 'document body');

// THEN: The keyboard help screeen should not be visible initially.
await host.snapshot();

// ---

// WHEN: TAB key is pressed.
await host.sendTab();

// THEN: It should focus on the close button.
await pageConditions.focusOn(pageElements.keyboardHelpScreenCloseButton(), 'keyboard help screen close button');

// THEN: The keyboard help screeen show be visible.
await host.snapshot();

// ---

// WHEN: ESCAPE key is pressed.
await host.sendKeys('ESCAPE');

// THEN: It should focus on the chat history.
await pageConditions.focusOn(pageElements.transcript(), 'chat history');

// THEN: It should close the keyboard help screen.
// The chat history and the last message should be focused.
await host.snapshot();
});
</script>
</body>
</html>
6 changes: 6 additions & 0 deletions __tests__/html/accessibility.keyboardHelp.escapeKey.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/** @jest-environment ./packages/test/harness/src/host/jest/WebDriverEnvironment.js */

describe('keyboard help screen', () => {
test('should close when ESCAPE key is pressed', () =>
runHTML('accessibility.keyboardHelp.escapeKey'));
});
87 changes: 87 additions & 0 deletions __tests__/html/accessibility.keyboardHelp.tabKey.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<!DOCTYPE html>
<html lang="en-US">
<head>
<link href="/assets/index.css" rel="stylesheet" type="text/css" />
<script crossorigin="anonymous" src="/test-harness.js"></script>
<script crossorigin="anonymous" src="/test-page-object.js"></script>
<script crossorigin="anonymous" src="/__dist__/webchat-es5.js"></script>
</head>
<body>
<div id="webchat"></div>
<script>
run(async function () {
const store = testHelpers.createStore();

const directLine = testHelpers.createDirectLineEmulator(store);

WebChat.renderWebChat({ directLine, store }, document.getElementById('webchat'));

await pageConditions.uiConnected();

// SETUP: With 2 bot messages.
await directLine.emulateIncomingActivity('Hello, World!');
await directLine.emulateIncomingActivity('Aloha!');
await pageConditions.numActivitiesShown(2);

// THEN: The focus should be on `document.body` initially.
await pageConditions.focusOn(document.body, 'document body');

// THEN: The keyboard help screeen should not be visible initially.
await host.snapshot();

// ---

// WHEN: TAB key is pressed.
await host.sendTab();

// THEN: It should focus on the close button.
await pageConditions.focusOn(pageElements.keyboardHelpScreenCloseButton(), 'keyboard help screen close button');

// THEN: The keyboard help screeen show be visible.
await host.snapshot();

// ---

// WHEN: TAB key is pressed.
await host.sendTab();

// THEN: It should focus on the chat history.
await pageConditions.focusOn(pageElements.transcript(), 'chat history');

// THEN: It should focus on the last message in the chat history.
await pageConditions.became(
'focus on the last message',
() => pageElements.focusedActivity() === pageElements.activities()[1],
1000
);

// THEN: The keyboard help screeen show be closed (not visible).
// The chat history and the last message should be focused.
await host.snapshot();

// ---

// WHEN: SHIFT-TAB key is pressed.
await host.sendShiftTab();

// THEN: It should focus on the close button.
await pageConditions.focusOn(pageElements.keyboardHelpScreenCloseButton(), 'keyboard help screen close button');

// THEN: The keyboard help screeen show be visible.
await host.snapshot();

// ---

// WHEN: SHIFT-TAB key is pressed while the keyboard help screen is visible.
await host.sendShiftTab();

// THEN: It should focus on the document body.
await pageConditions.focusOn(document.body, 'document body');

// THEN: The keyboard help screeen show be closed (not visible).
// As the focus is on document body, nothing in view should have focus ring.
await host.snapshot();
});
</script>
</body>
</html>
6 changes: 6 additions & 0 deletions __tests__/html/accessibility.keyboardHelp.tabKey.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/** @jest-environment ./packages/test/harness/src/host/jest/WebDriverEnvironment.js */

describe('keyboard help screen', () => {
test('should close when TAB away and show when TAB back', () =>
runHTML('accessibility.keyboardHelp.tabKey'));
});
3 changes: 2 additions & 1 deletion packages/api/src/localization/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@
"KEYBOARD_HELP_CHAT_HISTORY_ACCESS_ITEMS_IN_MESSAGE_HEADER": "Access items in message",
"KEYBOARD_HELP_CHAT_HISTORY_HEADER": "Chat history",
"KEYBOARD_HELP_CHAT_HISTORY_LEAVE_MESSAGE_BODY": "Escape key",
"KEYBOARD_HELP_CHAT_HISTORY_LEAVE_MESSAGE_HEADER": "Leave message",
"KEYBOARD_HELP_CHAT_HISTORY_LEAVE_MESSAGE_HEADER": "Exit message",
"_KEYBOARD_HELP_CHAT_HISTORY_LEAVE_MESSAGE_HEADER.comment": "While focus is on the message, when the user press ESCAPE key, it should exit the message focus mode and focus back on the text box in the send box.",
"KEYBOARD_HELP_CHAT_HISTORY_MOVE_BETWEEN_ITEMS_BODY": "Tab key\nShift + tab key",
"KEYBOARD_HELP_CHAT_HISTORY_MOVE_BETWEEN_ITEMS_HEADER": "Move between items in a message",
"KEYBOARD_HELP_CHAT_HISTORY_MOVE_BETWEEN_MESSAGES_BODY": "Arrow up key\nArrow down key",
Expand Down
2 changes: 1 addition & 1 deletion packages/bundle/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ let config = {
rules: [
{
// To speed up bundling, we are limiting Babel to a number of packages which does not publish ES5 bits.
test: /\/node_modules\/(botframework-streaming|buffer|nanoid|postcss|punycode|sanitize-html)\//iu,
test: /\/node_modules\/(bent|botframework-streaming|buffer|nanoid|postcss|punycode|sanitize-html)\//iu,
use: {
loader: 'babel-loader',
options: {
Expand Down
1 change: 1 addition & 0 deletions packages/component/src/Styles/StyleSet/KeyboardHelp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export default function createKeyboardHelpStyleSet({ paddingRegular, primaryFont
borderWidth: 2,
color: '#999',
height: 34,
outline: 0,
padding: 0,
position: 'absolute',
right: paddingRegular,
Expand Down
Loading

0 comments on commit b544650

Please sign in to comment.