Merge pull request #226 from 7w1/accessibility

Accessibility updates
This commit is contained in:
7w1 authored and GitHub committed 2026-03-07 03:02:00 -06:00
commit 3ae9b19702
14 files changed
+411 -53

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
---
sable: minor
---
Added setting to always underline links.
+5
View File
@@ -0,0 +1,5 @@
---
sable: minor
---
Added settings for disabling autoplay of gifs (& banners), stickers, and emojis.
+5
View File
@@ -0,0 +1,5 @@
---
sable: minor
---
Added reduced motion setting. Let us know if any elements were missed!
+5
View File
@@ -0,0 +1,5 @@
---
sable: minor
---
Replaced the monochrome mode with a saturation slider for more control.
@@ -0,0 +1,76 @@
import { useEffect, useRef, useState } from 'react';
export function ClientSideHoverFreeze({
children,
src,
className,
}: {
children: React.ReactNode;
src: string;
className?: string;
}) {
const [isHovered, setIsHovered] = useState(false);
const canvasRef = useRef<HTMLCanvasElement>(null);
const [isCanvasReady, setIsCanvasReady] = useState(false);
useEffect(() => {
let isMounted = true;
const img = new window.Image();
img.crossOrigin = 'anonymous';
img.src = src;
img.onload = () => {
if (isMounted && canvasRef.current) {
canvasRef.current.width = img.naturalWidth || img.width;
canvasRef.current.height = img.naturalHeight || img.height;
const ctx = canvasRef.current.getContext('2d');
ctx?.drawImage(img, 0, 0);
setIsCanvasReady(true);
}
};
return () => {
isMounted = false;
};
}, [src]);
return (
<div
onMouseEnter={() => setIsHovered(true)}
onMouseLeave={() => setIsHovered(false)}
onFocus={() => setIsHovered(true)}
onBlur={() => setIsHovered(false)}
className={className}
style={{
position: 'relative',
display: 'inline-flex',
cursor: 'pointer',
verticalAlign: 'middle',
overflow: 'hidden',
borderRadius: 'inherit',
}}
>
<div
style={{
opacity: isHovered || !isCanvasReady ? 1 : 0,
display: 'flex',
width: '100%',
}}
>
{children}
</div>
<canvas
ref={canvasRef}
style={{
position: 'absolute',
top: 0,
left: 0,
width: '100%',
height: '100%',
objectFit: 'inherit',
opacity: !isHovered && isCanvasReady ? 1 : 0,
pointerEvents: 'none',
display: 'block',
}}
/>
</div>
);
}
+22 -1
View File
@@ -1,6 +1,8 @@
import { memo, useMemo, useCallback } from 'react';
import { MsgType } from '$types/matrix-sdk';
import { testMatrixTo } from '$plugins/matrix-to';
import { useSetting } from '$state/hooks/settings';
import { settingsAtom } from '$state/settings';
import { HTMLReactParserOptions } from 'html-react-parser';
import { Opts } from 'linkifyjs';
import { config } from 'folds';
@@ -30,6 +32,7 @@ import { Image, MediaControl, Video } from './media';
import { ImageViewer } from './image-viewer';
import { PdfViewer } from './Pdf-viewer';
import { TextViewer } from './text-viewer';
import { ClientSideHoverFreeze } from './ClientSideHoverFreeze';
type RenderMessageContentProps = {
displayName: string;
@@ -70,6 +73,8 @@ function RenderMessageContentInternal({
}: RenderMessageContentProps) {
const content = useMemo(() => getContent<any>(), [getContent]);
const [autoplayGifs] = useSetting(settingsAtom, 'autoplayGifs');
const renderBody = useCallback(
(props: any) => (
<RenderBody
@@ -192,6 +197,13 @@ function RenderMessageContentInternal({
}
if (msgType === MsgType.Image) {
const isGif =
content.info?.mimetype === 'image/gif' ||
content.info?.mimetype === 'image/webp' ||
content.body?.toLowerCase().endsWith('.gif') ||
content.body?.toLowerCase().endsWith('.webp') ||
(typeof content.url === 'string' && content.url.toLowerCase().includes('gif'));
return (
<>
<MImage
@@ -200,7 +212,16 @@ function RenderMessageContentInternal({
<ImageContent
{...imageProps}
autoPlay={mediaAutoLoad}
renderImage={(p) => <Image {...p} loading="lazy" />}
renderImage={(p) => {
if (isGif && !autoplayGifs && p.src) {
return (
<ClientSideHoverFreeze src={p.src}>
<Image {...p} loading="lazy" />
</ClientSideHoverFreeze>
);
}
return <Image {...p} loading="lazy" />;
}}
renderViewer={(p) => <ImageViewer {...p} />}
/>
)}
+32 -8
View File
@@ -1,4 +1,4 @@
import { useState } from 'react';
import { useMemo, useState } from 'react';
import {
Avatar,
Box,
@@ -27,6 +27,7 @@ import { useBlobCache } from '$hooks/useBlobCache';
import { ImageViewer } from '$components/image-viewer';
import { AvatarPresence, PresenceBadge } from '$components/presence';
import { UserAvatar } from '$components/user-avatar';
import { ClientSideHoverFreeze } from '$components/ClientSideHoverFreeze';
import * as css from './styles.css';
type UserHeroProps = {
@@ -34,8 +35,9 @@ type UserHeroProps = {
avatarUrl?: string;
bannerUrl?: string;
presence?: UserPresence;
autoplayGifs?: boolean;
};
export function UserHero({ userId, avatarUrl, bannerUrl, presence }: UserHeroProps) {
export function UserHero({ userId, avatarUrl, bannerUrl, presence, autoplayGifs }: UserHeroProps) {
const [viewAvatar, setViewAvatar] = useState<string>();
const [isFullStatus, setIsFullStatus] = useState(false);
@@ -45,6 +47,25 @@ export function UserHero({ userId, avatarUrl, bannerUrl, presence }: UserHeroPro
const coverUrl = cachedBannerUrl || cachedAvatarUrl;
const isFallbackCover = !cachedBannerUrl && !!cachedAvatarUrl;
const isAnimated = useMemo(() => {
if (!coverUrl) return false;
const url = coverUrl.toLowerCase();
const isStatic = url.endsWith('.jpg') || url.endsWith('.jpeg') || url.endsWith('.png');
return !isStatic || url.includes('gif') || url.includes('webp');
}, [coverUrl]);
const bannerClasses = classNames(css.UserHeroCover, isFallbackCover && css.UserHeroCoverFallback);
const renderCoverImage = () => (
<img
className={classNames(css.UserHeroCover, isFallbackCover && css.UserHeroCoverFallback)}
src={coverUrl}
alt={`${userId} cover`}
draggable="false"
/>
);
const status = presence?.status;
const isExpandable = (status?.length ?? 0) > 70;
@@ -57,12 +78,15 @@ export function UserHero({ userId, avatarUrl, bannerUrl, presence }: UserHeroPro
}}
>
{coverUrl && (
<img
className={classNames(css.UserHeroCover, isFallbackCover && css.UserHeroCoverFallback)}
src={coverUrl}
alt={`${userId} cover`}
draggable="false"
/>
<>
{isAnimated && !autoplayGifs ? (
<ClientSideHoverFreeze src={coverUrl} className={bannerClasses}>
{renderCoverImage()}
</ClientSideHoverFreeze>
) : (
renderCoverImage()
)}
</>
)}
</div>
<Box direction="Row" className={css.UserHeroAvatarStatusContainer}>
@@ -259,6 +259,8 @@ export function UserRoomProfile({ userId, initialProfile }: UserRoomProfileProps
const ignoredUsers = useIgnoredUsers();
const ignored = ignoredUsers.includes(userId);
const [autoplayGifs] = useSetting(settingsAtom, 'autoplayGifs');
const room = useRoom();
const powerLevels = usePowerLevels(room);
const creators = useRoomCreators(room);
@@ -348,6 +350,7 @@ export function UserRoomProfile({ userId, initialProfile }: UserRoomProfileProps
avatarUrl={avatarUrl}
bannerUrl={bannerHttpUrl ?? undefined}
presence={presence && presence.lastActiveTs !== 0 ? presence : undefined}
autoplayGifs={autoplayGifs}
/>
<Box direction="Column" gap="300" style={{ padding: config.space.S400 }}>
<Box direction="Column" gap="200">
+40 -7
View File
@@ -129,6 +129,7 @@ import { useRoomCreators } from '$hooks/useRoomCreators';
import { useRoomPermissions } from '$hooks/useRoomPermissions';
import { useGetMemberPowerTag } from '$hooks/useMemberPowerTag';
import { profilesCacheAtom } from '$state/userRoomProfile';
import { ClientSideHoverFreeze } from '$components/ClientSideHoverFreeze';
import * as css from './RoomTimeline.css';
import { EncryptedContent, Event, Message, Reactions } from './message';
@@ -571,10 +572,14 @@ export function RoomTimeline({
const showUrlPreview = room.hasEncryptionStateEvent() ? encUrlPreview : urlPreview;
const [showHiddenEvents] = useSetting(settingsAtom, 'showHiddenEvents');
const [showDeveloperTools] = useSetting(settingsAtom, 'developerTools');
const [reducedMotion] = useSetting(settingsAtom, 'reducedMotion');
const [hour24Clock] = useSetting(settingsAtom, 'hour24Clock');
const [dateFormatString] = useSetting(settingsAtom, 'dateFormatString');
const [autoplayStickers] = useSetting(settingsAtom, 'autoplayStickers');
const [autoplayEmojis] = useSetting(settingsAtom, 'autoplayEmojis');
const ignoredUsersList = useIgnoredUsers();
const ignoredUsersSet = useMemo(() => new Set(ignoredUsersList), [ignoredUsersList]);
const nicknames = useAtomValue(nicknamesAtom);
@@ -657,8 +662,18 @@ export function RoomTimeline({
handleSpoilerClick: spoilerClickHandler,
handleMentionClick: mentionClickHandler,
nicknames,
autoplayEmojis,
}),
[mx, room, linkifyOpts, spoilerClickHandler, mentionClickHandler, useAuthentication, nicknames]
[
mx,
room,
linkifyOpts,
autoplayEmojis,
spoilerClickHandler,
mentionClickHandler,
useAuthentication,
nicknames,
]
);
const parseMemberEvent = useMemberEventParser();
@@ -814,7 +829,7 @@ export function RoomTimeline({
if (typeof absoluteIndex === 'number') {
const scrolled = scrollToItem(absoluteIndex, {
behavior: 'smooth',
behavior: reducedMotion ? 'instant' : 'smooth',
align: 'center',
stopInView: true,
});
@@ -828,7 +843,7 @@ export function RoomTimeline({
loadEventTimeline(evtId);
}
},
[room, timeline, scrollToItem, loadEventTimeline]
[room, timeline, scrollToItem, loadEventTimeline, reducedMotion]
);
useLiveTimelineRefresh(
@@ -1067,7 +1082,7 @@ export function RoomTimeline({
if (scrollToBottomCount > 0) {
const scrollEl = scrollRef.current;
if (scrollEl) {
const behavior = scrollToBottomRef.current.smooth ? 'smooth' : 'instant';
const behavior = scrollToBottomRef.current.smooth && !reducedMotion ? 'smooth' : 'instant';
scrollToBottom(scrollEl, behavior);
// On Android WebView, layout may still settle after the initial scroll.
// Fire a second instant scroll after a short delay to guarantee we
@@ -1078,7 +1093,7 @@ export function RoomTimeline({
}
}
}
}, [scrollToBottomCount]);
}, [scrollToBottomCount, reducedMotion]);
// Remove unreadInfo on mark as read
useEffect(() => {
@@ -1478,7 +1493,16 @@ export function RoomTimeline({
<ImageContent
{...props}
autoPlay={mediaAutoLoad}
renderImage={(p) => <Image {...p} loading="lazy" />}
renderImage={(p) => {
if (!autoplayStickers && p.src) {
return (
<ClientSideHoverFreeze src={p.src}>
<Image {...p} loading="lazy" />
</ClientSideHoverFreeze>
);
}
return <Image {...p} loading="lazy" />;
}}
renderViewer={(p) => <ImageViewer {...p} />}
/>
)}
@@ -1598,7 +1622,16 @@ export function RoomTimeline({
<ImageContent
{...props}
autoPlay={mediaAutoLoad}
renderImage={(p) => <Image {...p} loading="lazy" />}
renderImage={(p) => {
if (!autoplayStickers && p.src) {
return (
<ClientSideHoverFreeze src={p.src}>
<Image {...p} loading="lazy" />
</ClientSideHoverFreeze>
);
}
return <Image {...p} loading="lazy" />;
}}
renderViewer={(p) => <ImageViewer {...p} />}
/>
)}
+64 -3
View File
@@ -244,7 +244,12 @@ function SystemThemePreferences() {
function ThemeSettings() {
const [systemTheme, setSystemTheme] = useSetting(settingsAtom, 'useSystemTheme');
const [monochromeMode, setMonochromeMode] = useSetting(settingsAtom, 'monochromeMode');
const [saturation, setSaturation] = useSetting(settingsAtom, 'saturationLevel');
const [underlineLinks, setUnderlineLinks] = useSetting(settingsAtom, 'underlineLinks');
const [reducedMotion, setReducedMotion] = useSetting(settingsAtom, 'reducedMotion');
const [autoplayGifs, setAutoplayGifs] = useSetting(settingsAtom, 'autoplayGifs');
const [autoplayStickers, setAutoplayStickers] = useSetting(settingsAtom, 'autoplayStickers');
const [autoplayEmojis, setAutoplayEmojis] = useSetting(settingsAtom, 'autoplayEmojis');
return (
<Box direction="Column" gap="100">
@@ -274,8 +279,64 @@ function ThemeSettings() {
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
<SettingTile
title="Monochrome Mode"
after={<Switch variant="Primary" value={monochromeMode} onChange={setMonochromeMode} />}
title="Saturation"
description={`${saturation}%`}
after={
<input
type="range"
min="0"
max="100"
step="1"
value={saturation}
onChange={(e) => setSaturation(parseInt(e.target.value, 10))}
style={{
width: toRem(160),
cursor: 'pointer',
appearance: 'none',
height: toRem(6),
borderRadius: config.radii.Pill,
backgroundColor: 'var(--sable-surface-container-line)',
accentColor: 'var(--sable-primary-main)',
}}
/>
}
/>
</SequenceCard>
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
<SettingTile
title="Underline Links"
description="Always show underlines on links in chat."
after={<Switch variant="Primary" value={underlineLinks} onChange={setUnderlineLinks} />}
/>
</SequenceCard>
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
<SettingTile
title="Reduced Motion"
description="Stops animations and sliding UI elements."
after={<Switch variant="Primary" value={reducedMotion} onChange={setReducedMotion} />}
/>
</SequenceCard>
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
<SettingTile
title="Autoplay GIFs"
description="Automatically play animated image uploads and links."
after={<Switch variant="Primary" value={autoplayGifs} onChange={setAutoplayGifs} />}
/>
</SequenceCard>
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
<SettingTile
title="Autoplay Stickers"
description="Automatically play animated stickers."
after={
<Switch variant="Primary" value={autoplayStickers} onChange={setAutoplayStickers} />
}
/>
</SequenceCard>
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
<SettingTile
title="Autoplay Emojis"
description="Automatically play animated custom emojis."
after={<Switch variant="Primary" value={autoplayEmojis} onChange={setAutoplayEmojis} />}
/>
</SequenceCard>
</Box>
+19 -4
View File
@@ -30,20 +30,35 @@ export function UnAuthRouteThemeManager() {
export function AuthRouteThemeManager({ children }: { children: ReactNode }) {
const activeTheme = useActiveTheme();
const [monochromeMode] = useSetting(settingsAtom, 'monochromeMode');
const [saturation] = useSetting(settingsAtom, 'saturationLevel');
const [underlineLinks] = useSetting(settingsAtom, 'underlineLinks');
const [reducedMotion] = useSetting(settingsAtom, 'reducedMotion');
useEffect(() => {
document.body.className = '';
document.body.classList.add(configClass, varsClass);
document.body.classList.add(...activeTheme.classNames);
if (monochromeMode) {
if (underlineLinks) {
document.body.classList.add('force-underline-links');
} else {
document.body.classList.remove('force-underline-links');
}
if (reducedMotion) {
document.body.classList.add('reduced-motion');
} else {
document.body.classList.remove('reduced-motion');
}
if (saturation === 0) {
document.body.style.filter = 'grayscale(1)';
} else if (saturation && saturation < 100) {
document.body.style.filter = `saturate(${saturation}%)`;
} else {
document.body.style.filter = '';
}
}, [activeTheme, monochromeMode]);
}, [activeTheme, saturation, underlineLinks, reducedMotion]);
return <ThemeContextProvider value={activeTheme}>{children}</ThemeContextProvider>;
}
+53 -27
View File
@@ -36,6 +36,7 @@ import { findAndReplace } from '$utils/findAndReplace';
import { onEnterOrSpace } from '$utils/keyboard';
import { copyToClipboard } from '$utils/dom';
import { useTimeoutToggle } from '$hooks/useTimeoutToggle';
import { ClientSideHoverFreeze } from '$components/ClientSideHoverFreeze';
import {
parseMatrixToRoom,
parseMatrixToRoomEvent,
@@ -341,6 +342,7 @@ export const getReactCustomHtmlParser = (
handleMentionClick?: ReactEventHandler<HTMLElement>;
useAuthentication?: boolean;
nicknames?: Nicknames;
autoplayEmojis?: boolean;
}
): HTMLReactParserOptions => {
const opts: HTMLReactParserOptions = {
@@ -547,25 +549,39 @@ export const getReactCustomHtmlParser = (
const siblingCount = domNode.parent?.children.length ?? 0;
// seperate style for bundled emojis
// seperate style for bundled emojis
if (siblingCount > 5) {
return (
<span className={css.EmoticonBase}>
<span className={css.Emoticon()}>
<FallbackImg
{...props}
src={htmlSrc}
className={css.EmoticonImg}
style={{ verticalAlign: 'middle' }}
fallback={
<span
title={`Failed to load: ${props.alt || props.title || ''}`}
className={css.EmoticonBase}
>
{props.alt || props.title ? `:${props.alt || props.title}:` : '?'}
</span>
}
/>
{!params.autoplayEmojis ? (
<ClientSideHoverFreeze src={htmlSrc}>
<FallbackImg
{...props}
src={htmlSrc}
className={css.EmoticonImg}
style={{ verticalAlign: 'middle' }}
fallback={
<span className={css.EmoticonBase}>
{props.alt || props.title || '?'}
</span>
}
/>
</ClientSideHoverFreeze>
) : (
<FallbackImg
{...props}
src={htmlSrc}
className={css.EmoticonImg}
style={{ verticalAlign: 'middle' }}
fallback={
<span className={css.EmoticonBase}>
{props.alt || props.title || '?'}
</span>
}
/>
)}
</span>
</span>
);
@@ -575,19 +591,29 @@ export const getReactCustomHtmlParser = (
return (
<span className={css.EmoticonBase}>
<span className={css.Emoticon()}>
<FallbackImg
{...props}
src={htmlSrc}
className={css.EmoticonImg}
fallback={
<span
title={`Failed to load: ${props.alt || props.title || ''}`}
className={css.EmoticonBase}
>
{props.alt || props.title ? `:${props.alt || props.title}:` : '?'}
</span>
}
/>
{!params.autoplayEmojis ? (
<ClientSideHoverFreeze src={htmlSrc}>
<FallbackImg
{...props}
src={htmlSrc}
className={css.EmoticonImg}
fallback={
<span className={css.EmoticonBase}>
{props.alt || props.title || '?'}
</span>
}
/>
</ClientSideHoverFreeze>
) : (
<FallbackImg
{...props}
src={htmlSrc}
className={css.EmoticonImg}
fallback={
<span className={css.EmoticonBase}>{props.alt || props.title || '?'}</span>
}
/>
)}
</span>
</span>
);
+24 -3
View File
@@ -22,7 +22,7 @@ export interface Settings {
useSystemTheme: boolean;
lightThemeId?: string;
darkThemeId?: string;
monochromeMode?: boolean;
saturationLevel?: number;
uniformIcons: boolean;
isMarkdown: boolean;
editorToolbar: boolean;
@@ -80,6 +80,11 @@ export interface Settings {
showPingCounts: boolean;
hideReads: boolean;
emojiSuggestThreshold: number;
underlineLinks: boolean;
reducedMotion: boolean;
autoplayGifs: boolean;
autoplayStickers: boolean;
autoplayEmojis: boolean;
// furry stuff
renderAnimals: boolean;
@@ -90,7 +95,7 @@ const defaultSettings: Settings = {
useSystemTheme: true,
lightThemeId: undefined,
darkThemeId: undefined,
monochromeMode: false,
saturationLevel: 100,
uniformIcons: false,
isMarkdown: true,
editorToolbar: false,
@@ -149,6 +154,11 @@ const defaultSettings: Settings = {
showPingCounts: true,
hideReads: false,
emojiSuggestThreshold: 2,
underlineLinks: false,
reducedMotion: false,
autoplayGifs: true,
autoplayStickers: true,
autoplayEmojis: true,
// furry stuff
renderAnimals: true,
@@ -157,9 +167,20 @@ const defaultSettings: Settings = {
export const getSettings = () => {
const settings = localStorage.getItem(STORAGE_KEY);
if (settings === null) return defaultSettings;
// migration for old keys
// monochrome -> saturation
const parsed = JSON.parse(settings);
if (parsed.monochromeMode === true && parsed.saturationLevel === undefined) {
parsed.saturationLevel = 0;
} else if (parsed.monochromeMode === false && parsed.saturationLevel === undefined) {
parsed.saturationLevel = 100;
}
delete parsed.monochromeMode;
return {
...defaultSettings,
...(JSON.parse(settings) as Settings),
...(parsed as Settings),
};
};
+58
View File
@@ -174,3 +174,61 @@ pre {
letter-spacing: -0.01em;
font-variant-ligatures: contextual;
}
/* Accessibility Overrides :D */
.force-underline-links a {
text-decoration: underline !important;
text-decoration-thickness: 1px;
text-underline-offset: 2px;
}
body.reduced-motion * {
animation-duration: 0.001ms !important;
transition-duration: 0.001ms !important;
}
body.reduced-motion button:hover,
body.reduced-motion a:hover,
body.reduced-motion [role='button']:hover {
transform: none !important;
scale: 1 !important;
}
body.reduced-motion div[class*='Sidebar_SidebarItem']:hover,
body.reduced-motion div[class*='Sidebar_SidebarItem']:hover button,
body.reduced-motion div[class*='Sidebar_SidebarItem']:hover img {
transform: none !important;
scale: 1 !important;
translate: none !important;
margin: 0 !important;
padding: 0 !important;
}
body.reduced-motion div[class*='Sidebar_SidebarStack']:hover {
width: revert !important;
translate: none !important;
transform: none !important;
}
body.reduced-motion div[class*='layout_MessageBase'] {
animation: none !important;
transition: none !important;
transform: none !important;
}
body.reduced-motion div[class*='RoomTimeline_messageList'],
body.reduced-motion div[class*='RoomTimeline_messageList'] > * {
scroll-behavior: auto !important;
}
body.reduced-motion span[class*='layout_AvatarBase']:hover,
body.reduced-motion span[class*='layout_AvatarBase']:hover *,
body.reduced-motion button[class*='styles_MessageAvatar']:hover,
body.reduced-motion button[class*='styles_MessageAvatar']:hover * {
transform: none !important;
scale: 1 !important;
translate: none !important;
animation: none !important;
margin: 0 !important;
}