accessibility

package
v0.6.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 22, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package accessibility provides accessibility primitives for widgets.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BoolPtr

func BoolPtr(value bool) *bool

BoolPtr returns a pointer to a bool.

func FormatChange

func FormatChange(widget Accessible) string

FormatChange builds a short description of a widget's state.

Types

type Accessible

type Accessible interface {
	// Identity
	AccessibleRole() Role
	AccessibleLabel() string
	AccessibleDescription() string
	AccessibleState() StateSet
	AccessibleValue() *ValueInfo

	// Live regions — mirrors aria-live, aria-relevant, aria-atomic
	AccessibleLive() Live
	AccessibleRelevant() Relevant
	AccessibleAtomic() bool

	// Landmarks — mirrors ARIA landmark roles
	AccessibleLandmark() Landmark

	// Relationships — mirrors aria-labelledby, aria-describedby, aria-controls, aria-owns, aria-flowto
	AccessibleLabelledBy() string
	AccessibleDescribedBy() string
	AccessibleControls() string
	AccessibleOwns() string
	AccessibleFlowTo() string

	// WAI-ARIA 1.2/1.3 properties
	AccessibleLevel() int
	AccessibleOrientation() string
	AccessibleActiveDescendant() string
	AccessiblePosInSet() int
	AccessibleSetSize() int
	AccessibleHasPopup() string
	AccessibleErrorMessage() string
	AccessibleCurrent() string
	AccessibleAutocomplete() string
	AccessiblePlaceholder() string
	AccessibleSort() string
	AccessibleKeyShortcuts() string
	AccessibleDetails() string
	AccessibleRoleDescription() string
}

Accessible is implemented by widgets that expose accessibility metadata.

type Announcement

type Announcement struct {
	Message  string
	Priority Priority
}

Announcement captures a published accessibility message.

type Announcer

type Announcer interface {
	Announce(message string, priority Priority)
	AnnounceChange(widget Accessible)
}

Announcer publishes accessibility announcements.

type Base

type Base struct {
	Role        Role
	Label       string
	Description string
	State       StateSet
	Value       *ValueInfo

	// Live region behavior (aria-live, aria-relevant, aria-atomic)
	Live     Live
	Relevant Relevant
	Atomic   bool

	// Relationships (aria-labelledby, aria-describedby, aria-controls, aria-owns, aria-flowto)
	LabelledBy  string
	DescribedBy string
	Controls    string
	Owns        string
	FlowTo      string

	// Landmark (aria landmark roles)
	Landmark Landmark

	// WAI-ARIA 1.2/1.3 properties
	Level            int    // aria-level (heading level, tree depth)
	Orientation      string // aria-orientation (horizontal/vertical)
	ActiveDescendant string // aria-activedescendant (ID of focused descendant)
	PosInSet         int    // aria-posinset (position in set, 1-based)
	SetSize          int    // aria-setsize (total items in set)
	HasPopup         string // aria-haspopup (false/true/menu/listbox/tree/grid/dialog)
	ErrorMessage     string // aria-errormessage (ID of error element)
	Current          string // aria-current (page/step/location/date/time/true)
	Autocomplete     string // aria-autocomplete (inline/list/both/none)
	Placeholder      string // aria-placeholder
	Sort             string // aria-sort (ascending/descending/none/other)
	KeyShortcuts     string // aria-keyshortcuts
	Details          string // aria-details (ID of detailed description)
	RoleDescription  string // aria-roledescription (custom role label for AT)
}

Base is a helper implementation of Accessible.

func (*Base) AccessibleActiveDescendant

func (b *Base) AccessibleActiveDescendant() string

AccessibleActiveDescendant returns the ID of the active descendant.

func (*Base) AccessibleAtomic

func (b *Base) AccessibleAtomic() bool

AccessibleAtomic returns whether the entire region is announced on change.

func (*Base) AccessibleAutocomplete

func (b *Base) AccessibleAutocomplete() string

AccessibleAutocomplete returns the autocomplete mode.

func (*Base) AccessibleControls

func (b *Base) AccessibleControls() string

AccessibleControls returns the ID of the widget this one controls.

func (*Base) AccessibleCurrent

func (b *Base) AccessibleCurrent() string

AccessibleCurrent returns the current indicator (page/step/location/date/time/true).

func (*Base) AccessibleDescribedBy

func (b *Base) AccessibleDescribedBy() string

AccessibleDescribedBy returns the ID of the widget that describes this one.

