8000 Add labels for pyrepl component (#322) · yannickfunk/pyscript@508a7d8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 508a7d8

Browse files
ic-768fpliger
andauthored
Add labels for pyrepl component (pyscript#322)
* Add labels for pyrepl component * Add id to editor box instead of main div Co-authored-by: Fabio Pliger <fabio.pliger@gmail.com>
1 parent 9119939 commit 508a7d8

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

pyscriptjs/src/components/pyrepl.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,35 @@ export class PyRepl extends BaseEvalElement {
9494
const mainDiv = document.createElement('div');
9595
addClasses(mainDiv, ['parentBox', 'flex', 'flex-col', 'mt-2', 'mx-8', 'relative']);
9696

97+
// Styles that we use to hide the labels whilst also keeping it accessible for screen readers
98+
const labelStyle = 'overflow:hidden; display:block; width:1px; height:1px';
99+
100+
// Code editor Label
101+
this.editorNode.id = 'code-editor';
102+
const editorLabel = document.createElement('label');
103+
editorLabel.innerHTML = 'Python Script Area';
104+
editorLabel.setAttribute('style', labelStyle);
105+
editorLabel.htmlFor = 'code-editor';
106+
107+
mainDiv.append(editorLabel);
108+
97109
// add Editor to main PyScript div
98110
mainDiv.appendChild(this.editorNode);
99111

100112
// Play Button
101113
this.btnRun = document.createElement('button');
114+
this.btnRun.id = 'btnRun';
102115
this.btnRun.innerHTML =
103116
'<svg id="" class="svelte-fa svelte-ps5qeg" style="height:20px;width:20px;vertical-align:-.125em;transform-origin:center;overflow:visible;color:green" viewBox="0 0 384 512" aria-hidden="true" role="img" xmlns="http://www.w3.org/2000/svg"><g transform="translate(192 256)" transform-origin="96 0"><g transform="translate(0,0) scale(1,1)"><path d="M361 215C375.3 223.8 384 239.3 384 256C384 272.7 375.3 288.2 361 296.1L73.03 472.1C58.21 482 39.66 482.4 24.52 473.9C9.377 465.4 0 449.4 0 432V80C0 62.64 9.377 46.63 24.52 38.13C39.66 29.64 58.21 29.99 73.03 39.04L361 215z" fill="currentColor" transform="translate(-192 -256)"></path></g></g></svg>';
104117
addClasses(this.btnRun, ['absolute', 'right-1', 'bottom-1', 'opacity-0', 'group-hover:opacity-100']);
118+
119+
// Play Button Label
120+
const btnLabel = document.createElement('label');
121+
btnLabel.innerHTML = 'Python Script Run Button';
122+
btnLabel.setAttribute('style', labelStyle);
123+
btnLabel.htmlFor = 'btnRun';
124+
125+
this.editorNode.appendChild(btnLabel);
105126
this.editorNode.appendChild(this.btnRun);
106127

107128
this.btnRun.addEventListener('click', () => {

0 commit comments

Comments
 (0)
0