Files
3x-ui/frontend/src/pages/inbounds/form/protocols/shadowsocks.tsx
T
Alireza Ahmadi e2184777a0 fix(frontend): make the panel usable with screen readers (#6907)
* fix(frontend): make the panel usable with screen readers

* fix(frontend): keep mobile tab names and the inbound expiry hint

Review of #6907 found two gaps in the screen-reader pass:

- On phone-width screens catTabLabel renders only the icon and names the
  tab by putting aria-label on it, but callers now pass that icon with
  aria-hidden for the desktop label, so every Settings, Xray and Host
  category tab lost its name under TalkBack. catTabLabel now clears
  aria-hidden on the icon it uses as the name.
- DateTimePicker forwarded id and aria-label but not aria-describedby,
  so the inbound expiry hint ("leave blank to never expire") was never
  attached. It now forwards it on both the Gregorian and Jalali input.
2026-10-23 18:29:47 +02:00

66 lines
2.2 KiB
TypeScript

import { useId } from 'react';
import { useTranslation } from 'react-i18next';
import { Button, Form, Input, Select, Space, Switch } from 'antd';
import { ReloadOutlined } from '@ant-design/icons';
import { useFormContext } from 'react-hook-form';
import { RandomUtil } from '@/utils';
import { FormField } from '@/components/form/rhf';
import { SSInboundMethodSchema } from '@/schemas/protocols/shared/shadowsocks';
interface ShadowsocksFieldsProps {
isSSWith2022: boolean;
}
export default function ShadowsocksFields({ isSSWith2022 }: ShadowsocksFieldsProps) {
const { t } = useTranslation();
const uid = useId();
const { getValues, setValue } = useFormContext();
return (
<>
<FormField
name={['settings', 'method']}
label={t('pages.inbounds.form.encryptionMethod')}
onAfterChange={(v) => {
setValue('settings.password', RandomUtil.randomShadowsocksPassword(v as string));
}}
>
<Select options={SSInboundMethodSchema.options.map((m) => ({ value: m, label: m }))} />
</FormField>
{isSSWith2022 && (
<Form.Item htmlFor={`${uid}-password`} label={t('password')}>
<Space.Compact block>
<FormField name={['settings', 'password']} noStyle>
<Input id={`${uid}-password`} style={{ width: 'calc(100% - 32px)' }} />
</FormField>
<Button
aria-label={t('regenerate')}
icon={<ReloadOutlined aria-hidden />}
onClick={() => {
const method = getValues('settings.method');
setValue(
'settings.password',
RandomUtil.randomShadowsocksPassword(method as string),
);
}}
/>
</Space.Compact>
</Form.Item>
)}
<FormField name={['settings', 'network']} label={t('pages.inbounds.network')}>
<Select
style={{ width: 120 }}
options={[
{ value: 'tcp,udp', label: 'TCP, UDP' },
{ value: 'tcp', label: 'TCP' },
{ value: 'udp', label: 'UDP' },
]}
/>
</FormField>
<FormField name={['settings', 'ivCheck']} label="ivCheck" valueProp="checked">
<Switch />
</FormField>
</>
);
}