Skip to content

Commit 3d4881a

Browse files
OEvgenyEugene Olonov
andauthored
Give Fluent suggested actions a solid background in forced colors (#5935)
* Fluent: give suggested actions a ButtonFace background in forced colors * Add PR number to changelog * Move the changelog entry to .changelog/ --------- Co-authored-by: Eugene Olonov <eugeneolonov@microsoft.com>
1 parent 2c28a27 commit 3d4881a

6 files changed

Lines changed: 137 additions & 0 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
### Fixed
2+
3+
- Fixed Fluent suggested actions showing the page background through them in forced colors, in PR [#5935](https://github.com/microsoft/BotFramework-WebChat/pull/5935), by [@OEvgeny](https://github.com/OEvgeny)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<script>
5+
location = './suggestedActions.forcedColors?fluent-theme=dark';
6+
</script>
7+
</head>
8+
<body></body>
9+
</html>
14.1 KB
Loading
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
<!doctype html>
2+
<html lang="en-US">
3+
<head>
4+
<link href="/assets/index.css" rel="stylesheet" type="text/css" />
5+
<style>
6+
/* The host page has a background image and shows it through Web Chat. */
7+
body {
8+
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='8'%3E%3Cpath d='M0 8L8 0' stroke='%23808080' stroke-width='2'/%3E%3C/svg%3E");
9+
}
10+
11+
#webchat {
12+
background-color: transparent;
13+
}
14+
15+
.fui-FluentProvider {
16+
height: 100%;
17+
}
18+
</style>
19+
</head>
20+
<body>
21+
<main id="webchat"></main>
22+
<script type="importmap">
23+
{
24+
"imports": {
25+
"@fluentui/react-provider": "/__dist__/packages/test/test-assets/out/@fluentui/react-provider.js",
26+
"@fluentui/tokens": "/__dist__/packages/test/test-assets/out/@fluentui/tokens.js",
27+
"botframework-webchat": "/__dist__/packages/bundle/static/botframework-webchat.js",
28+
"botframework-webchat/": "/__dist__/packages/bundle/static/botframework-webchat/",
29+
"botframework-webchat-fluent-theme": "/__dist__/packages/fluent-theme/static/botframework-webchat-fluent-theme.js",
30+
"react": "/__dist__/packages/bundle/static/react.js",
31+
"react-dom": "/__dist__/packages/bundle/static/react-dom.js",
32+
"react-dom/client": "/__dist__/packages/bundle/static/react-dom/client.js",
33+
"react-jsx-runtime": "/__dist__/packages/bundle/static/react/jsx-runtime.js"
34+
}
35+
}
36+
</script>
37+
<script type="module">
38+
import '/test-harness.mjs';
39+
import '/test-page-object.mjs';
40+
41+
import { FluentProvider } from '@fluentui/react-provider';
42+
import { webDarkTheme } from '@fluentui/tokens';
43+
import { createStoreWithOptions, ReactWebChat } from 'botframework-webchat';
44+
import { FluentThemeProvider, testIds } from 'botframework-webchat-fluent-theme';
45+
import { createElement } from 'react';
46+
import { createRoot } from 'react-dom/client';
47+
48+
// TODO: This is for `createDirectLineEmulator` only, should find ways to eliminate this line.
49+
window.WebChat = { createStoreWithOptions };
50+
51+
run(async function () {
52+
const colorScheme = new URLSearchParams(location.search).get('fluent-theme') === 'dark' ? 'dark' : 'light';
53+
54+
// GIVEN: A light or dark high contrast theme (such as "Desert" or "Aquatic" on Windows) is active before Web Chat renders.
55+
await host.sendDevToolsCommand('Emulation.setEmulatedMedia', {
56+
features: [
57+
{ name: 'forced-colors', value: 'active' },
58+
{ name: 'prefers-color-scheme', value: colorScheme },
59+
{ name: 'prefers-reduced-motion', value: 'reduce' }
60+
]
61+
});
62+
63+
expect(window.matchMedia(`(forced-colors: active) and (prefers-color-scheme: ${colorScheme})`).matches).toBe(
64+
true
65+
);
66+
67+
const { directLine, store } = testHelpers.createDirectLineEmulator();
68+
69+
const webChatElement = createElement(
70+
FluentThemeProvider,
71+
{ variant: 'fluent' },
72+
createElement(ReactWebChat, { directLine, store })
73+
);
74+
75+
// GIVEN: With a dark color scheme, the page uses the dark Fluent UI theme.
76+
createRoot(document.getElementById('webchat')).render(
77+
colorScheme === 'dark'
78+
? createElement(
79+
FluentProvider,
80+
{ style: { backgroundColor: 'transparent' }, theme: webDarkTheme }, // Also shows the background image.
81+
webChatElement
82+
)
83+
: webChatElement
84+
);
85+
86+
await pageConditions.uiConnected();
87+
88+
// WHEN: The bot sends a message with 2 suggested actions.
89+
await directLine.emulateIncomingActivity({
90+
suggestedActions: {
91+
actions: [
92+
{ title: 'Checklist', type: 'imBack', value: 'Checklist' },
93+
{ title: 'Benefits overview', type: 'imBack', value: 'Benefits overview' }
94+
],
95+
to: []
96+
},
97+
text: 'What would you like to do next?',
98+
type: 'message'
99+
});
100+
101+
await pageConditions.numActivitiesShown(1);
102+
103+
// THEN: Both suggested actions should be shown.
104+
await expect(
105+
Promise.all(
106+
Array.from(document.querySelectorAll(`[data-testid="${testIds.sendBoxSuggestedAction}"]`)).map(element =>
107+
testHelpers.getAccessibleName(element)
108+
)
109+
)
110+
).resolves.toEqual(['Checklist', 'Benefits overview']);
111+
112+
// THEN: Both suggested actions should have a solid button background, the background image should not show through them.
113+
await host.snapshot('local');
114+
});
115+
</script>
116+
</body>
117+
</html>
13.9 KB
Loading

‎packages/fluent-theme/src/components/suggestedActions/SuggestedAction.module.css‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@
2727
color: var(--webchat-colorNeutralForegroundDisabled);
2828
cursor: not-allowed;
2929
}
30+
31+
/* Forced colors keep a transparent background transparent, so the host page would show through the button. */
32+
@media (forced-colors: active) {
33+
&,
34+
&:not([aria-disabled='true']):is(:active, :hover) {
35+
background-color: ButtonFace;
36+
}
37+
}
3038
}
3139

3240
:global(.webchat-fluent) .suggested-action__image {

0 commit comments

Comments
 (0)