Raxol.Core.Accessibility (Raxol Core v2.4.0)

Copy Markdown View Source

Refactored Accessibility module that delegates to the unified GenAccessibilityServer.

This module provides the same API as the original Accessibility module but uses a supervised GenServer instead of the Process dictionary for state management.

Migration Notice

This module is a drop-in replacement for Raxol.Core.Accessibility. All functions maintain backward compatibility while providing improved fault tolerance and functional programming patterns.

Benefits over Process Dictionary

  • Unified state management across all accessibility features
  • Supervised state with fault tolerance
  • Pure functional transformations
  • Announcement queuing with priority
  • Better debugging and testing capabilities
  • No global state pollution

Consolidated Modules

This refactored version consolidates functionality from:

Summary

Functions

Make an announcement for screen readers.

Make an announcement with user preferences (behaviour callback).

Announce component activation.

Announce with synchronous confirmation.

Check if any accessibility feature is active.

Clear announcement history.

Clear all announcements (behaviour callback).

Disable accessibility features.

Enable accessibility features with the given options.

Check if accessibility features are enabled.

Ensures the Accessibility server is started.

Get announcement history.

Get accessibility metadata for a component.

Get all accessibility preferences.

Handle focus change event.

Check if high contrast mode is enabled.

Initialize accessibility with the given options.

Check if large text mode is enabled.

Check if reduced motion mode is enabled.

Remove metadata for a component.

Reset all accessibility settings to defaults.

Check if screen reader support is enabled.

Set announcement callback function.

Set high contrast mode.

Set keyboard focus indicators.

Set large text mode.

Set large text mode with user preferences (behaviour callback).

Set accessibility metadata for a component.

Set reduced motion mode.

Set screen reader support.

Subscribe to announcement events. Returns :ok. The subscriber will receive {:announcement_added, ref, message} messages.

Unsubscribe from announcement events.

Update a specific metadata field for a component.

Functions

announce(message, opts \\ [])

Make an announcement for screen readers.

Options

  • :priority - Priority level (:high, :medium, :low) default: :medium
  • :interrupt - Whether to interrupt current announcement default: false
  • :language - Language for the announcement

announce(message, opts, user_preferences_pid_or_name)

Make an announcement with user preferences (behaviour callback).

announce_activation(component_id)

@spec announce_activation(term()) :: :ok

Announce component activation.

announce_sync(message, opts \\ [])

@spec announce_sync(
  String.t(),
  keyword()
) :: :ok

Announce with synchronous confirmation.

announce_value_change(component_id, old_value, new_value)

@spec announce_value_change(term(), term(), term()) :: :ok

Announce value change.

any_feature_active?()

@spec any_feature_active?() :: boolean()

Check if any accessibility feature is active.

clear_announcement_history()

@spec clear_announcement_history() :: :ok

Clear announcement history.

clear_announcements()

Clear all announcements (behaviour callback).

disable(user_preferences_pid_or_name \\ nil)

Disable accessibility features.

enable(options \\ [], user_preferences_pid_or_name \\ nil)

Enable accessibility features with the given options.

Options

  • :high_contrast - Enable high contrast mode (default: false)
  • :reduced_motion - Enable reduced motion (default: false)
  • :large_text - Enable large text (default: false)
  • :screen_reader - Enable screen reader support (default: true)
  • :keyboard_focus - Enable keyboard focus indicators (default: true)
  • :silence_announcements - Silence screen reader announcements (default: false)

enabled?()

Check if accessibility features are enabled.

enabled?(pid_or_name)

ensure_started()

@spec ensure_started() :: :ok

Ensures the Accessibility server is started.

get_announcement_history(limit \\ nil)

@spec get_announcement_history(non_neg_integer() | nil) :: [map()]

Get announcement history.

get_metadata(component_id)

@spec get_metadata(term()) :: map() | nil

Get accessibility metadata for a component.

get_option(key, pid_or_name, default)

get_preferences()

@spec get_preferences() :: map()

Get all accessibility preferences.

get_text_scale(user_preferences_pid_or_name \\ nil)

@spec get_text_scale(atom() | pid() | nil) :: float()

handle_focus_change_event(arg)

@spec handle_focus_change_event({:focus_change, term(), term()}) :: :ok

Handle focus change event.

handle_locale_changed_event(event)

handle_preference_changed_event(event)

handle_theme_changed_event(event)

high_contrast?()

@spec high_contrast?() :: boolean()

Check if high contrast mode is enabled.

high_contrast_enabled?(user_preferences_pid_or_name)

@spec high_contrast_enabled?(atom() | pid()) :: boolean()

init(options \\ [])

@spec init(keyword()) :: :ok

Initialize accessibility with the given options.

large_text?()

@spec large_text?() :: boolean()

Check if large text mode is enabled.

large_text_enabled?(user_preferences_pid_or_name)

@spec large_text_enabled?(atom() | pid()) :: boolean()

reduced_motion?()

@spec reduced_motion?() :: boolean()

Check if reduced motion mode is enabled.

reduced_motion_enabled?(user_preferences_pid_or_name)

@spec reduced_motion_enabled?(atom() | pid()) :: boolean()

remove_metadata(component_id)

@spec remove_metadata(term()) :: :ok

Remove metadata for a component.

reset()

@spec reset() :: :ok

Reset all accessibility settings to defaults.

screen_reader?()

@spec screen_reader?() :: boolean()

Check if screen reader support is enabled.

set_announcement_callback(callback)

@spec set_announcement_callback((String.t() -> any())) :: :ok

Set announcement callback function.

set_enabled(bool)

@spec set_enabled(boolean()) :: :ok

set_high_contrast(enabled)

@spec set_high_contrast(boolean()) :: :ok

Set high contrast mode.

set_high_contrast(enabled, user_preferences_pid_or_name)

@spec set_high_contrast(boolean(), atom() | pid()) :: :ok

set_keyboard_focus(enabled)

@spec set_keyboard_focus(boolean()) :: :ok

Set keyboard focus indicators.

set_large_text(enabled)

@spec set_large_text(boolean()) :: :ok

Set large text mode.

set_large_text(enabled, user_preferences_pid_or_name)

Set large text mode with user preferences (behaviour callback).

set_metadata(component_id, metadata)

@spec set_metadata(term(), map()) :: :ok

Set accessibility metadata for a component.

Metadata fields

  • :label - Accessible label for the component
  • :role - ARIA role (button, navigation, etc.)
  • :description - Extended description
  • :hint - Usage hint for screen readers
  • :state - Current state (expanded, selected, etc.)

set_reduced_motion(enabled)

@spec set_reduced_motion(boolean()) :: :ok

Set reduced motion mode.

set_reduced_motion(enabled, user_preferences_pid_or_name)

@spec set_reduced_motion(boolean(), atom() | pid()) :: :ok

set_screen_reader(enabled)

@spec set_screen_reader(boolean()) :: :ok

Set screen reader support.

subscribe_to_announcements(ref)

@spec subscribe_to_announcements(reference()) :: :ok

Subscribe to announcement events. Returns :ok. The subscriber will receive {:announcement_added, ref, message} messages.

unsubscribe_from_announcements(ref)

@spec unsubscribe_from_announcements(reference()) :: :ok

Unsubscribe from announcement events.

update_metadata(component_id, field, value)

@spec update_metadata(term(), atom(), term()) :: :ok

Update a specific metadata field for a component.