func (*Base) AccessibleDescription

func (b *Base) AccessibleDescription() string

AccessibleDescription returns the current description.

func (*Base) AccessibleDetails

func (b *Base) AccessibleDetails() string

AccessibleDetails returns the ID of the details element.

func (*Base) AccessibleErrorMessage

func (b *Base) AccessibleErrorMessage() string

AccessibleErrorMessage returns the ID of the error message element.

func (*Base) AccessibleFlowTo

func (b *Base) AccessibleFlowTo() string

AccessibleFlowTo returns the ID of the next widget in reading order.

func (*Base) AccessibleHasPopup

func (b *Base) AccessibleHasPopup() string

AccessibleHasPopup returns the popup type.

func (*Base) AccessibleKeyShortcuts

func (b *Base) AccessibleKeyShortcuts() string

AccessibleKeyShortcuts returns the keyboard shortcuts.

func (*Base) AccessibleLabel

func (b *Base) AccessibleLabel() string

AccessibleLabel returns the current label.

func (*Base) AccessibleLabelledBy

func (b *Base) AccessibleLabelledBy() string

AccessibleLabelledBy returns the ID of the widget that labels this one.

func (*Base) AccessibleLandmark

func (b *Base) AccessibleLandmark() Landmark

AccessibleLandmark returns the landmark designation.

func (*Base) AccessibleLevel

func (b *Base) AccessibleLevel() int

AccessibleLevel returns the heading level or tree depth.

func (*Base) AccessibleLive

func (b *Base) AccessibleLive() Live

AccessibleLive returns the live region behavior.

func (*Base) AccessibleOrientation

func (b *Base) AccessibleOrientation() string

AccessibleOrientation returns the orientation (horizontal/vertical).

func (*Base) AccessibleOwns

func (b *Base) AccessibleOwns() string

AccessibleOwns returns the ID of the widget this one owns.

func (*Base) AccessiblePlaceholder

func (b *Base) AccessiblePlaceholder() string

AccessiblePlaceholder returns the placeholder text.

func (*Base) AccessiblePosInSet

func (b *Base) AccessiblePosInSet() int

AccessiblePosInSet returns the 1-based position in the set.

func (*Base) AccessibleRelevant

func (b *Base) AccessibleRelevant() Relevant

AccessibleRelevant returns which mutations trigger announcements.

func (*Base) AccessibleRole

func (b *Base) AccessibleRole() Role

AccessibleRole returns the current role.

func (*Base) AccessibleRoleDescription

func (b *Base) AccessibleRoleDescription() string

AccessibleRoleDescription returns the custom role description.

func (*Base) AccessibleSetSize

func (b *Base) AccessibleSetSize() int

AccessibleSetSize returns the total items in the set.

func (*Base) AccessibleSort

func (b *Base) AccessibleSort() string

AccessibleSort returns the sort direction.

func (*Base) AccessibleState

func (b *Base) AccessibleState() StateSet

AccessibleState returns the current state set.

func (*Base) AccessibleValue

func (b *Base) AccessibleValue() *ValueInfo

AccessibleValue returns the current value info.

func (*Base) HasExtendedARIA

func (b *Base) HasExtendedARIA() bool

HasExtendedARIA returns true if any WAI-ARIA 1.2/1.3 extended properties are set. This allows callers to skip serialization/processing of extended properties when none are in use.

func (*Base) SetActiveDescendant

func (b *Base) SetActiveDescendant(id string)

SetActiveDescendant updates the ID of the active descendant.

func (*Base) SetAtomic

func (b *Base) SetAtomic(atomic bool)

SetAtomic updates whether the entire region is announced on change.

func (*Base) SetAutocomplete

func (b *Base) SetAutocomplete(autocomplete string)

SetAutocomplete updates the autocomplete mode.

func (*Base) SetControls

func (b *Base) SetControls(id string)

SetControls updates the ID of the widget this one controls.

func (*Base) SetCurrent

func (b *Base) SetCurrent(current string)

SetCurrent updates the current indicator.

func (*Base) SetDescribedBy

func (b *Base) SetDescribedBy(id string)

SetDescribedBy updates the ID of the widget that describes this one.

func (*Base) SetDescription

func (b *Base) SetDescription(description string)

SetDescription updates the description.

func (*Base) SetDetails

func (b *Base) SetDetails(id string)

SetDetails updates the ID of the details element.

func (*Base) SetErrorMessage

func (b *Base) SetErrorMessage(id string)

