Add keyboard activation to the interactive elements and use stable keys. [skip build]
This commit is contained in:
@@ -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>(
|
||||
<div
|
||||
ref={frameRef}
|
||||
className={css.Frame}
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
aria-label={alt || undefined}
|
||||
onKeyDown={handleKeyDown}
|
||||
data-zoomed={zoomed || undefined}
|
||||
data-pannable={zoomed || undefined}
|
||||
data-dragging={dragging || undefined}
|
||||
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
} from 'matrix-js-sdk';
|
||||
import { useAtomValue } from 'jotai';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { onEnterOrSpace } from '../../utils/keyboard';
|
||||
import { WindowControls } from './WindowControls';
|
||||
import { UpdateNotification } from '../update-notification';
|
||||
import * as css from './TitleBar.css';
|
||||
@@ -688,6 +689,9 @@ export function TitleBar({ mx, children }: TitleBarProps) {
|
||||
{notifications.map((notification) => (
|
||||
<div
|
||||
key={notification.id}
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
onKeyDown={onEnterOrSpace(handleNotificationClick(notification))}
|
||||
className={`${css.NewMessagePill} ${notification.exiting ? css.NewMessagePillExiting : ''}`}
|
||||
onClick={handleNotificationClick(notification)}
|
||||
onMouseDown={(e) => e.stopPropagation()}
|
||||
|
||||
@@ -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<string>();
|
||||
const bannerUrl = useOtherUserBanner(userId);
|
||||
const { assetUrls } = useOtherUserCollectibles(userId);
|
||||
|
||||
@@ -94,7 +94,6 @@ export function UserRoomProfile({ userId }: UserRoomProfileProps) {
|
||||
<UserHero
|
||||
userId={userId}
|
||||
avatarUrl={avatarUrl}
|
||||
avatarMxc={avatarMxc}
|
||||
presence={presence && presence.lastActiveTs !== 0 ? presence : undefined}
|
||||
>
|
||||
<Box
|
||||
|
||||
Reference in New Issue
Block a user