Skip to content

Commit 533c151

Browse files
OEvgenycompulim
andauthored
Fluent: integrate webchat focus management (#5150)
* Fluent: focus management integration * Self review * Update use-propagate * Remove deprecated functionality * Update test to use useFocus() hook * Fix: itemEffector should pass cleanup callbacks * Update changelog * Fix changelog * Update wordings --------- Co-authored-by: William Wong <[email protected]>
1 parent 73ee44a commit 533c151

27 files changed

+230
-114
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
2929
- `useSuggestedActions` type is updated to align with its actual implementation, by [@OEvgeny](https://github.com/OEvgeny), in PR [#5122](https://github.com/microsoft/BotFramework-WebChat/pull/5122)
3030
- Removed deprecated code: `connect*`, `useRenderActivity`, `useRenderActivityStatus`, `useRenderAvatar`, in PR [#5148](https://github.com/microsoft/BotFramework-WebChat/pull/5148), by [@compulim](https://github.com/compulim)
3131
- Added named exports in both CommonJS and ES Modules module format, in PR [#5148](https://github.com/microsoft/BotFramework-WebChat/pull/5148), by [@compulim](https://github.com/compulim)
32+
- Removed deprecated `useFocusSendBox()` hook, please use `useFocus('sendBox')` instead, in PR [#5150](https://github.com/microsoft/BotFramework-WebChat/pull/5150), by [@OEvgeny](https://github.com/OEvgeny)
3233

3334
### Added
3435

@@ -53,6 +54,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
5354
- Added dark theme support, in PR [#5138](https://github.com/microsoft/BotFramework-WebChat/pull/5138)
5455
- Added an information message to the telephone keypad, in PR [#5140](https://github.com/microsoft/BotFramework-WebChat/pull/5140)
5556
- Added animation to focus indicator and pixel-perfected, in PR [#5143](https://github.com/microsoft/BotFramework-WebChat/pull/5143)
57+
- Integrated focus management for send box, in PR [#5150](https://github.com/microsoft/BotFramework-WebChat/pull/5150), by [@OEvgeny](https://github.com/OEvgeny)
5658
- (Experimental) Added `<LocalizeString />` component which can be used to localize strings, by [@OEvgeny](https://github.com/OEvgeny) in PR [#5140](https://github.com/microsoft/BotFramework-WebChat/pull/5140)
5759
- Added `<ThemeProvider>` component to apply theme pack to Web Chat, by [@compulim](https://github.com/compulim), in PR [#5120](https://github.com/microsoft/BotFramework-WebChat/pull/5120)
5860
- Added `useMakeThumbnail` hook option to create a thumbnail from the file given, by [@compulim](https://github.com/compulim), in PR [#5123](https://github.com/microsoft/BotFramework-WebChat/pull/5123) and [#5122](https://github.com/microsoft/BotFramework-WebChat/pull/5122)
@@ -66,6 +68,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
6668
- Fixes [#5146](https://github.com/microsoft/BotFramework-WebChat/issues/5146). Fixed chat history focus indicator should not show up on tap, by [@OEvgeny](https://github.com/OEvgeny), in PR [#5145](https://github.com/microsoft/BotFramework-WebChat/pull/5145)
6769
- Fixes type portability issues by exporting types from all exported code, in PR [#5148](https://github.com/microsoft/BotFramework-WebChat/pull/5148), by [@compulim](https://github.com/compulim)
6870
- Fixes missing exports of `useNotifications`, in PR [#5148](https://github.com/microsoft/BotFramework-WebChat/pull/5148), by [@compulim](https://github.com/compulim)
71+
- Fixes suggested actions keyboard navigation skips actions after suggested actions got updated, in PR [#5150](https://github.com/microsoft/BotFramework-WebChat/pull/5150), by [@OEvgeny](https://github.com/OEvgeny)
6972

7073
### Changed
7174

Loading
Loading
Loading

__tests__/hooks/useFocusSendBox.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ test('calling emitTypingIndicator should send a typing activity', async () => {
1313

1414
await driver.wait(uiConnected(), timeouts.directLine);
1515

16-
await pageObjects.runHook('useFocusSendBox', [], fn => fn());
16+
await pageObjects.runHook('useFocus', [], fn => fn('sendBox'));
1717

1818
await driver.wait(sendBoxTextBoxFocused(), timeouts.ui);
1919
});
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<!doctype html>
2+
<html lang="en-US">
3+
<head>
4+
<link href="/assets/index.css" rel="stylesheet" type="text/css" />
5+
<script crossorigin="anonymous" src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
6+
<script crossorigin="anonymous" src="https://unpkg.com/[email protected]/umd/react.production.min.js"></script>
7+
<script crossorigin="anonymous" src="https://unpkg.com/[email protected]/umd/react-dom.production.min.js"></script>
8+
<script crossorigin="anonymous" src="/test-harness.js"></script>
9+
<script crossorigin="anonymous" src="/test-page-object.js"></script>
10+
<script crossorigin="anonymous" src="/__dist__/webchat-es5.js"></script>
11+
<script crossorigin="anonymous" src="/__dist__/botframework-webchat-fluent-theme.production.min.js"></script>
12+
</head>
13+
<body>
14+
<main id="webchat"></main>
15+
<script type="text/babel">
16+
run(async function () {
17+
const {
18+
React,
19+
ReactDOM: { render },
20+
WebChat: { FluentThemeProvider, ReactWebChat }
21+
} = window; // Imports in UMD fashion.
22+
23+
const { directLine, store } = testHelpers.createDirectLineEmulator();
24+
25+
const App = () => (
26+
<ReactWebChat directLine={directLine} store={store} styleOptions={{ hideTelephoneKeypadButton: false }} />
27+
);
28+
29+
render(
30+
<FluentThemeProvider>
31+
<App />
32+
</FluentThemeProvider>,
33+
document.getElementById('webchat')
34+
);
35+
36+
await pageConditions.uiConnected();
37+
38+
await directLine.emulateIncomingActivity(
39+
'Eiusmod anim adipisicing cupidatat adipisicing officia sint qui consequat veniam id aute.'
40+
);
41+
42+
await pageConditions.numActivitiesShown(1);
43+
44+
document.querySelector(`[data-testid="${WebChat.testIds.sendBoxTextBox}"]`).focus();
45+
46+
// WHEN: SHIFT-TAB key is pressed.
47+
await host.sendShiftTab();
48+
49+
// THEN: Should focus on the chat history.
50+
await host.snapshot();
51+
52+
// WHEN: A key is pressed.
53+
await host.sendKeys('The quick brown fox jumps over the lazy dog');
54+
55+
// THEN: Should focus on the SendBox
56+
await host.snapshot();
57+
58+
await (await directLine.actPostActivity(() => host.sendKeys('\n'))).resolveAll();
59+
60+
// THEN: Should send the activity.
61+
await pageConditions.numActivitiesShown(2);
62+
await pageConditions.allOutgoingActivitiesSent();
63+
await host.snapshot();
64+
});
65+
</script>
66+
</body>
67+
</html>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/** @jest-environment ./packages/test/harness/src/host/jest/WebDriverEnvironment.js */
2+
3+
describe('Fluent theme applied', () => {
4+
test('focus moves back to sendbox when letter pressed', () => runHTML('fluentTheme/focusManagement.backToSendBox'));
5+
});

__tests__/html/useFocus.main.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
await pageConditions.uiConnected();
3232

3333
// WHEN: The callback of "useFocus()" is called.
34-
await renderWebChatWithHook(() => window.WebChat.hooks.useFocus()());
34+
await renderWebChatWithHook(() => Promise.resolve(window.WebChat.hooks.useFocus()).then(focus => focus()));
3535

3636
// THEN: It should focus on the (blank) transcript.
3737
await host.snapshot();

__tests__/html/useFocus.sendBox.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
);
3030

3131
await pageConditions.uiConnected();
32-
await pageObjects.runHook(({ useFocus }) => useFocus()('sendBox'));
32+
await pageObjects.runHook(({ useFocus }) => Promise.resolve(useFocus()).then(focus => focus('sendBox')));
3333

3434
await host.snapshot();
3535
});

__tests__/html/useFocus.sendBoxWithoutKeyboard.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
// Since the keyboard is controlled by the browser and OS, we cannot test if the keyboard activated or not.
3434
// This is our best-effort to check if focus is being set correctly or not.
35-
await pageObjects.runHook(({ useFocus }) => useFocus()('sendBoxWithoutKeyboard'));
35+
await pageObjects.runHook(({ useFocus }) => Promise.resolve(useFocus()).then(focus => focus('sendBoxWithoutKeyboard')));
3636

3737
await host.snapshot();
3838
});

0 commit comments

Comments
 (0)