SetErrorMessage updates the ID of the error message element.

func (*Base) SetFlowTo

func (b *Base) SetFlowTo(id string)

SetFlowTo updates the ID of the next widget in reading order.

func (*Base) SetHasPopup

func (b *Base) SetHasPopup(popup string)

SetHasPopup updates the popup type.

func (*Base) SetKeyShortcuts

func (b *Base) SetKeyShortcuts(shortcuts string)

SetKeyShortcuts updates the keyboard shortcuts.

func (*Base) SetLabel

func (b *Base) SetLabel(label string)

SetLabel updates the label.

func (*Base) SetLabelledBy

func (b *Base) SetLabelledBy(id string)

SetLabelledBy updates the ID of the widget that labels this one.

func (*Base) SetLandmark

func (b *Base) SetLandmark(landmark Landmark)

SetLandmark updates the landmark designation.

func (*Base) SetLevel

func (b *Base) SetLevel(level int)

SetLevel updates the heading level or tree depth.

func (*Base) SetLive

func (b *Base) SetLive(live Live)

SetLive updates the live region behavior.

func (*Base) SetOrientation

func (b *Base) SetOrientation(orientation string)

SetOrientation updates the orientation.

func (*Base) SetOwns

func (b *Base) SetOwns(id string)

SetOwns updates the ID of the widget this one owns.

func (*Base) SetPlaceholder

func (b *Base) SetPlaceholder(placeholder string)

SetPlaceholder updates the placeholder text.

func (*Base) SetPosInSet

func (b *Base) SetPosInSet(pos int)

SetPosInSet updates the 1-based position in the set.

func (*Base) SetRelevant

func (b *Base) SetRelevant(relevant Relevant)

SetRelevant updates which mutations trigger announcements.

func (*Base) SetRole

func (b *Base) SetRole(role Role)

SetRole updates the role.

func (*Base) SetRoleDescription

func (b *Base) SetRoleDescription(desc string)

SetRoleDescription updates the custom role description.

func (*Base) SetSetSize

func (b *Base) SetSetSize(size int)

SetSetSize updates the total items in the set.

func (*Base) SetSort

func (b *Base) SetSort(sort string)

SetSort updates the sort direction.

func (*Base) SetState

func (b *Base) SetState(state StateSet)

SetState updates the state.

func (*Base) SetValue

func (b *Base) SetValue(value *ValueInfo)

SetValue updates the value.

type Bridge

type Bridge interface {
	// Register connects the application to the platform accessibility system.
	// The app parameter provides access to the widget tree.
	Register(app BridgeApp) error

	// Announce sends text to the screen reader.
	// Priority controls whether the message interrupts current speech.
	Announce(text string, priority Priority) error

	// UpdateTree notifies the screen reader that the widget structure changed.
	// Call this after layout changes.
	UpdateTree() error

	// NotifyFocusChange informs the screen reader that focus moved to a new widget.
	NotifyFocusChange(widget Accessible) error

	// NotifyValueChange informs the screen reader that a widget's value changed.
	// For text inputs, sliders, progress bars, etc.
	NotifyValueChange(widget Accessible, oldValue, newValue string) error

	// NotifyStateChange informs the screen reader that a widget's state changed.
	// For checkboxes, expandable items, etc.
	NotifyStateChange(widget Accessible, state string, value bool) error

	// Close disconnects from the platform accessibility system.
	Close() error
}

Bridge provides cross-platform screen reader integration. Implementations connect to platform-specific accessibility APIs: - Linux: AT-SPI via D-Bus - macOS: NSAccessibility - Windows: UI Automation

func NewBridge

func NewBridge() Bridge

NewBridge returns an AT-SPI bridge for Linux.

type BridgeAnnouncer

type BridgeAnnouncer struct {
	// contains filtered or unexported fields
}

BridgeAnnouncer wraps a Bridge to implement the Announcer interface.

func NewBridgeAnnouncer

func NewBridgeAnnouncer(bridge Bridge) *BridgeAnnouncer

NewBridgeAnnouncer creates an Announcer that uses the given Bridge.

func (*BridgeAnnouncer) Announce

func (ba *BridgeAnnouncer) Announce(message string, priority Priority)

Announce sends text to the screen reader.

func (*BridgeAnnouncer) AnnounceChange

func (ba *BridgeAnnouncer) AnnounceChange(widget Accessible)

AnnounceChange announces the widget state.

type BridgeApp

