Skip to content

Commit 1497b2d

Browse files
authored
fix(snippets-btn): Minor styling/a11y fixes (#434)
* fix(snippets-btn): Minor styling/a11y fixes * Add changeset * update tests
1 parent 4580d8d commit 1497b2d

4 files changed

Lines changed: 9 additions & 13 deletions

File tree

.changeset/short-windows-tan.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@stackoverflow/stacks-editor": patch
3+
---
4+
5+
Minor a11y and layout fixes for "Run code snippets" button

plugins/official/stack-snippets/src/snippet-view.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,8 @@ export class StackSnippetView implements NodeView {
8787
if (opts && opts.renderer) {
8888
const runCodeButton = document.createElement("button");
8989
runCodeButton.type = "button";
90-
runCodeButton.className = "s-btn s-btn__filled";
91-
runCodeButton.title = "Run code snippet";
92-
runCodeButton.setAttribute("aria-label", "Run code snippet");
90+
runCodeButton.className =
91+
"s-btn s-btn__filled d-inline-flex ai-center g2";
9392
// create the svg svg-icon-bg element
9493
const runIcon = document.createElement("span");
9594
runIcon.className = "svg-icon-bg iconPlay";

plugins/official/stack-snippets/test/render.test.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,7 @@ describe("stack snippets", () => {
2929
const shouldHaveRunCodeButton = (rendered: Element) => {
3030
const runCode = rendered.querySelectorAll("div.snippet-ctas > button");
3131
expect(runCode).toHaveLength(1);
32-
expect(runCode[0].attributes.getNamedItem("title").value).toBe(
33-
"Run code snippet"
34-
);
35-
expect(runCode[0].attributes.getNamedItem("aria-label").value).toBe(
36-
"Run code snippet"
37-
);
32+
expect(runCode[0].textContent).toBe("Run code snippet");
3833
};
3934

4035
const shouldHaveLanguageBlocks = (rendered: Element, langs: string[]) => {

plugins/official/stack-snippets/test/snippet-view.test.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,7 @@ describe("StackSnippetView", () => {
6969
);
7070

7171
expect(runCodeButton).toHaveLength(1);
72-
expect(runCodeButton[0].getAttribute("aria-label")).toBe(
73-
"Run code snippet"
74-
);
75-
expect(runCodeButton[0].getAttribute("title")).toBe("Run code snippet");
72+
expect(runCodeButton[0].textContent).toBe("Run code snippet");
7673
});
7774

7875
it("should not render run code button if no renderer provided", () => {

0 commit comments

Comments
 (0)