Skip to content

Commit b27f9b7

Browse files
authored
Allow any ARIA role attribute/prop (#5601)
* Allow any role * Allow role of string * Fix propTypes * Remove obsoleted tests
1 parent 847e900 commit b27f9b7

File tree

6 files changed

+48
-79
lines changed

6 files changed

+48
-79
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ Notes: web developers are advised to use [`~` (tilde range)](https://github.com/
142142
- Bundling vendor chunks, by [@compulim](https://github.com/compulim) in PR [#5595](https://github.com/microsoft/BotFramework-WebChat/pull/5595)
143143
- Added deprecation notes for legacy imports, by [@compulim](https://github.com/compulim) in PR [#5600](https://github.com/microsoft/BotFramework-WebChat/pull/5600)
144144
- `import { hooks } from 'botframework-webchat'` should be replaced by `import * as hooks from 'botframework-webchat/hook'`
145+
- Relaxed `role` prop to allow any string instead of ARIA landmark roles, in PR [#5561](https://github.com/microsoft/BotFramework-WebChat/pull/5561), by [@compulim](https://github.com/compulim)
145146

146147
### Changed
147148

__tests__/html2/accessibility/landmarkRole/invalid.html

Lines changed: 0 additions & 32 deletions
This file was deleted.

__tests__/html2/accessibility/landmarkRole/valid.html

Lines changed: 0 additions & 30 deletions
This file was deleted.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<!doctype html>
2+
<html lang="en-US">
3+
<head>
4+
<link href="/assets/index.css" rel="stylesheet" type="text/css" />
5+
</head>
6+
<body>
7+
<main id="webchat"></main>
8+
<script type="importmap">
9+
{
10+
"imports": {
11+
"botframework-webchat": "/__dist__/packages/bundle/static/botframework-webchat.js",
12+
"react": "/__dist__/packages/bundle/static/react.baseline.js",
13+
"react-dom": "/__dist__/packages/bundle/static/react-dom.baseline.js"
14+
}
15+
}
16+
</script>
17+
<script type="module">
18+
import '/test-harness.mjs';
19+
import '/test-page-object.mjs';
20+
21+
import { createDirectLine, createStoreWithOptions, renderWebChat } from 'botframework-webchat';
22+
import { version } from 'react';
23+
24+
run(async function () {
25+
const {
26+
testHelpers: { createDirectLineEmulator }
27+
} = window;
28+
29+
// TODO: This is for `createDirectLineEmulator` only, should find ways to eliminate this line.
30+
window.WebChat = { createStoreWithOptions };
31+
32+
const { directLine, store } = createDirectLineEmulator();
33+
34+
renderWebChat({ directLine, role: 'application', store }, document.getElementById('webchat'));
35+
36+
await pageConditions.uiConnected();
37+
38+
expect(document.querySelector('#webchat .webchat__surface').getAttribute('role')).toBe('application');
39+
});
40+
</script>
41+
</body>
42+
</html>

packages/component/src/BasicWebChat.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { validateProps } from '@msinternal/botframework-webchat-react-valibot';
55
import { SendBoxMiddlewareProxy, hooks } from 'botframework-webchat-api';
66
import classNames from 'classnames';
77
import React, { memo } from 'react';
8-
import { fallback, literal, object, optional, pipe, readonly, string, union, type InferInput } from 'valibot';
8+
import { object, optional, pipe, readonly, string, type InferInput } from 'valibot';
99

1010
import BasicConnectivityStatus from './BasicConnectivityStatus';
1111
import BasicToaster from './BasicToaster';
@@ -42,14 +42,7 @@ const TRANSCRIPT_STYLE = {
4242
const basicWebChatPropsSchema = pipe(
4343
object({
4444
className: optional(string()),
45-
role: fallback(
46-
optional(
47-
// Subset of landmark roles: https://w3.org/TR/wai-aria/#landmark_roles
48-
union([literal('complementary'), literal('contentinfo'), literal('form'), literal('main'), literal('region')])
49-
),
50-
// Fallback to "complementary" if specified is not a valid landmark role.
51-
'complementary'
52-
)
45+
role: optional(string())
5346
}),
5447
readonly()
5548
);

packages/component/src/ReactWebChat.tsx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,10 @@ import Composer, { ComposerProps } from './Composer';
1212
// - They can run hooks outside of activity/attachment middleware
1313
// - They will put <Composer> as very top of their page, and allow buttons on their existing page to send message to bot
1414

15-
// Subset of landmark roles: https://w3.org/TR/wai-aria/#landmark_roles
16-
const ARIA_LANDMARK_ROLES = ['complementary', 'contentinfo', 'form', 'main', 'region'];
17-
1815
type ReactWebChatProps = Readonly<
1916
Omit<ComposerProps, 'children'> & {
20-
className?: string;
21-
role?: 'complementary' | 'contentinfo' | 'form' | 'main' | 'region';
17+
className?: string | undefined;
18+
role?: string | undefined;
2219
}
2320
>;
2421

@@ -42,9 +39,7 @@ const {
4239

4340
ReactWebChat.propTypes = {
4441
className: PropTypes.string,
45-
// Ignoring deficiencies with TypeScript/PropTypes inference.
46-
// @ts-ignore
47-
role: PropTypes.oneOf(ARIA_LANDMARK_ROLES),
42+
role: PropTypes.string,
4843
...composerPropTypesWithoutChildren
4944
};
5045

0 commit comments

Comments
 (0)