type BridgeApp interface {
	// Name returns the application name.
	Name() string

	// RootAccessible returns the root accessible element.
	RootAccessible() Accessible

	// FocusedAccessible returns the currently focused element.
	FocusedAccessible() Accessible

	// AccessibleAt returns the accessible at the given path.
	// Path is a slash-separated list of indices from root.
	AccessibleAt(path string) Accessible

	// ChildAccessibles returns the children of the given accessible.
	ChildAccessibles(parent Accessible) []Accessible
}

BridgeApp provides the bridge with access to application state.

type FocusStyle

type FocusStyle struct {
	Indicator    string
	Style        backend.Style
	HighContrast backend.Style
}

FocusStyle defines consistent focus rendering.

type Landmark

type Landmark string

Landmark describes the structural significance of a widget for navigation. Mirrors ARIA landmark roles: navigation, main, search, form, banner, etc.

const (
	LandmarkNone          Landmark = ""
	LandmarkNavigation    Landmark = "navigation"
	LandmarkMain          Landmark = "main"
	LandmarkSearch        Landmark = "search"
	LandmarkForm          Landmark = "form"
	LandmarkBanner        Landmark = "banner"
	LandmarkContentInfo   Landmark = "contentinfo"
	LandmarkRegion        Landmark = "region"
	LandmarkComplementary Landmark = "complementary"
)

type Live

type Live string

Live describes how content changes are announced to assistive technology. Mirrors aria-live: off (default), polite (wait for idle), assertive (interrupt).

const (
	// LiveOff suppresses automatic announcements (default).
	LiveOff Live = ""
	// LivePolite announces changes when the user is idle.
	LivePolite Live = "polite"
	// LiveAssertive interrupts current speech to announce changes.
	LiveAssertive Live = "assertive"
)

type Priority

type Priority int

Priority describes announcement urgency.

const (
	// PriorityPolite waits for current speech to complete.
	PriorityPolite Priority = iota
	// PriorityAssertive interrupts current speech for important messages.
	PriorityAssertive
	// PriorityLow is lower than polite, can be dropped.
	PriorityLow
	// PriorityMedium is equivalent to PriorityPolite.
	PriorityMedium
	// PriorityHigh is between polite and assertive.
	PriorityHigh
	// PriorityUrgent interrupts current speech immediately.
	PriorityUrgent
)

type Relevant

type Relevant string

Relevant describes which mutations in a live region trigger announcements. Mirrors aria-relevant: additions, removals, text, all.

const (
	// RelevantAdditions announces new children added to the region.
	RelevantAdditions Relevant = "additions"
	// RelevantRemovals announces children removed from the region.
	RelevantRemovals Relevant = "removals"
	// RelevantText announces text content changes.
	RelevantText Relevant = "text"
	// RelevantAll announces all mutations.
	RelevantAll Relevant = "all"
)

type Role

type Role string

Role describes the semantic role of a widget.

const (
	RoleButton      Role = "button"
	RoleCheckbox    Role = "checkbox"
	RoleRadio       Role = "radio"
	RoleTextbox     Role = "textbox"
	RoleList        Role = "list"
	RoleListItem    Role = "listitem"
	RoleTable       Role = "table"
	RoleRow         Role = "row"
	RoleCell        Role = "cell"
	RoleSlider      Role = "slider"
	RoleTree        Role = "tree"
	RoleTreeItem    Role = "treeitem"
	RoleMenu        Role = "menu"
	RoleMenuItem    Role = "menuitem"
	RoleTab         Role = "tab"
	RoleTabList     Role = "tablist"
	RoleTabPanel    Role = "tabpanel"
	RoleDialog      Role = "dialog"
	RoleAlert       Role = "alert"
	RoleStatus      Role = "status"
	RoleProgressBar Role = "progressbar"
	RoleGroup       Role = "group"
	RoleText        Role = "text"
	RoleChart       Role = "chart"
	RoleWindow      Role = "window"
	RoleApplication Role = "application"

	// WAI-ARIA 1.2 additional roles
	RoleCombobox   Role = "combobox"
	RoleSwitch     Role = "switch"
	RoleSpinButton Role = "spinbutton"
	RoleHeading    Role = "heading"
	RoleLink       Role = "link"
	RoleSeparator  Role = "separator"
	RoleLog        Role = "log"
	RoleTimer      Role = "timer"
	RoleFeed       Role = "feed"
	RoleToolbar    Role = "toolbar"
	RoleSearchbox  Role = "searchbox"
	RoleNone       Role = "none"
	RoleImg        Role = "img"
	RoleNote       Role = "note"
	RoleScrollbar  Role = "scrollbar"

	// WAI-ARIA 1.2 composite and structural roles
	RoleListbox          Role = "listbox"
	RoleOption           Role = "option"
	RoleRadioGroup       Role = "radiogroup"
	RoleGrid             Role = "grid"
	RoleGridCell         Role = "gridcell"
	RoleColumnHeader     Role = "columnheader"
	RoleRowHeader        Role = "rowheader"
	RoleRowGroup         Role = "rowgroup"
	RoleAlertDialog      Role = "alertdialog"
	RoleMenuItemCheckbox Role = "menuitemcheckbox"
	RoleMenuItemRadio    Role = "menuitemradio"
	RoleMenuBar          Role = "menubar"
	RoleTreeGrid         Role = "treegrid"
	RoleDocument         Role = "document"
	RoleMarquee          Role = "marquee"
	RolePresentation     Role = "presentation"
	RoleTooltip          Role = "tooltip"
	RoleMeter            Role = "meter"

	// WAI-ARIA landmark roles
	RoleForm          Role = "form"
	RoleNavigation    Role = "navigation"
	RoleComplementary Role = "complementary"

	// WAI-ARIA 1.3 roles
	RoleComment    Role = "comment"
	RoleMark       Role = "mark"
	RoleSuggestion Role = "suggestion"
	RoleCode       Role = "code"
	RoleTime       Role = "time"
	RoleImage      Role = "image"
)

