Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp

fix(app): improve form and message control accessibility

Hampusa92b5bc853c5
diff --git a/fluxer_app/src/features/channel/components/MessageUsername.tsx b/fluxer_app/src/features/channel/components/MessageUsername.tsx
index 978beedfa..7cf546c07 100644
--- a/fluxer_app/src/features/channel/components/MessageUsername.tsx
+++ b/fluxer_app/src/features/channel/components/MessageUsername.tsx
@@ -53,14 +53,13 @@ export const MessageUsername = observer(
const keyboardModeEnabled = KeyboardMode.keyboardModeEnabled;
const usernameNode = (
<FocusRing data-flx="channel.message-username.focus-ring">
- {/* biome-ignore lint/a11y/noStaticElementInteractions: the username span is only keyboard-interactive in keyboard mode (role="button"/tabIndex set conditionally); pointer/popout/context-menu interactions are handled by the wrapping PreloadableUserPopout. */}
<span
className={clsx(className, contextMenuOpen && styles.contextMenuUnderline)}
style={{color}}
data-user-id={user.id}
data-guild-id={guild?.id}
tabIndex={keyboardModeEnabled ? 0 : undefined}
- role={keyboardModeEnabled ? 'button' : undefined}
+ role="button"
ref={usernameRef}
onKeyDown={handleKeyDown}
data-flx="channel.message-username.context-menu-underline.key-down"
diff --git a/fluxer_app/src/features/channel/components/SystemMessageUsername.tsx b/fluxer_app/src/features/channel/components/SystemMessageUsername.tsx
index 1d3f4c755..a32c2f9dc 100644
--- a/fluxer_app/src/features/channel/components/SystemMessageUsername.tsx
+++ b/fluxer_app/src/features/channel/components/SystemMessageUsername.tsx
@@ -36,6 +36,8 @@ export const SystemMessageUsername = React.forwardRef<
>
<span
className={clsx(styles.systemMessageLink, contextMenuOpen && styles.contextMenuUnderline)}
+ role="button"
+ tabIndex={-1}
style={{color: member?.getColorString()}}
data-user-id={author.id}
data-guild-id={guild?.id}
diff --git a/fluxer_app/src/features/channel/components/channel_header_components/ChannelPinsButton.tsx b/fluxer_app/src/features/channel/components/channel_header_components/ChannelPinsButton.tsx
index 18b5c6d59..f19cb6573 100644
--- a/fluxer_app/src/features/channel/components/channel_header_components/ChannelPinsButton.tsx
+++ b/fluxer_app/src/features/channel/components/channel_header_components/ChannelPinsButton.tsx
@@ -78,34 +78,33 @@ export const ChannelPinsButton = observer(({channel}: ChannelPinsButtonProps) =>
);
}
return (
- <Popout
- data-flx="channel.channel-header-components.channel-pins-button.popout"
- {...openProps}
- render={({onClose}) => (
- <ChannelPinsPopout
- channel={channel}
- onClose={onClose}
- data-flx="channel.channel-header-components.channel-pins-button.channel-pins-popout"
- />
- )}
- position="bottom-end"
- subscribeTo="CHANNEL_PINS_OPEN"
+ <div
+ className={styles.iconButtonWrapper}
+ data-flx="channel.channel-header-components.channel-pins-button.icon-button-wrapper--2"
>
- <div
- className={styles.iconButtonWrapper}
- data-flx="channel.channel-header-components.channel-pins-button.icon-button-wrapper--2"
+ <Popout
+ data-flx="channel.channel-header-components.channel-pins-button.popout"
+ {...openProps}
+ render={({onClose}) => (
+ <ChannelPinsPopout
+ channel={channel}
+ onClose={onClose}
+ data-flx="channel.channel-header-components.channel-pins-button.channel-pins-popout"
+ />
+ )}
+ position="bottom-end"
+ subscribeTo="CHANNEL_PINS_OPEN"
>
<ChannelHeaderIcon
icon={PushPinIcon}
label={pinsLabel}
isSelected={isOpen}
aria-haspopup={true}
- aria-expanded={isOpen}
keybindAction="chat_toggle_pins"
data-flx="channel.channel-header-components.channel-pins-button.channel-header-icon"
/>
- {indicator}
- </div>
- </Popout>
+ </Popout>
+ {indicator}
+ </div>
);
});
diff --git a/fluxer_app/src/features/ui/components/form/ColorPickerField.module.css b/fluxer_app/src/features/ui/components/form/ColorPickerField.module.css
index 9952f4d20..bd534d9e0 100644
--- a/fluxer_app/src/features/ui/components/form/ColorPickerField.module.css
+++ b/fluxer_app/src/features/ui/components/form/ColorPickerField.module.css
@@ -67,7 +67,7 @@
}
.inputError {
- color: var(--status-danger);
+ color: color-mix(in srgb, var(--status-danger) 70%, var(--text-primary));
}
.divider {
diff --git a/fluxer_app/src/features/ui/components/form/ColorPickerField.tsx b/fluxer_app/src/features/ui/components/form/ColorPickerField.tsx
index 42f496467..1de936a8c 100644
--- a/fluxer_app/src/features/ui/components/form/ColorPickerField.tsx
+++ b/fluxer_app/src/features/ui/components/form/ColorPickerField.tsx
@@ -179,6 +179,7 @@ export const ColorPickerField: React.FC<ColorPickerFieldProps> = observer((props
if (!popoutOpen) {
const effectiveValue = getEffectiveValue();
setInputValue(numberToHex(effectiveValue));
+ setShowError(false);
}
}, [getEffectiveValue, popoutOpen]);
const commitFromText = useCallback(() => {
diff --git a/fluxer_app/src/features/ui/components/form/FormInput.module.css b/fluxer_app/src/features/ui/components/form/FormInput.module.css
index 34a6c7cda..30dffb802 100644
--- a/fluxer_app/src/features/ui/components/form/FormInput.module.css
+++ b/fluxer_app/src/features/ui/components/form/FormInput.module.css
@@ -24,11 +24,11 @@
}
.input.hasRightElement {
- padding-right: 3rem;
+ padding-inline-end: 3rem;
}
.input.hasLeftIcon {
- padding-left: 2.25rem;
+ padding-inline-start: 2.25rem;
}
.input.focusable:focus-within {
@@ -80,7 +80,7 @@
.errorText {
font-size: 0.875rem;
line-height: 1.25rem;
- color: var(--status-danger);
+ color: color-mix(in srgb, var(--status-danger) 78%, var(--text-primary) 22%);
}
.inputContainer {
@@ -97,7 +97,7 @@
.leftIcon {
position: absolute;
top: 50%;
- left: 0.75rem;
+ inset-inline-start: 0.75rem;
transform: translateY(-50%);
pointer-events: none;
color: var(--text-tertiary);
@@ -106,7 +106,7 @@
.leftElement {
position: absolute;
top: 50%;
- left: 0.25rem;
+ inset-inline-start: 0.25rem;
transform: translateY(-50%);
display: flex;
align-items: center;
@@ -115,13 +115,13 @@
}
.input.hasLeftElement {
- padding-left: 2.5rem;
+ padding-inline-start: 2.5rem;
}
.rightIcon {
position: absolute;
top: 50%;
- right: 0.75rem;
+ inset-inline-end: 0.75rem;
transform: translateY(-50%);
pointer-events: none;
color: var(--text-tertiary);
@@ -130,7 +130,7 @@
.passwordToggle {
position: absolute;
top: 50%;
- right: 0.75rem;
+ inset-inline-end: 0.75rem;
transform: translateY(-50%);
border-radius: 0.25rem;
padding: 0.375rem;
@@ -149,7 +149,7 @@
.rightElement {
position: absolute;
top: 50%;
- right: 0.5rem;
+ inset-inline-end: 0.5rem;
transform: translateY(-50%);
display: flex;
align-items: center;
@@ -175,30 +175,6 @@
border-color: var(--status-danger);
}
-.textarea {
- min-width: 0;
- max-width: 100%;
- width: 100%;
- flex: 1 1 0%;
- resize: none;
- overflow-x: hidden;
- white-space: pre-wrap;
- overflow-wrap: anywhere;
- word-break: break-word;
- appearance: none;
- border: 0;
- background-color: transparent;
- padding: 0.625rem 1rem;
- font-size: 0.875rem;
- line-height: 1.25rem;
- color: var(--text-primary);
- outline: none;
-}
-
-.textarea::placeholder {
- color: var(--text-tertiary);
-}
-
textarea.input {
min-width: 0;
max-width: 100%;
diff --git a/fluxer_app/src/features/ui/components/form/FormInput.tsx b/fluxer_app/src/features/ui/components/form/FormInput.tsx
index b8a6b3e83..8fb3d883e 100644
--- a/fluxer_app/src/features/ui/components/form/FormInput.tsx
+++ b/fluxer_app/src/features/ui/components/form/FormInput.tsx
@@ -58,7 +58,7 @@ const FieldSet = React.forwardRef<HTMLFieldSetElement, FieldSetProps>(
<div className={styles.inputGroup} data-flx="ui.form.input.field-set.input-group">
{children}
{error && (
- <span id={errorId} className={styles.errorText} data-flx="ui.form.input.field-set.error-text">
+ <span id={errorId} className={styles.errorText} role="alert" data-flx="ui.form.input.field-set.error-text">
{error}
</span>
)}
@@ -249,6 +249,8 @@ export const Input = React.forwardRef<HTMLInputElement, InputProps>(
<button
type="button"
className={styles.passwordToggle}
+ tabIndex={-1}
+ onMouseDown={(event) => event.preventDefault()}
onClick={handlePasswordToggle}
aria-label={passwordToggleLabel}
data-flx="ui.form.input.input-content.password-toggle.button"
@@ -304,7 +306,7 @@ export const Input = React.forwardRef<HTMLInputElement, InputProps>(
<div className={styles.inputContainer} data-flx="ui.form.input.input-container">
{focusDecoratedInput}
{error && (
- <span id={errorId} className={styles.errorText} data-flx="ui.form.input.error-text">
+ <span id={errorId} className={styles.errorText} role="alert" data-flx="ui.form.input.error-text">
{error}
</span>
)}
@@ -351,8 +353,6 @@ type TextareaProps = React.TextareaHTMLAttributes<HTMLTextAreaElement> & {
maxRows?: number;
showCharacterCount?: boolean;
actionButton?: React.ReactNode;
- innerActionButton?: React.ReactNode;
- characterCountTooltip?: (remaining: number, total: number, current: number) => React.ReactNode;
};
export const Textarea = React.forwardRef<HTMLTextAreaElement, TextareaProps>(
@@ -367,8 +367,6 @@ export const Textarea = React.forwardRef<HTMLTextAreaElement, TextareaProps>(
maxLength,
value,
actionButton,
- innerActionButton,
- characterCountTooltip,
disabled,
id,
...props
@@ -381,7 +379,6 @@ export const Textarea = React.forwardRef<HTMLTextAreaElement, TextareaProps>(
const currentValue = useMemo(() => value || '', [value]);
const currentLength = useMemo(() => String(currentValue).length, [currentValue]);
const textareaRef = useRef<HTMLTextAreaElement | null>(null);
- const textareaWrapperRef = useRef<HTMLDivElement | null>(null);
const generatedTextareaId = useId();
const textareaId = id ?? generatedTextareaId;
const errorId = error ? `${textareaId}-error` : undefined;
@@ -528,35 +525,6 @@ export const Textarea = React.forwardRef<HTMLTextAreaElement, TextareaProps>(
className={clsx(error ? styles.error : styles.focusable)}
ref={setTextareaRefs}
/>
- ) : null,
- [innerActionButton, textareaProps, error, setTextareaRefs],
- );
- const ringTarget = useMemo(
- () => (innerActionButton ? textareaWrapperRef : textareaRef),
- [innerActionButton, textareaWrapperRef, textareaRef],
- );
- const control = useMemo(
- () => (innerActionButton ? textareaWithActions : simpleTextarea)!,
- [innerActionButton, textareaWithActions, simpleTextarea],
- );
- return (
- <FieldSet
- error={error}
- errorId={errorId}
- footer={footer}
- label={label}
- labelRight={labelRight}
- htmlFor={textareaId}
- data-flx="ui.form.input.textarea.field-set"
- >
- <FocusRing
- focusTarget={textareaRef}
- ringTarget={ringTarget}
- offset={-2}
- enabled={!disabled}
- data-flx="ui.form.input.textarea.focus-ring"
- >
- {control}
</FocusRing>
</FieldSet>
);
diff --git a/fluxer_app/src/features/ui/components/form/FormSwitch.module.css b/fluxer_app/src/features/ui/components/form/FormSwitch.module.css
index e8668e6b0..97713f499 100644
--- a/fluxer_app/src/features/ui/components/form/FormSwitch.module.css
+++ b/fluxer_app/src/features/ui/components/form/FormSwitch.module.css
@@ -22,7 +22,7 @@
flex-direction: column;
align-items: flex-start;
gap: 0.25rem;
- text-align: left;
+ text-align: start;
}
.label {
@@ -46,7 +46,7 @@
}
.description {
- padding-right: 1rem;
+ padding-inline-end: 1rem;
font-size: 0.875rem;
line-height: 1.25rem;
color: var(--text-primary-muted);
@@ -54,8 +54,6 @@
.switchRoot {
--switch-highlight: rgba(255, 255, 255, 0.1);
- --switch-edge: rgba(0, 0, 0, 0.25);
- --switch-shadow: rgba(0, 0, 0, 0.2);
display: inline-flex;
align-items: center;
position: relative;
@@ -105,7 +103,7 @@
transition-duration: 150ms;
transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
will-change: transform;
- transform: translateX(0.125rem);
+ transform: translateX(calc(0.125rem * var(--switch-travel-sign, 1)));
}
.switchRoot:active .switchThumb {
@@ -117,7 +115,11 @@
.switchThumb[data-state='checked'] {
background-color: var(--brand-primary-fill);
- transform: translateX(1.375rem);
+ transform: translateX(calc(1.375rem * var(--switch-travel-sign, 1)));
+}
+
+:global(html[dir='rtl']) .switchRoot {
+ --switch-travel-sign: -1;
}
.iconChecked {
diff --git a/fluxer_app/src/features/ui/components/form/FormSwitch.tsx b/fluxer_app/src/features/ui/components/form/FormSwitch.tsx
index 9bf119d47..6dedac303 100644
--- a/fluxer_app/src/features/ui/components/form/FormSwitch.tsx
+++ b/fluxer_app/src/features/ui/components/form/FormSwitch.tsx
@@ -67,13 +67,14 @@ export const Switch = observer(
<span
id={labelId}
className={clsx(styles.label, disabled && styles.disabled)}
+ dir="auto"
data-flx="ui.form.switch.label"
>
{label}
</span>
)}
{hasDescription && (
- <span id={descriptionId} className={styles.description} data-flx="ui.form.switch.description">
+ <span id={descriptionId} className={styles.description} dir="auto" data-flx="ui.form.switch.description">
{description}
</span>
)}
diff --git a/fluxer_app/src/features/ui/radio_group/RadioGroup.tsx b/fluxer_app/src/features/ui/radio_group/RadioGroup.tsx
index 358f14973..840e17618 100644
--- a/fluxer_app/src/features/ui/radio_group/RadioGroup.tsx
+++ b/fluxer_app/src/features/ui/radio_group/RadioGroup.tsx
@@ -2,11 +2,12 @@
import FocusRing from '@app/features/ui/focus_ring/FocusRing';
import styles from '@app/features/ui/radio_group/RadioGroup.module.css';
+import {useDirection} from '@base-ui/react/direction-provider';
import * as RadixRadioGroup from '@radix-ui/react-radio-group';
import {clsx} from 'clsx';
import {observer} from 'mobx-react-lite';
import type React from 'react';
-import {useRef} from 'react';
+import {useId, useRef} from 'react';
export interface RadioOption<T> {
value: T;
@@ -23,7 +24,6 @@ interface RadioGroupProps<T> {
onChange: (value: T) => void;
renderContent?: (option: RadioOption<T>, checked: boolean) => React.ReactNode;
optionAlign?: 'start' | 'center';
- dir?: 'ltr' | 'rtl';
'aria-label'?: string;
}
@@ -45,6 +45,9 @@ const RadioOptionItem = <T,>({
align,
}: RadioOptionItemProps<T>) => {
const radioRef = useRef<HTMLButtonElement | null>(null);
+ const labelId = useId();
+ const descriptionId = useId();
+ const describedByDescription = !renderContent && Boolean(option.desc);
return (
<FocusRing
focusTarget={radioRef}
@@ -58,6 +61,8 @@ const RadioOptionItem = <T,>({
ref={radioRef}
value={value}
disabled={option.disabled || groupDisabled}
+ aria-labelledby={describedByDescription ? labelId : undefined}
+ aria-describedby={describedByDescription ? descriptionId : undefined}
className={clsx(styles.radioGroupOption, align === 'center' && styles.radioGroupOptionCenter)}
data-flx="ui.radio-group.radio-group.radio-option-item.radio-group-option"
>
@@ -103,13 +108,17 @@ const RadioOptionItem = <T,>({
</div>
) : (
<>
- <span className={styles.label} data-flx="ui.radio-group.radio-group.radio-option-item.label">
+ <span id={labelId} className={styles.label} data-flx="ui.radio-group.radio-group.radio-option-item.label">
<div className={styles.labelText} data-flx="ui.radio-group.radio-group.radio-option-item.label-text">
{option.name}
</div>
</span>
{option.desc && (
- <div className={styles.description} data-flx="ui.radio-group.radio-group.radio-option-item.description">
+ <div
+ id={descriptionId}
+ className={styles.description}
+ data-flx="ui.radio-group.radio-group.radio-option-item.description"
+ >
{option.desc}
</div>
)}
@@ -129,9 +138,9 @@ export const RadioGroup = observer(
onChange,
renderContent,
optionAlign = 'start',
- dir,
'aria-label': ariaLabel,
}: RadioGroupProps<T>) => {
+ const direction = useDirection();
const valueToString = (val: T): string => {
if (typeof val === 'string') return val;
if (typeof val === 'number') return String(val);
@@ -155,7 +164,7 @@ export const RadioGroup = observer(
onValueChange={handleChange}
disabled={disabled}
orientation="vertical"
- dir={dir}
+ dir={direction}
aria-label={ariaLabel}
data-flx="ui.radio-group.radio-group.group"
>
diff --git a/fluxer_app/src/features/ui/segmented_tabs/SegmentedTabs.tsx b/fluxer_app/src/features/ui/segmented_tabs/SegmentedTabs.tsx
index a68c64b85..d5844e3f9 100644
--- a/fluxer_app/src/features/ui/segmented_tabs/SegmentedTabs.tsx
+++ b/fluxer_app/src/features/ui/segmented_tabs/SegmentedTabs.tsx
@@ -19,6 +19,7 @@ interface SegmentedTabsProps<T extends string = string> {
onTabChange: (tab: T) => void;
ariaLabel?: string;
className?: string;
+ semantics?: 'tabs' | 'radio';
}
export function SegmentedTabs<T extends string = string>({
@@ -27,7 +28,9 @@ export function SegmentedTabs<T extends string = string>({
onTabChange,
ariaLabel,
className,
+ semantics = 'tabs',
}: SegmentedTabsProps<T>) {
+ const radio = semantics === 'radio';
const tabRefs = useRef(new Map<T, HTMLButtonElement>());
const selectedIndex = tabs.findIndex((tab) => tab.id === selectedTab);
const focusTab = (tabId: T) => {
@@ -51,9 +54,9 @@ export function SegmentedTabs<T extends string = string>({
<div className={clsx(styles.container, className)} data-flx="ui.segmented-tabs.segmented-tabs.container">
<div
className={styles.tabList}
- role="tablist"
- aria-label={ariaLabel}
- aria-orientation="horizontal"
+ {...(radio
+ ? {role: 'radiogroup', 'aria-label': ariaLabel}
+ : {role: 'tablist', 'aria-label': ariaLabel, 'aria-orientation': 'horizontal' as const})}
data-flx="ui.segmented-tabs.segmented-tabs.tab-list"
>
{tabs.map((tab) => {
@@ -69,8 +72,7 @@ export function SegmentedTabs<T extends string = string>({
}
}}
type="button"
- role="tab"
- aria-selected={isSelected}
+ {...(radio ? {role: 'radio', 'aria-checked': isSelected} : {role: 'tab', 'aria-selected': isSelected})}
tabIndex={isSelected ? 0 : -1}
onClick={() => onTabChange(tab.id)}
onKeyDown={(event) => handleKeyDown(event, tab.id)}
@@ -95,7 +97,7 @@ export function SegmentedTabs<T extends string = string>({
}
style={{
width: `calc((100% - 6px) / ${tabs.length})`,
- left: `calc(3px + (100% - 6px) * ${selectedIndex} / ${tabs.length})`,
+ insetInlineStart: `calc(3px + (100% - 6px) * ${selectedIndex} / ${tabs.length})`,
}}
data-flx="ui.segmented-tabs.segmented-tabs.tab-background"
/>