Loading...
Loading...
Accessibility (a11y) for CometChat UI Kit integrations across all families — React, React Native, Angular, Android (V5/V6), iOS, Flutter. Covers WCAG 2.1 AA targets, keyboard navigation in chat, screen reader announcements (live regions for new messages), color contrast, focus management on call screens, motion-reduction support, and the cross-family checks that catch the common production a11y bugs. Cross-family — applies wherever the agent is checking accessibility.
npx skill4agent add cometchat/cometchat-skills cometchat-a11y<div><button>prefers-reduced-motion// scripts/check-contrast.ts (run in CI or as a one-shot)
function contrastRatio(hex1: string, hex2: string): number {
const luminance = (hex: string) => {
const rgb = hex.match(/\w\w/g)!.map(c => parseInt(c, 16) / 255).map(c =>
c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4
);
return 0.2126 * rgb[0] + 0.7152 * rgb[1] + 0.0722 * rgb[2];
};
const l1 = luminance(hex1);
const l2 = luminance(hex2);
return (Math.max(l1, l2) + 0.05) / (Math.min(l1, l2) + 0.05);
}
// Pull the values from your CSS variables
const fg = getComputedStyle(document.documentElement).getPropertyValue("--cometchat-text-color").trim();
const bg = getComputedStyle(document.documentElement).getPropertyValue("--cometchat-background-color").trim();
const ratio = contrastRatio(fg, bg);
if (ratio < 4.5) {
console.warn(`Text/background contrast ${ratio.toFixed(2)}:1 fails WCAG AA (need ≥4.5:1)`);
}tests/a11y/contrast.test.ts#F0F0F0#999999import { useEffect, useRef } from "react";
export function ChatScreen() {
const composerRef = useRef<HTMLElement>(null);
useEffect(() => {
// After mount + animations, focus the composer
const timer = setTimeout(() => {
composerRef.current?.focus();
}, 100);
return () => clearTimeout(timer);
}, []);
return (
<div>
<CometChatMessageHeader />
<CometChatMessageList />
<CometChatMessageComposer ref={composerRef} />
</div>
);
}CometChatMessageComposercomposerRef.current?.querySelector("input, [contenteditable]")?.focus()import { useRef, useEffect } from "react";
import { findNodeHandle, AccessibilityInfo } from "react-native";
export function ChatScreen() {
const composerRef = useRef(null);
useEffect(() => {
const handle = findNodeHandle(composerRef.current);
if (handle) {
AccessibilityInfo.setAccessibilityFocus(handle);
}
}, []);
return (
<View>
<CometChatMessageHeader />
<CometChatMessageList />
<CometChatMessageComposer ref={composerRef} />
</View>
);
}@Component({...})
export class ChatComponent implements AfterViewInit {
@ViewChild("composer") composer!: ElementRef;
ngAfterViewInit() {
setTimeout(() => this.composer.nativeElement.focus(), 100);
}
}override fun onResume() {
super.onResume()
composerView.requestFocus()
composerView.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED)
}override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
UIAccessibility.post(notification: .screenChanged, argument: composerView)
}final FocusNode _composerFocus = FocusNode();
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback((_) {
_composerFocus.requestFocus();
});
}
// Then on the composer widget: focusNode: _composerFocus<!-- A visually-hidden region that screen readers announce -->
<div
aria-live="polite"
aria-atomic="true"
style="position: absolute; left: -9999px; height: 1px; width: 1px; overflow: hidden;"
id="message-announcer"></div>// Listen for new messages and announce
import { CometChat } from "@cometchat/chat-sdk-javascript";
const listenerId = "a11y-message-announcer";
CometChat.addMessageListener(listenerId, new CometChat.MessageListener({
onTextMessageReceived: (msg: CometChat.TextMessage) => {
const senderName = msg.getSender().getName();
const text = msg.getText();
const region = document.getElementById("message-announcer");
if (region) {
// Clearing first ensures the same text re-announces
region.textContent = "";
setTimeout(() => {
region.textContent = `New message from ${senderName}: ${text}`;
}, 100);
}
},
}));aria-live="polite"aria-live="assertive"import { AccessibilityInfo } from "react-native";
CometChat.addMessageListener(listenerId, new CometChat.MessageListener({
onTextMessageReceived: (msg) => {
const text = `New message from ${msg.getSender().getName()}: ${msg.getText()}`;
AccessibilityInfo.announceForAccessibility(text);
},
}));View.announceForAccessibility(text)UIAccessibility.post(notification: .announcement, argument: text)SemanticsService.announce(text, TextDirection.ltr)<div onClick>// ✗ WRONG — keyboard users can't activate
<div onClick={() => openConversation(c)}>{c.name}</div>
// ✓ RIGHT — `<button>` is keyboard + screen-reader native
<button onClick={() => openConversation(c)}>{c.name}</button>
// ✓ ALSO RIGHT — div with explicit ARIA + keyboard handlers
<div
role="button"
tabIndex={0}
onClick={() => openConversation(c)}
onKeyDown={(e) => {
if (e.key === "Enter" || e.key === " ") {
e.preventDefault();
openConversation(c);
}
}}
>
{c.name}
</div><a href="#message-composer" class="skip-link">Skip to message composer</a>.skip-link {
position: absolute;
left: -9999px;
z-index: 999;
}
.skip-link:focus {
left: 0;
top: 0;
background: white;
padding: 8px;
}useEffect(() => {
const handler = (e: KeyboardEvent) => {
// Cmd/Ctrl + K → focus search
if ((e.metaKey || e.ctrlKey) && e.key === "k") {
e.preventDefault();
searchRef.current?.focus();
}
// Escape → close any open thread / modal
if (e.key === "Escape") {
closeOpenThread();
}
};
window.addEventListener("keydown", handler);
return () => window.removeEventListener("keydown", handler);
}, []);@media (prefers-reduced-motion: reduce) {
/* Disable kit animations + your custom ones */
* {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
}import { AccessibilityInfo } from "react-native";
const [reduceMotion, setReduceMotion] = useState(false);
useEffect(() => {
AccessibilityInfo.isReduceMotionEnabled().then(setReduceMotion);
const sub = AccessibilityInfo.addEventListener("reduceMotionChanged", setReduceMotion);
return () => sub.remove();
}, []);
// In animations
<Animated.View
style={{
transform: [{ scale: reduceMotion ? 1 : animatedValue }],
}}
/>let reduceMotion = UIAccessibility.isReduceMotionEnabled
if !reduceMotion {
UIView.animate(withDuration: 0.3) { ... }
} else {
// Apply final state without animation
}val reduceMotion = Settings.Global.getFloat(
contentResolver, Settings.Global.ANIMATOR_DURATION_SCALE, 1.0f
) == 0.0ffinal reduceMotion = MediaQuery.of(context).disableAnimations;UIAccessibility.post(.announcement)npm install --save-dev @axe-core/playwrightimport { test, expect } from "@playwright/test";
import AxeBuilder from "@axe-core/playwright";
test("chat screen passes axe AA", async ({ page }) => {
await page.goto("/messages");
const results = await new AxeBuilder({ page }).withTags(["wcag2a", "wcag2aa"]).analyze();
expect(results.violations).toEqual([]);
});<div onClick>prefers-reduced-motionaria-live="assertive"<div onClick>prefers-reduced-motionisReduceMotionEnabledassertive<html lang="...">cometchat-i18nUIAccessibility.isReduceMotionEnabledcometchat-i18n<html lang>cometchat-{family}-customizationcometchat-{family}-troubleshooting