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 * as css from './ImageViewer.css';
|
||||||
import { downloadAndSaveMedia } from '../../utils/saveMedia';
|
import { downloadAndSaveMedia } from '../../utils/saveMedia';
|
||||||
import { getCurrentAccessToken } from '../../utils/auth';
|
import { getCurrentAccessToken } from '../../utils/auth';
|
||||||
|
import { onEnterOrSpace } from '../../utils/keyboard';
|
||||||
|
|
||||||
const ZOOM_MIN = 1;
|
const ZOOM_MIN = 1;
|
||||||
const ZOOM_MAX = 5;
|
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) => {
|
const handleClick = (event: React.MouseEvent) => {
|
||||||
if (suppressClickRef.current) {
|
if (suppressClickRef.current) {
|
||||||
suppressClickRef.current = false;
|
suppressClickRef.current = false;
|
||||||
@@ -283,13 +292,16 @@ export const ImageViewer = as<'div', ImageViewerProps>(
|
|||||||
if (!img?.src) return;
|
if (!img?.src) return;
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
const { x, y } = framePoint(event.clientX, event.clientY);
|
const { x, y } = framePoint(event.clientX, event.clientY);
|
||||||
if (zoomRef.current.scale <= 1.01) {
|
toggleZoomAt(x, y);
|
||||||
zoomAround(x, y, ZOOM_CLICK);
|
|
||||||
} else {
|
|
||||||
resetZoom();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 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) => {
|
const handlePointerDown = (event: React.PointerEvent) => {
|
||||||
if (event.button !== 0 && event.pointerType === 'mouse') return;
|
if (event.button !== 0 && event.pointerType === 'mouse') return;
|
||||||
|
|
||||||
@@ -410,6 +422,10 @@ export const ImageViewer = as<'div', ImageViewerProps>(
|
|||||||
<div
|
<div
|
||||||
ref={frameRef}
|
ref={frameRef}
|
||||||
className={css.Frame}
|
className={css.Frame}
|
||||||
|
role="button"
|
||||||
|
tabIndex={0}
|
||||||
|
aria-label={alt || undefined}
|
||||||
|
onKeyDown={handleKeyDown}
|
||||||
data-zoomed={zoomed || undefined}
|
data-zoomed={zoomed || undefined}
|
||||||
data-pannable={zoomed || undefined}
|
data-pannable={zoomed || undefined}
|
||||||
data-dragging={dragging || undefined}
|
data-dragging={dragging || undefined}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import {
|
|||||||
} from 'matrix-js-sdk';
|
} from 'matrix-js-sdk';
|
||||||
import { useAtomValue } from 'jotai';
|
import { useAtomValue } from 'jotai';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
|
import { onEnterOrSpace } from '../../utils/keyboard';
|
||||||
import { WindowControls } from './WindowControls';
|
import { WindowControls } from './WindowControls';
|
||||||
import { UpdateNotification } from '../update-notification';
|
import { UpdateNotification } from '../update-notification';
|
||||||
import * as css from './TitleBar.css';
|
import * as css from './TitleBar.css';
|
||||||
@@ -688,6 +689,9 @@ export function TitleBar({ mx, children }: TitleBarProps) {
|
|||||||
{notifications.map((notification) => (
|
{notifications.map((notification) => (
|
||||||
<div
|
<div
|
||||||
key={notification.id}
|
key={notification.id}
|
||||||
|
role="button"
|
||||||
|
tabIndex={0}
|
||||||
|
onKeyDown={onEnterOrSpace(handleNotificationClick(notification))}
|
||||||
className={`${css.NewMessagePill} ${notification.exiting ? css.NewMessagePillExiting : ''}`}
|
className={`${css.NewMessagePill} ${notification.exiting ? css.NewMessagePillExiting : ''}`}
|
||||||
onClick={handleNotificationClick(notification)}
|
onClick={handleNotificationClick(notification)}
|
||||||
onMouseDown={(e) => e.stopPropagation()}
|
onMouseDown={(e) => e.stopPropagation()}
|
||||||
|
|||||||
@@ -22,11 +22,10 @@ import { ProfileCollectibleOverlays } from './ProfileCollectibleOverlays';
|
|||||||
type UserHeroProps = {
|
type UserHeroProps = {
|
||||||
userId: string;
|
userId: string;
|
||||||
avatarUrl?: string;
|
avatarUrl?: string;
|
||||||
avatarMxc?: string;
|
|
||||||
presence?: UserPresence;
|
presence?: UserPresence;
|
||||||
children?: ReactNode;
|
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 [viewAvatar, setViewAvatar] = useState<string>();
|
||||||
const bannerUrl = useOtherUserBanner(userId);
|
const bannerUrl = useOtherUserBanner(userId);
|
||||||
const { assetUrls } = useOtherUserCollectibles(userId);
|
const { assetUrls } = useOtherUserCollectibles(userId);
|
||||||
|
|||||||
@@ -94,7 +94,6 @@ export function UserRoomProfile({ userId }: UserRoomProfileProps) {
|
|||||||
<UserHero
|
<UserHero
|
||||||
userId={userId}
|
userId={userId}
|
||||||
avatarUrl={avatarUrl}
|
avatarUrl={avatarUrl}
|
||||||
avatarMxc={avatarMxc}
|
|
||||||
presence={presence && presence.lastActiveTs !== 0 ? presence : undefined}
|
presence={presence && presence.lastActiveTs !== 0 ? presence : undefined}
|
||||||
>
|
>
|
||||||
<Box
|
<Box
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import { isKeyHotkey } from 'is-hotkey';
|
|||||||
import { Editor } from 'slate';
|
import { Editor } from 'slate';
|
||||||
import { IconButton, Line, PopOut } from 'folds';
|
import { IconButton, Line, PopOut } from 'folds';
|
||||||
import { useAtomValue } from 'jotai';
|
import { useAtomValue } from 'jotai';
|
||||||
import { Room } from 'matrix-js-sdk';
|
|
||||||
import { Icon, Icons } from '../../components/icons';
|
import { Icon, Icons } from '../../components/icons';
|
||||||
import {
|
import {
|
||||||
CustomEditor,
|
CustomEditor,
|
||||||
@@ -28,7 +27,6 @@ import { PluginButtonSlot } from '../settings/plugins/PluginButtonSlot';
|
|||||||
type ForumChatComposerProps = {
|
type ForumChatComposerProps = {
|
||||||
editor: Editor;
|
editor: Editor;
|
||||||
roomId: string;
|
roomId: string;
|
||||||
room: Room;
|
|
||||||
placeholder?: string;
|
placeholder?: string;
|
||||||
onSend?: () => void;
|
onSend?: () => void;
|
||||||
showAttachButton?: boolean;
|
showAttachButton?: boolean;
|
||||||
@@ -39,7 +37,6 @@ type ForumChatComposerProps = {
|
|||||||
export function ForumChatComposer({
|
export function ForumChatComposer({
|
||||||
editor,
|
editor,
|
||||||
roomId,
|
roomId,
|
||||||
room,
|
|
||||||
placeholder = 'Send a message…',
|
placeholder = 'Send a message…',
|
||||||
onSend,
|
onSend,
|
||||||
showAttachButton = false,
|
showAttachButton = false,
|
||||||
|
|||||||
@@ -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 classNames from 'classnames';
|
||||||
import { Box, Text, Input, Avatar, Button, config, Spinner, color, toRem } from 'folds';
|
import { Box, Text, Input, Avatar, Button, config, Spinner, color, toRem } from 'folds';
|
||||||
import { HexColorPicker } from 'react-colorful';
|
import { HexColorPicker } from 'react-colorful';
|
||||||
@@ -38,13 +38,7 @@ import {
|
|||||||
/**
|
/**
|
||||||
* Banner upload component for user's profile banner (MSC4427 via MSC4133).
|
* Banner upload component for user's profile banner (MSC4427 via MSC4133).
|
||||||
*/
|
*/
|
||||||
function ProfileBanner({
|
function ProfileBanner() {
|
||||||
avatarRef,
|
|
||||||
nameRef,
|
|
||||||
}: {
|
|
||||||
avatarRef: React.RefObject<HTMLDivElement>;
|
|
||||||
nameRef: React.RefObject<HTMLDivElement>;
|
|
||||||
}) {
|
|
||||||
const mx = useMatrixClient();
|
const mx = useMatrixClient();
|
||||||
const useAuthentication = useMediaAuthentication();
|
const useAuthentication = useMediaAuthentication();
|
||||||
const userId = mx.getUserId()!;
|
const userId = mx.getUserId()!;
|
||||||
@@ -1207,8 +1201,5 @@ function ProfileBanner({
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function Profile() {
|
export function Profile() {
|
||||||
const avatarRef = useRef<HTMLDivElement>(null);
|
return <ProfileBanner />;
|
||||||
const nameRef = useRef<HTMLDivElement>(null);
|
|
||||||
|
|
||||||
return <ProfileBanner avatarRef={avatarRef} nameRef={nameRef} />;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -112,11 +112,11 @@ function SpaceNavSection({
|
|||||||
{section.items.length > 0 && (
|
{section.items.length > 0 && (
|
||||||
<div data-nav-rooms="">
|
<div data-nav-rooms="">
|
||||||
<div data-nav-room-list="">
|
<div data-nav-room-list="">
|
||||||
{section.items.map((item, index) => {
|
{section.items.map((item) => {
|
||||||
if (item.type === 'unjoined-subroom') {
|
if (item.type === 'unjoined-subroom') {
|
||||||
return (
|
return (
|
||||||
<UnjoinedSubRoomItem
|
<UnjoinedSubRoomItem
|
||||||
key={`${item.roomId}:${index}`}
|
key={item.roomId}
|
||||||
roomId={item.roomId}
|
roomId={item.roomId}
|
||||||
depth={item.depth}
|
depth={item.depth}
|
||||||
isLast={item.isLast}
|
isLast={item.isLast}
|
||||||
@@ -127,7 +127,7 @@ function SpaceNavSection({
|
|||||||
if (item.type === 'subroom') {
|
if (item.type === 'subroom') {
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
key={`${item.roomId}:${index}`}
|
key={item.roomId}
|
||||||
data-nav-depth={item.depth}
|
data-nav-depth={item.depth}
|
||||||
style={{
|
style={{
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
@@ -158,7 +158,7 @@ function SpaceNavSection({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<RoomNavItem
|
<RoomNavItem
|
||||||
key={`${item.roomId}:${index}`}
|
key={item.roomId}
|
||||||
room={room}
|
room={room}
|
||||||
selected={selectedRoomId === item.roomId}
|
selected={selectedRoomId === item.roomId}
|
||||||
showAvatar={mDirects.has(item.roomId)}
|
showAvatar={mDirects.has(item.roomId)}
|
||||||
|
|||||||
@@ -197,7 +197,13 @@ export const factoryRenderLinkifyWithMention = (
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<a {...attributes} onClick={handleExternalLinkClick}>
|
<a
|
||||||
|
{...attributes}
|
||||||
|
role="link"
|
||||||
|
tabIndex={0}
|
||||||
|
onKeyDown={onEnterOrSpace(handleExternalLinkClick)}
|
||||||
|
onClick={handleExternalLinkClick}
|
||||||
|
>
|
||||||
{content}
|
{content}
|
||||||
</a>
|
</a>
|
||||||
);
|
);
|
||||||
@@ -508,7 +514,13 @@ export function InlineCode({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<span className={css.InlineCodeWrapper}>
|
<span className={css.InlineCodeWrapper}>
|
||||||
<span className={css.InlineCodeCopyButton} onClick={handleCopy}>
|
<span
|
||||||
|
className={css.InlineCodeCopyButton}
|
||||||
|
role="button"
|
||||||
|
tabIndex={0}
|
||||||
|
onKeyDown={onEnterOrSpace(handleCopy)}
|
||||||
|
onClick={handleCopy}
|
||||||
|
>
|
||||||
{copied ? (
|
{copied ? (
|
||||||
<Icon size="50" src={Icons.Check} />
|
<Icon size="50" src={Icons.Check} />
|
||||||
) : (
|
) : (
|
||||||
@@ -681,7 +693,13 @@ export const getReactCustomHtmlParser = (
|
|||||||
// Handle external links - add click handler for Tauri
|
// Handle external links - add click handler for Tauri
|
||||||
if (props.href?.startsWith('http://') || props.href?.startsWith('https://')) {
|
if (props.href?.startsWith('http://') || props.href?.startsWith('https://')) {
|
||||||
return (
|
return (
|
||||||
<a {...props} onClick={handleExternalLinkClick}>
|
<a
|
||||||
|
{...props}
|
||||||
|
role="link"
|
||||||
|
tabIndex={0}
|
||||||
|
onKeyDown={onEnterOrSpace(handleExternalLinkClick)}
|
||||||
|
onClick={handleExternalLinkClick}
|
||||||
|
>
|
||||||
{domToReact(children, opts)}
|
{domToReact(children, opts)}
|
||||||
</a>
|
</a>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user