Skip to content

Commit

Permalink
Make scrollable focusable
Browse files Browse the repository at this point in the history
  • Loading branch information
compulim committed Nov 15, 2024
1 parent 6219651 commit fe5079c
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 6 deletions.
Binary file modified __tests__/html2/markdown/math/layout.4.html.snap-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified __tests__/html2/markdown/math/layout.4.html.snap-3.png
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.
40 changes: 39 additions & 1 deletion __tests__/html2/markdown/math/layout.scroll.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
const {
Fluent: { createDarkTheme, createLightTheme, FluentProvider },
ReactDOMClient: { createRoot },
WebChat: { FluentThemeProvider, ReactWebChat }
WebChat: { FluentThemeProvider, ReactWebChat, testIds }
} = window; // Imports in UMD fashion.

const { directLine, store } = testHelpers.createDirectLineEmulator();
Expand Down Expand Up @@ -77,6 +77,44 @@
await pageConditions.numActivitiesShown(1);

await host.snapshot('local');

// WHEN: Press ENTER over the activity.
document.querySelector(`#webchat [data-testid="${testIds.sendBoxTextBox}"]`).focus();

await host.sendShiftTab(
(searchParams.get('variant') === 'copilot' || searchParams.get('variant') === 'fluent') ? 2 : 3
);
await host.sendKeys('ENTER');

// THEN: Should focus on the first <figure>.
expect(document).toHaveProperty(
'activeElement',
pageElements.activityContents()[0].querySelectorAll('figure')[0]
);
// expect(document).toHaveProperty('activeElement.tagName', 'FIGURE');
await host.snapshot('local');

// ----------------------------------------

// WHEN: Press RIGHT key.
await host.sendKeys('RIGHT');

// THEN: Should scroll to the right.
await pageConditions.became('should scroll to the right', () => document.activeElement.scrollLeft > 10, 1000);
await pageConditions.stabilized('should finish scrolling', () => document.activeElement.scrollLeft, 5, 1000);
await host.snapshot('local');

// ----------------------------------------

// WHEN: Press TAB key.
await host.sendKeys('TAB');

// THEN: Should focus on the second <figure>.
expect(document).toHaveProperty(
'activeElement',
pageElements.activityContents()[0].querySelectorAll('figure')[1]
);
await host.snapshot('local');
});
</script>
</body>
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.
3 changes: 2 additions & 1 deletion packages/bundle/src/markdown/mathExtension/htmlRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ export default function createHtmlRenderer(options: CreateHtmlRendererOptions =
type: 'block' | 'inline' | 'error' = defaults.type,
tag: 'figure' | 'span' | 'pre' | 'code' = defaults.tag
) => {
this.tag(`<${tag} data-math-type="${type}">`);
// Math could be scrollable, need to be tabbable.
this.tag(`<${tag} data-math-type="${type}" tabindex="0">`);
this.raw(content);
this.tag(`</${tag}>`);
};
Expand Down
4 changes: 2 additions & 2 deletions packages/component/src/Styles/StyleSet/RenderMarkdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export default function createMarkdownStyle() {
content: "'['"
},

'& [data-math-type=block] math': {
'& [data-math-type=block]': {
alignItems: 'center',
display: 'flex',
flexDirection: 'column',
Expand All @@ -76,7 +76,7 @@ export default function createMarkdownStyle() {
scrollbarWidth: 'thin'
},

'& [data-math-type=inline] math': {
'& [data-math-type=inline]': {
alignItems: 'center',
display: 'inline-flex',
flexDirection: 'column'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const DEFAULT_ALLOWED_TAGS: ReadonlyMap<string, Readonly<{ attributes: ReadonlyS
['del', []],
['div', []],
['em', []],
['figure', ['data-math-type']],
['figure', ['data-math-type', 'tabindex']],
['h1', []],
['h2', []],
['h3', []],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@
/* Scrollbars */
:global(.webchat-fluent).theme :global(.webchat__basic-transcript .webchat__basic-transcript__scrollable),
:global(.webchat-fluent).theme :global(.webchat__view-code-dialog__code-body),
:global(.webchat-fluent).theme :global(.webchat__render-markdown [data-math-type='block'] math) {
:global(.webchat-fluent).theme :global(.webchat__render-markdown [data-math-type='block']) {
/* Edge uses -webkit-scrollbar if scrollbar-* is not set */
scrollbar-color: unset;
scrollbar-width: unset;
Expand Down

0 comments on commit fe5079c

Please sign in to comment.