From eaa9ac00dd22ff70b6c3aca3fedb7f4a960a26d6 Mon Sep 17 00:00:00 2001 From: litruv Date: Sun, 1 Nov 2026 21:32:32 +1100 Subject: [PATCH] Add keyboard activation to the interactive elements and use stable keys. [skip build] --- .../components/image-viewer/ImageViewer.tsx | 26 +++++++++++++++---- src/app/components/title-bar/TitleBar.tsx | 4 +++ src/app/components/user-profile/UserHero.tsx | 3 +-- .../user-profile/UserRoomProfile.tsx | 1 - src/app/features/forum/ForumChatComposer.tsx | 3 --- src/app/features/settings/account/Profile.tsx | 15 +++-------- src/app/pages/client/space/Space.tsx | 8 +++--- src/app/plugins/react-custom-html-parser.tsx | 24 ++++++++++++++--- 8 files changed, 54 insertions(+), 30 deletions(-) diff --git a/src/app/components/image-viewer/ImageViewer.tsx b/src/app/components/image-viewer/ImageViewer.tsx index 0f2b7fd0..d037947a 100644 --- a/src/app/components/image-viewer/ImageViewer.tsx +++ b/src/app/components/image-viewer/ImageViewer.tsx @@ -5,6 +5,7 @@ import { Icon, Icons } from '../icons'; import * as css from './ImageViewer.css'; import { downloadAndSaveMedia } from '../../utils/saveMedia'; import { getCurrentAccessToken } from '../../utils/auth'; +import { onEnterOrSpace } from '../../utils/keyboard'; const ZOOM_MIN = 1; const ZOOM_MAX = 5; @@ -270,6 +271,14 @@ export const ImageViewer = as<'div', ImageViewerProps>( } }; + const toggleZoomAt = (x: number, y: number) => { + if (zoomRef.current.scale <= 1.01) { + zoomAround(x, y, ZOOM_CLICK); + } else { + resetZoom(); + } + }; + const handleClick = (event: React.MouseEvent) => { if (suppressClickRef.current) { suppressClickRef.current = false; @@ -283,13 +292,16 @@ export const ImageViewer = as<'div', ImageViewerProps>( if (!img?.src) return; event.preventDefault(); const { x, y } = framePoint(event.clientX, event.clientY); - if (zoomRef.current.scale <= 1.01) { - zoomAround(x, y, ZOOM_CLICK); - } else { - resetZoom(); - } + toggleZoomAt(x, y); }; + // Keyboard activation has no pointer position, so it zooms around the frame centre. + const handleKeyDown = onEnterOrSpace(() => { + const frame = frameRef.current; + if (!frame || !imgRef.current?.src) return; + toggleZoomAt(frame.clientWidth / 2, frame.clientHeight / 2); + }); + const handlePointerDown = (event: React.PointerEvent) => { if (event.button !== 0 && event.pointerType === 'mouse') return; @@ -410,6 +422,10 @@ export const ImageViewer = as<'div', ImageViewerProps>(
(
e.stopPropagation()} diff --git a/src/app/components/user-profile/UserHero.tsx b/src/app/components/user-profile/UserHero.tsx index 46e0963e..cd90ea52 100644 --- a/src/app/components/user-profile/UserHero.tsx +++ b/src/app/components/user-profile/UserHero.tsx @@ -22,11 +22,10 @@ import { ProfileCollectibleOverlays } from './ProfileCollectibleOverlays'; type UserHeroProps = { userId: string; avatarUrl?: string; - avatarMxc?: string; presence?: UserPresence; children?: ReactNode; }; -export function UserHero({ userId, avatarUrl, avatarMxc, presence, children }: UserHeroProps) { +export function UserHero({ userId, avatarUrl, presence, children }: UserHeroProps) { const [viewAvatar, setViewAvatar] = useState(); const bannerUrl = useOtherUserBanner(userId); const { assetUrls } = useOtherUserCollectibles(userId); diff --git a/src/app/components/user-profile/UserRoomProfile.tsx b/src/app/components/user-profile/UserRoomProfile.tsx index 5fbd8b5f..1aec998d 100644 --- a/src/app/components/user-profile/UserRoomProfile.tsx +++ b/src/app/components/user-profile/UserRoomProfile.tsx @@ -94,7 +94,6 @@ export function UserRoomProfile({ userId }: UserRoomProfileProps) { void; showAttachButton?: boolean; @@ -39,7 +37,6 @@ type ForumChatComposerProps = { export function ForumChatComposer({ editor, roomId, - room, placeholder = 'Send a message…', onSend, showAttachButton = false, diff --git a/src/app/features/settings/account/Profile.tsx b/src/app/features/settings/account/Profile.tsx index f7307f00..2f17bc97 100644 --- a/src/app/features/settings/account/Profile.tsx +++ b/src/app/features/settings/account/Profile.tsx @@ -1,4 +1,4 @@ -import React, { ChangeEvent, useCallback, useEffect, useMemo, useRef, useState } from 'react'; +import React, { ChangeEvent, useCallback, useEffect, useMemo, useState } from 'react'; import classNames from 'classnames'; import { Box, Text, Input, Avatar, Button, config, Spinner, color, toRem } from 'folds'; import { HexColorPicker } from 'react-colorful'; @@ -38,13 +38,7 @@ import { /** * Banner upload component for user's profile banner (MSC4427 via MSC4133). */ -function ProfileBanner({ - avatarRef, - nameRef, -}: { - avatarRef: React.RefObject; - nameRef: React.RefObject; -}) { +function ProfileBanner() { const mx = useMatrixClient(); const useAuthentication = useMediaAuthentication(); const userId = mx.getUserId()!; @@ -1207,8 +1201,5 @@ function ProfileBanner({ } export function Profile() { - const avatarRef = useRef(null); - const nameRef = useRef(null); - - return ; + return ; } diff --git a/src/app/pages/client/space/Space.tsx b/src/app/pages/client/space/Space.tsx index c3a92aee..191615c9 100644 --- a/src/app/pages/client/space/Space.tsx +++ b/src/app/pages/client/space/Space.tsx @@ -112,11 +112,11 @@ function SpaceNavSection({ {section.items.length > 0 && (
- {section.items.map((item, index) => { + {section.items.map((item) => { if (item.type === 'unjoined-subroom') { return ( + {content} ); @@ -508,7 +514,13 @@ export function InlineCode({ return ( - + {copied ? ( ) : ( @@ -681,7 +693,13 @@ export const getReactCustomHtmlParser = ( // Handle external links - add click handler for Tauri if (props.href?.startsWith('http://') || props.href?.startsWith('https://')) { return ( - + {domToReact(children, opts)} );