-
Notifications
You must be signed in to change notification settings - Fork 1.6k
fix: allow focusing code block contents #5575
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
601c701
fix: focus trap escape for code block
OEvgeny 48d6ddc
rework code block focus and styling
OEvgeny 8f92c11
test: code block scroll test
OEvgeny a9383f2
Merge branch 'main' into fix/focusa-trap-escape
OEvgeny 05cebd7
Changelog
OEvgeny 0560518
snaps: part grouping
OEvgeny 3e972fd
snaps: markdownRenderHTML
OEvgeny File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file modified
BIN
-333 Bytes
(100%)
__tests__/html2/activity/collapsible.copilot.dark.html.snap-4.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
BIN
-357 Bytes
(100%)
__tests__/html2/activity/collapsible.copilot.dark.html.snap-5.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
BIN
-359 Bytes
(100%)
__tests__/html2/activity/collapsible.copilot.dark.html.snap-6.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
BIN
-352 Bytes
(100%)
__tests__/html2/activity/collapsible.copilot.dark.html.snap-7.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
BIN
-282 Bytes
(100%)
__tests__/html2/activity/collapsible.copilot.dark.html.snap-8.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
BIN
-348 Bytes
(100%)
__tests__/html2/activity/collapsible.copilot.html.snap-4.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
BIN
-346 Bytes
(100%)
__tests__/html2/activity/collapsible.copilot.html.snap-5.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
BIN
-366 Bytes
(100%)
__tests__/html2/activity/collapsible.copilot.html.snap-6.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
BIN
-341 Bytes
(100%)
__tests__/html2/activity/collapsible.copilot.html.snap-7.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
BIN
-421 Bytes
(100%)
__tests__/html2/activity/collapsible.copilot.html.snap-8.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
BIN
-218 Bytes
(100%)
__tests__/html2/activity/collapsible.fluent.dark.html.snap-4.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
BIN
-208 Bytes
(100%)
__tests__/html2/activity/collapsible.fluent.dark.html.snap-5.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
BIN
-211 Bytes
(100%)
__tests__/html2/activity/collapsible.fluent.dark.html.snap-6.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
BIN
-211 Bytes
(100%)
__tests__/html2/activity/collapsible.fluent.dark.html.snap-7.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
BIN
+179 Bytes
(100%)
__tests__/html2/activity/collapsible.fluent.dark.html.snap-8.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
BIN
-212 Bytes
(100%)
__tests__/html2/activity/collapsible.fluent.html.snap-4.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
BIN
-167 Bytes
(100%)
__tests__/html2/activity/collapsible.fluent.html.snap-5.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
BIN
-223 Bytes
(100%)
__tests__/html2/activity/collapsible.fluent.html.snap-6.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
BIN
-238 Bytes
(100%)
__tests__/html2/activity/collapsible.fluent.html.snap-7.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
BIN
+250 Bytes
(100%)
__tests__/html2/activity/collapsible.fluent.html.snap-8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,148 @@ | ||
| <!doctype html> | ||
| <html lang="en-US"> | ||
| <head> | ||
| <link href="/assets/index.css" rel="stylesheet" type="text/css" /> | ||
| <script crossorigin="anonymous" src="https://unpkg.com/@babel/standalone@7.8.7/babel.min.js"></script> | ||
| <script crossorigin="anonymous" src="https://unpkg.com/react@16.8.6/umd/react.production.min.js"></script> | ||
| <script crossorigin="anonymous" src="https://unpkg.com/react-dom@16.8.6/umd/react-dom.production.min.js"></script> | ||
| <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> | ||
| <main id="webchat"></main> | ||
| <script type="text/babel"> | ||
| run(async function () { | ||
| const { | ||
| React, | ||
| ReactDOM: { render }, | ||
| WebChat: { ReactWebChat } | ||
| } = window; // Imports in UMD fashion. | ||
|
|
||
| const aiMessageEntity = { | ||
| '@context': 'https://schema.org', | ||
| '@id': '', | ||
| '@type': 'Message', | ||
| keywords: ['AIGeneratedContent', 'AllowCopy'], | ||
| type: 'https://schema.org/Message' | ||
| }; | ||
|
|
||
| const waveSvg = `data:image/svg+xml;utf8,${encodeURIComponent(` | ||
| <svg width="400" height="200" viewBox="0 0 400 200" xmlns="http://www.w3.org/2000/svg"> | ||
| <!-- Primary Wave --> | ||
| <path d="M0,100 C50,50 100,150 150,100 C200,50 250,150 300,100 C350,50 400,150 400,100" | ||
| stroke="#3B82F6" fill="none" stroke-width="2" opacity="0.5"/> | ||
|
|
||
| <!-- Second Harmonic --> | ||
| <path d="M0,100 C25,75 50,125 75,100 C100,75 125,125 150,100 C175,75 200,125 225,100 C250,75 275,125 300,100 C325,75 350,125 375,100 C400,75 400,125 400,100" | ||
| stroke="#10B981" fill="none" stroke-width="2" opacity="0.5"/> | ||
|
|
||
| <!-- Combined Wave --> | ||
| <path d="M0,100 C40,30 80,170 120,100 C160,30 200,170 240,100 C280,30 320,170 360,100 C380,65 400,135 400,100" | ||
| stroke="#EF4444" fill="none" stroke-width="3"/> | ||
|
|
||
| <!-- Grid Lines --> | ||
| <line x1="0" y1="100" x2="400" y2="100" stroke="#CBD5E1" stroke-width="0.5" stroke-dasharray="4"/> | ||
| <line x1="100" y1="0" x2="100" y2="200" stroke="#CBD5E1" stroke-width="0.5" stroke-dasharray="4"/> | ||
| <line x1="200" y1="0" x2="200" y2="200" stroke="#CBD5E1" stroke-width="0.5" stroke-dasharray="4"/> | ||
| <line x1="300" y1="0" x2="300" y2="200" stroke="#CBD5E1" stroke-width="0.5" stroke-dasharray="4"/> | ||
| </svg>`)}`; | ||
|
|
||
| const { directLine, store } = testHelpers.createDirectLineEmulator(); | ||
|
|
||
| render( | ||
| <ReactWebChat directLine={directLine} store={store} />, | ||
| document.getElementById('webchat') | ||
| ); | ||
|
|
||
| await pageConditions.uiConnected(); | ||
|
|
||
| directLine.emulateIncomingActivity({ | ||
| from: { role: 'bot' }, | ||
| entities: [{ | ||
| ...aiMessageEntity, | ||
| isBasedOn: { | ||
| '@type': 'SoftwareSourceCode', | ||
| 'programmingLanguage': 'python', | ||
| "text": `import numpy as np | ||
| import matplotlib.pyplot as plt | ||
|
|
||
| def plot_sine_waves(): | ||
| """Create a beautiful visualization of sine waves with different frequencies.""" | ||
| # Generate time points | ||
| t = np.linspace(0, 10, 1000) | ||
|
|
||
| # Create waves with different frequencies and phases | ||
| wave1 = np.sin(t) | ||
| wave2 = 0.5 * np.sin(2 * t + np.pi/4) | ||
| wave3 = 0.3 * np.sin(3 * t + np.pi/3) | ||
|
|
||
| # Combine waves | ||
| combined = wave1 + wave2 + wave3 | ||
|
|
||
| # Create a stylish plot | ||
| plt.style.use('seaborn-darkgrid') | ||
| plt.figure(figsize=(12, 8)) | ||
|
|
||
| # Plot individual waves | ||
| plt.plot(t, wave1, label='Primary Wave', alpha=0.5) | ||
| plt.plot(t, wave2, label='Second Harmonic', alpha=0.5) | ||
| plt.plot(t, wave3, label='Third Harmonic', alpha=0.5) | ||
|
|
||
| # Plot combined wave with a thicker line | ||
| plt.plot(t, combined, 'r-', | ||
| label='Combined Wave', | ||
| linewidth=2) | ||
|
|
||
| plt.title('Harmonic Wave Composition', fontsize=14) | ||
| plt.xlabel('Time', fontsize=12) | ||
| plt.ylabel('Amplitude', fontsize=12) | ||
| plt.legend() | ||
| plt.grid(True, alpha=0.3) | ||
|
|
||
| # Show the plot | ||
| plt.tight_layout() | ||
| plt.show() | ||
|
|
||
| # Generate the visualization | ||
| plot_sine_waves()` | ||
| } | ||
| }], | ||
| type: "message", | ||
| text: `This example demonstrates creating a beautiful visualization of harmonic waves using Python's Matplotlib library. The code generates three sine waves with different frequencies and phases, then combines them to show wave interference patterns.\n<img alt="wave plot" src="${waveSvg}">`, | ||
| }); | ||
|
|
||
| await pageConditions.numActivitiesShown(1); | ||
|
|
||
| // When: Focus the "Code" button | ||
| const codeButton = document.querySelector(`[data-testid="${WebChat.testIds.viewCodeButton}"]`); | ||
| codeButton.focus(); | ||
|
|
||
| // Then: Shows a focus ring around the "Code" button | ||
| expect(document.activeElement).toBe(codeButton); | ||
|
|
||
| // WHEN: Press ENTER on the "Code" button. | ||
| await host.sendKeys('ENTER'); | ||
|
|
||
| // WHEN: Press Tab to focus copy button. | ||
| await host.sendTab(); | ||
|
|
||
| // THEN: Shows a focus ring around the "Copy" button. | ||
| await host.snapshot('local'); | ||
|
|
||
| // WHEN: Press Tab to focus code block. | ||
| await host.sendTab(); | ||
|
|
||
| // THEN: Shows a focus ring around the code block. | ||
| await host.snapshot('local'); | ||
|
|
||
| // WHEN: Press ARROW_DOWN to scroll down the code block. | ||
| await host.sendKeys('ARROW_DOWN'); | ||
| await host.sendKeys('ARROW_DOWN'); | ||
|
|
||
| // // THEN: The code block should scroll down. | ||
| await host.snapshot('local'); | ||
| }); | ||
| </script> | ||
| </body> | ||
| </html> |
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.
Binary file modified
BIN
+101 Bytes
(100%)
...sts__/html2/markdown/codeBlockCopyButton/adaptiveCards/behavior.html.snap-1.png
|
compulim marked this conversation as resolved.
|
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
BIN
+7 Bytes
(100%)
...sts__/html2/markdown/codeBlockCopyButton/adaptiveCards/behavior.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
BIN
-10 Bytes
(100%)
...sts__/html2/markdown/codeBlockCopyButton/adaptiveCards/behavior.html.snap-3.png
Oops, something went wrong.
Binary file modified
BIN
-48 Bytes
(100%)
__tests__/html2/markdown/codeBlockCopyButton/adaptiveCards/layout.html.snap-1.png
Oops, something went wrong.
Binary file modified
BIN
+8 Bytes
(100%)
__tests__/html2/markdown/codeBlockCopyButton/fluent/layout.html.snap-1.png
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
packages/component/src/Attachment/Text/private/ViewCodeDialog.module.css
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| :global(.webchat) .view-code-dialog { | ||
| box-sizing: border-box; | ||
| display: grid; | ||
| height: 100%; | ||
| max-height: 100vh; | ||
| overflow: hidden; | ||
| padding: 1rem; | ||
| place-items: center; | ||
| } | ||
|
|
||
| :global(.webchat) .view-code-dialog :global(.webchat__modal-dialog__box) { | ||
| display: flex; | ||
| flex-direction: column; | ||
| max-height: 100%; | ||
| max-width: 100%; | ||
| position: relative; | ||
| } | ||
|
|
||
| :global(.webchat) .view-code-dialog :global(.webchat__modal-dialog__close-button-layout) { | ||
| position: absolute; | ||
| right: 0; | ||
| } | ||
|
|
||
| :global(.webchat) .view-code-dialog :global(.webchat__modal-dialog__body) { | ||
| display: flex; | ||
| flex-direction: column; | ||
| gap: var(--webchat__padding--regular); | ||
| overflow: hidden; | ||
| } | ||
|
|
||
| :global(.webchat) .view-code-dialog__header { | ||
| align-items: center; | ||
| display: flex; | ||
| padding-inline-end: 30px; | ||
| } | ||
|
|
||
| :global(.webchat) .view-code-dialog__title { | ||
| margin: 0 auto 0 0; | ||
| text-transform: capitalize; | ||
| } | ||
|
|
||
| :global(.webchat) .view-code-dialog .view-code-dialog__body { | ||
| border: none; | ||
| border-radius: 0; | ||
| overflow: auto; | ||
| height: 100%; | ||
| } | ||
|
|
||
| :global(.webchat) .view-code-dialog :global(.code-block__body) { | ||
| display: block; | ||
| /* TODO: align with the rest of code blocks */ | ||
| line-height: normal; | ||
| padding: 16px 0; | ||
| } | ||
|
|
||
| :global(.webchat) .view-code-dialog__footer { | ||
| color: var(--webchat__color--subtle); | ||
| line-height: 20px; | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
packages/component/src/providers/CustomElements/customElements/CodeBlock.module.css
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| :global(.webchat) .code-block { | ||
| background: var(--webchat__background--code-block, inherit); | ||
| border: 1px solid #d1d1d1; | ||
| border-radius: 4px; | ||
| color: var(--webchat__color--code-block, currentColor); | ||
| display: block; | ||
| margin: 16px 0; | ||
| overflow: hidden; | ||
| padding: 4px 4px 4px 8px; | ||
| line-height: normal; | ||
| } | ||
|
|
||
| :global(.webchat) .code-block:has(.code-block__theme--github-dark-default) { | ||
| background: var(--webchat__background--code-block, #0d1117); | ||
| color: var(--webchat__color--code-block, #e6edf3); | ||
| } | ||
|
|
||
| :global(.webchat) .code-block:has(.code-block__theme--github-light-default) { | ||
| background: var(--webchat__background--code-block, #ffffff); | ||
| color: var(--webchat__color--code-block, #1f2328); | ||
| } | ||
|
|
||
| :global(.webchat) .code-block:has(.code-block__body:focus-visible):focus-within { | ||
| outline: 2px solid #000; | ||
| outline-offset: -2px; | ||
| } | ||
|
|
||
| :global(.webchat) .code-block__body { | ||
| margin: 0; | ||
| outline: none; | ||
| white-space: pre-wrap; | ||
| /* TODO: align with the rest of code blocks */ | ||
| line-height: unset; | ||
| display: inline; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.