Skip to content
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions blocks/math.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const blocks = createBlockDefinitionsFromJsonArray([
'type': 'field_number',
'name': 'NUM',
'value': 0,
'ariaName': 'Number',
},
],
'output': 'Number',
Expand Down
2 changes: 1 addition & 1 deletion core/block_svg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ export class BlockSvg

let blockTypeText = 'block';
if (this.isShadow()) {
blockTypeText = 'replacable block';
blockTypeText = 'replaceable block';
} else if (this.outputConnection) {
blockTypeText = 'input block';
} else if (this.statementInputCount) {
Expand Down
9 changes: 9 additions & 0 deletions core/bubbles/bubble.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ export abstract class Bubble implements IBubble, ISelectable, IFocusableNode {
this.focusableElement = overriddenFocusableElement ?? this.svgRoot;
this.focusableElement.setAttribute('id', this.id);
aria.setRole(this.focusableElement, aria.Role.GROUP);
const label = this.getAriaLabel();
if (label) aria.setState(this.focusableElement, aria.State.LABEL, label);

browserEvents.conditionalBind(
this.background,
Expand All @@ -166,6 +168,13 @@ export abstract class Bubble implements IBubble, ISelectable, IFocusableNode {
this.disposed = true;
}

/**
* @returns The ARIA label to use for this bubble, or null if none should be used.
*/
protected getAriaLabel(): string | null {
return null;
}

/**
* Set the location the tail of this bubble points to.
*
Expand Down
4 changes: 4 additions & 0 deletions core/bubbles/mini_workspace_bubble.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ export class MiniWorkspaceBubble extends Bubble {
this.updateBubbleSize();
}

protected override getAriaLabel(): string | null {
return 'Mutator Bubble';
}

dispose() {
this.miniWorkspace.dispose();
super.dispose();
Expand Down
4 changes: 4 additions & 0 deletions core/bubbles/text_bubble.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ export class TextBubble extends Bubble {
dom.addClass(this.svgRoot, 'blocklyTextBubble');
}

protected override getAriaLabel(): string | null {
return 'Warning Bubble';
}

/** @returns the current text of this text bubble. */
getText(): string {
return this.text;
Expand Down
4 changes: 4 additions & 0 deletions core/bubbles/textinput_bubble.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ export class TextInputBubble extends Bubble {
this.setSize(this.DEFAULT_SIZE, true);
}

protected override getAriaLabel(): string | null {
return 'Comment Bubble';
}

/** @returns the text of this bubble. */
getText(): string {
return this.editor.getText();
Expand Down
9 changes: 1 addition & 8 deletions core/field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,14 +272,7 @@ export abstract class Field<T = any>
}

getAriaName(): string | null {
return (
this.config?.ariaName ??
this.config?.name ??
this.config?.type ??
this.getSourceBlock()?.type ??
this.name ??
null
);
return this.config?.ariaName ?? null;
}

/**
Expand Down
15 changes: 8 additions & 7 deletions core/field_image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,17 +156,18 @@ export class FieldImage extends Field<string> {
}

const element = this.getFocusableElement();
if (this.clickHandler) {
if (this.isClickable()) {
this.imageElement.style.cursor = 'pointer';
aria.setRole(element, aria.Role.BUTTON);

const label = [this.altText, this.getAriaName()]
.filter((item) => !!item)
.join(', ');
aria.setState(element, aria.State.LABEL, label);
} else {
aria.setRole(element, aria.Role.IMAGE);
// The field isn't navigable unless it's clickable.
aria.setRole(element, aria.Role.PRESENTATION);
}

const label = [this.altText, this.getAriaName()]
.filter((item) => !!item)
.join(', ');
aria.setState(element, aria.State.LABEL, label);
}

override updateSize_() {}
Expand Down
Loading