Skip to content

Commit baea955

Browse files
committed
feat: add basic accessibility roles to library components
- NodeEditor: accessible-role list, labeled "Node Editor" - BaseNode: accessible-role list-item, description indicates selection state - Pin: accessible-role button, labeled by pin type (input/output) - Minimal example: sets accessible-label to node title Enables screen reader support and MCP introspection of the UI tree.
1 parent ae8e935 commit baea955

4 files changed

Lines changed: 31 additions & 0 deletions

File tree

examples/minimal/ui/minimal.slint

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export { LinkData, DragState, NodeEditorInternalCallbacks, NodeEditorComputation
2121

2222
component SimpleNode inherits BaseNode {
2323
in property <string> title: "Node";
24+
accessible-label: title;
2425
// Set node size for BaseNode
2526
node-width: 250px;
2627
node-height: 80px;

node-editor-building-blocks.slint

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,12 +454,21 @@ export component Link inherits Path {
454454
/// applies transform-scale for zoom, so nodes just use x: world-x, y: world-y directly.
455455
///
456456
/// Zoom/pan values are accessed from the ViewportState global - examples don't need to pass them.
457+
///
458+
/// **Accessibility:** BaseNode defaults to `accessible-label: "Node " + node-id`.
459+
/// Override this in your node component with the node's title for better screen reader
460+
/// and MCP introspection support: `accessible-label: title;`
457461
export component BaseNode inherits Rectangle {
458462
// === Common Properties ===
459463
in property <int> node-id;
460464
in property <bool> selected: false;
461465
in property <length> world-x;
462466
in property <length> world-y;
467+
468+
// === Accessibility ===
469+
accessible-role: list-item;
470+
accessible-label: "Node " + node-id;
471+
accessible-description: selected ? "selected" : "";
463472
// Persistent position offset (survives drag end until model updates)
464473
property <length> persistent-offset-x: 0px;
465474
property <length> persistent-offset-y: 0px;
@@ -669,6 +678,10 @@ export component Pin inherits Rectangle {
669678
in property <int> pin-id;
670679
in property <int> node-id; // Node this pin belongs to (for position reporting)
671680
in property <int> pin-type; // Type of pin (input/output/custom)
681+
682+
// === Accessibility ===
683+
accessible-role: button;
684+
accessible-label: pin-type == 1 ? "input pin" : pin-type == 2 ? "output pin" : "pin";
672685
in property <color> base-color: #888888;
673686
in property <color> hover-color: #aaaaaa;
674687
in property <length> base-size: 12px;

node-editor.slint

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ export enum BoxSelectionModifier {
8484
/// Multiple editors in separate windows work fine. This limitation will be
8585
/// lifted once Slint introduces component-scoped globals.
8686
export component NodeEditor inherits FocusScope {
87+
// === Accessibility ===
88+
accessible-role: list;
89+
accessible-label: "Node Editor";
90+
8791
// === Shared viewport state ===
8892
in-out property <length> pan-x: 0px;
8993
in-out property <length> pan-y: 0px;

src/lib.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,19 @@
3232
//! - [`Link`] - Bezier curve link component
3333
//! - [`Minimap`] - Bird's-eye view component
3434
//!
35+
//! ## Accessibility
36+
//!
37+
//! Library components include accessibility roles for screen readers and MCP
38+
//! introspection. When creating custom node components, set `accessible-label`
39+
//! to the node's display title:
40+
//!
41+
//! ```slint
42+
//! component MyNode inherits BaseNode {
43+
//! in property <string> title;
44+
//! accessible-label: title; // override default "Node <id>"
45+
//! }
46+
//! ```
47+
//!
3548
//! ## Rust Helpers
3649
//!
3750
//! This crate provides Rust helper functions for common operations:

0 commit comments

Comments
 (0)