Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions src/containers/blocks.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ class Blocks extends React.Component {

const toolboxWorkspace = this.workspace.getFlyout().getWorkspace();




const varListButtonCallback = type =>
(() => this.ScratchBlocks.Variables.createVariable(this.workspace, null, type));
const procButtonCallback = () => {
Expand Down Expand Up @@ -152,6 +155,46 @@ class Blocks extends React.Component {
if (this.props.isVisible) {
this.setLocale();
}

function getBlockText(block) {
const fieldTexts = block.inputList.flatMap(input =>
input.fieldRow.map(field => field.getText())
);
return fieldTexts.join(' ').trim();
}

this.workspace.addChangeListener((event) => {

if (event.blockId) {
const block = this.workspace.getBlockById(event.blockId);
const svgRoot = block?.getSvgRoot();

if (svgRoot) {
const label = getBlockText(block);
svgRoot.setAttribute('aria-label', label);
}
}
});

// After Blockly is injected and workspace is initialized
const flyout = this.workspace.getFlyout();

if (flyout) {
const flyoutWorkspace = flyout.getWorkspace();

flyoutWorkspace.addChangeListener((event) => {
if (event.blockId) {
const block = flyoutWorkspace.getBlockById(event.blockId);
const svgRoot = block?.getSvgRoot();
if (svgRoot && !svgRoot.getAttribute('aria-label')) {
svgRoot.setAttribute('aria-label', getBlockText(block)); // Use block.type as the opcode label
}
}
});
}



}
shouldComponentUpdate(nextProps, nextState) {
return (
Expand Down Expand Up @@ -202,6 +245,7 @@ class Blocks extends React.Component {
} else {
this.workspace.setVisible(false);
}

}
componentWillUnmount() {
this.detachVM();
Expand Down