mirror of
https://github.com/SlimeVR/SlimeVR-Server.git
synced 2026-12-05 16:22:32 -08:00
More accessibility stuff
This commit is contained in:
1 parent
dbed346fe8
commit
b6a34cee91
4 files changed
+94
-5
No files matched your search
@@ -1154,6 +1154,10 @@ onboarding-assign_trackers-tab-fingers = Fingers
|
||||
onboarding-assign_trackers-tab-toes = Toes
|
||||
onboarding-assign_trackers-side-right = Right
|
||||
onboarding-assign_trackers-side-left = Left
|
||||
# Accessible name for the left/right pill radiogroup in the assignment panel header
|
||||
onboarding-assign_trackers-side = Body side
|
||||
# Accessible name for the mirror-view pill toggle in the assignment panel header
|
||||
onboarding-assign_trackers-mirror = Mirror view
|
||||
onboarding-assign_trackers-finger-thumb = Thumb
|
||||
onboarding-assign_trackers-finger-index = Index finger
|
||||
onboarding-assign_trackers-finger-middle = Middle finger
|
||||
|
||||
@@ -1,15 +1,21 @@
|
||||
import classNames from 'classnames';
|
||||
import { Clickable } from './Clickable';
|
||||
import { ReactNode } from 'react';
|
||||
import { KeyboardEvent, ReactNode } from 'react';
|
||||
import { Typography } from './Typography';
|
||||
|
||||
export function TogglePill({
|
||||
compact,
|
||||
onClick,
|
||||
pressed,
|
||||
label,
|
||||
radiogroupLabel,
|
||||
children,
|
||||
}: {
|
||||
compact?: boolean;
|
||||
onClick?: () => void;
|
||||
pressed?: boolean;
|
||||
label?: string;
|
||||
radiogroupLabel?: string;
|
||||
children: ReactNode;
|
||||
}) {
|
||||
const className = classNames(
|
||||
@@ -18,27 +24,77 @@ export function TogglePill({
|
||||
compact ? 'p-0.5' : 'p-1'
|
||||
);
|
||||
|
||||
if (radiogroupLabel !== undefined) {
|
||||
return (
|
||||
<div
|
||||
role="radiogroup"
|
||||
aria-label={radiogroupLabel}
|
||||
className={className}
|
||||
onKeyDown={handleRadioKeys}
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (!onClick) return <div className={className}>{children}</div>;
|
||||
|
||||
return (
|
||||
<Clickable onClick={onClick} className={className}>
|
||||
<Clickable
|
||||
onClick={onClick}
|
||||
pressed={pressed}
|
||||
label={label}
|
||||
className={className}
|
||||
>
|
||||
{children}
|
||||
</Clickable>
|
||||
);
|
||||
}
|
||||
|
||||
function handleRadioKeys(e: KeyboardEvent<HTMLDivElement>) {
|
||||
const step: Record<string, number> = {
|
||||
ArrowRight: 1,
|
||||
ArrowDown: 1,
|
||||
ArrowLeft: -1,
|
||||
ArrowUp: -1,
|
||||
};
|
||||
if (!(e.key in step) && e.key !== 'Home' && e.key !== 'End') return;
|
||||
|
||||
const radios = Array.from(
|
||||
e.currentTarget.querySelectorAll<HTMLElement>(
|
||||
'[role="radio"]:not([disabled])'
|
||||
)
|
||||
);
|
||||
const current = radios.indexOf(document.activeElement as HTMLElement);
|
||||
if (current < 0) return;
|
||||
|
||||
e.preventDefault();
|
||||
const last = radios.length - 1;
|
||||
const next =
|
||||
e.key === 'Home'
|
||||
? 0
|
||||
: e.key === 'End'
|
||||
? last
|
||||
: (current + step[e.key] + radios.length) % radios.length;
|
||||
|
||||
radios[next].focus();
|
||||
radios[next].click();
|
||||
}
|
||||
|
||||
export function TogglePillOption({
|
||||
compact,
|
||||
dotClass,
|
||||
labelId,
|
||||
active,
|
||||
onClick,
|
||||
radio,
|
||||
}: {
|
||||
compact?: boolean;
|
||||
dotClass: string;
|
||||
labelId: string;
|
||||
active?: boolean;
|
||||
onClick?: () => void;
|
||||
radio?: boolean;
|
||||
}) {
|
||||
const className = classNames(
|
||||
'flex items-center rounded-full',
|
||||
@@ -62,6 +118,20 @@ export function TogglePillOption({
|
||||
|
||||
if (!onClick) return <div className={className}>{content}</div>;
|
||||
|
||||
if (radio) {
|
||||
return (
|
||||
<Clickable
|
||||
onClick={onClick}
|
||||
role="radio"
|
||||
aria-checked={active}
|
||||
tabIndex={active ? 0 : -1}
|
||||
className={className}
|
||||
>
|
||||
{content}
|
||||
</Clickable>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Clickable onClick={onClick} pressed={active} className={className}>
|
||||
{content}
|
||||
|
||||
@@ -35,6 +35,7 @@ export function ShowAllPartsToggle({ compact }: { compact?: boolean }) {
|
||||
}
|
||||
|
||||
export function MirrorLegend({ compact }: { compact?: boolean }) {
|
||||
const { l10n } = useLocalization();
|
||||
const { config, setConfig } = useConfig();
|
||||
const mirror = config?.mirrorView ?? false;
|
||||
|
||||
@@ -53,6 +54,8 @@ export function MirrorLegend({ compact }: { compact?: boolean }) {
|
||||
return (
|
||||
<TogglePill
|
||||
compact={compact}
|
||||
pressed={mirror}
|
||||
label={l10n.getString('onboarding-assign_trackers-mirror')}
|
||||
onClick={() => setConfig({ mirrorView: !mirror })}
|
||||
>
|
||||
{pill('right')}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import classNames from 'classnames';
|
||||
import { useLocalization } from '@fluent/react';
|
||||
import { Clickable } from '@/components/commons/Clickable';
|
||||
import {
|
||||
HTMLAttributes,
|
||||
@@ -265,14 +266,19 @@ function Tab({
|
||||
pressed={active}
|
||||
onClick={onClick}
|
||||
className={classNames(
|
||||
'rounded-md',
|
||||
'grid place-items-center rounded-md',
|
||||
compact ? 'px-3 py-1' : 'px-4 py-2',
|
||||
active && 'bg-background-50',
|
||||
disabled && 'opacity-40 cursor-not-allowed',
|
||||
!disabled && !active && 'cursor-pointer hover:bg-background-60'
|
||||
)}
|
||||
>
|
||||
<Typography bold={active} id={labelId} />
|
||||
<div aria-hidden className="invisible col-start-1 row-start-1">
|
||||
<Typography bold id={labelId} />
|
||||
</div>
|
||||
<div className="col-start-1 row-start-1">
|
||||
<Typography bold={active} id={labelId} />
|
||||
</div>
|
||||
</Clickable>
|
||||
);
|
||||
}
|
||||
@@ -288,9 +294,12 @@ export function ExtremitySideToggle({
|
||||
side: ExtremitySide;
|
||||
onChange: (side: ExtremitySide) => void;
|
||||
}) {
|
||||
const { l10n } = useLocalization();
|
||||
|
||||
const option = (value: ExtremitySide, dotClass: string) => (
|
||||
<TogglePillOption
|
||||
compact={compact}
|
||||
radio
|
||||
dotClass={dotClass}
|
||||
active={side === value}
|
||||
onClick={() => onChange(value)}
|
||||
@@ -299,7 +308,10 @@ export function ExtremitySideToggle({
|
||||
);
|
||||
|
||||
return (
|
||||
<TogglePill compact={compact}>
|
||||
<TogglePill
|
||||
compact={compact}
|
||||
radiogroupLabel={l10n.getString('onboarding-assign_trackers-side')}
|
||||
>
|
||||
{option('left', 'outline-assign-left')}
|
||||
{option('right', 'outline-assign-right')}
|
||||
</TogglePill>
|
||||
|
||||
Reference in new issue
Block a user