Common accessibility roles.

type SimpleAnnouncer

type SimpleAnnouncer struct {
	// contains filtered or unexported fields
}

SimpleAnnouncer stores announcements in memory.

func (*SimpleAnnouncer) Announce

func (a *SimpleAnnouncer) Announce(message string, priority Priority)

Announce publishes a message.

func (*SimpleAnnouncer) AnnounceChange

func (a *SimpleAnnouncer) AnnounceChange(widget Accessible)

AnnounceChange announces the widget state.

func (*SimpleAnnouncer) CloseSpeaker

func (a *SimpleAnnouncer) CloseSpeaker()

CloseSpeaker stops any pending speech and closes the speaker.

func (*SimpleAnnouncer) History

func (a *SimpleAnnouncer) History() []Announcement

History returns a copy of announcements.

func (*SimpleAnnouncer) SetOnMessage

func (a *SimpleAnnouncer) SetOnMessage(fn func(Announcement))

SetOnMessage sets a callback for new announcements.

func (*SimpleAnnouncer) SetSpeaker

func (a *SimpleAnnouncer) SetSpeaker(s Speaker)

SetSpeaker attaches a TTS speaker to the announcer. When set, announcements are automatically spoken.

type Speaker

type Speaker interface {
	// Speak sends text to the TTS engine. It blocks until speech completes
	// or ctx is cancelled.
	Speak(ctx context.Context, text string) error

	// Stop cancels any in-progress speech.
	Stop() error

	// Close releases TTS resources.
	Close() error
}

Speaker provides text-to-speech output. Implementations wrap platform-specific TTS engines.

type StateSet

type StateSet struct {
	Checked         *bool // nil = not applicable
	Expanded        *bool
	Pressed         *bool // nil = not applicable (tri-state, for toggle buttons)
	Selected        bool
	Disabled        bool
	ReadOnly        bool
	Required        bool
	Invalid         bool
	Hidden          bool
	Busy            bool
	Modal           bool
	Multiline       bool // aria-multiline
	Multiselectable bool // aria-multiselectable
}

StateSet describes the state of a widget.

func (StateSet) Strings

func (s StateSet) Strings() []string

Strings returns human-friendly descriptions of the state.

type ValueInfo

type ValueInfo struct {
	Min     float64
	Max     float64
	Current float64
	Text    string
}

ValueInfo describes a widget's numeric value.

Directories

Path Synopsis
Package atspi provides Linux accessibility support via AT-SPI D-Bus.
Package atspi provides Linux accessibility support via AT-SPI D-Bus.
Package nsaccessibility provides macOS accessibility support via NSAccessibility.
Package nsaccessibility provides macOS accessibility support via NSAccessibility.
Package tts provides platform TTS backends implementing accessibility.Speaker.
Package tts provides platform TTS backends implementing accessibility.Speaker.
Package uiautomation provides Windows accessibility support via UI Automation.
Package uiautomation provides Windows accessibility support via UI Automation.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL