LibreChat/client/src/components/Nav/SettingsTabs/DangerButton.tsx
Daniel Lew 1143f73f59
Some checks failed
Docker Dev Branch Images Build / build (Dockerfile, lc-dev, node) (push) Has been cancelled
Docker Dev Branch Images Build / build (Dockerfile.multi, lc-dev-api, api-build) (push) Has been cancelled
🔇 fix: Hide Button Icons from Screen Readers (#10776)
If you've got a screen reader that is reading out the whole page,
each icon button (i.e., `<button><SVG></button>`) will have both
the button's aria-label read out as well as the title from the
SVG (which is usually just "image").

Since we are pretty good about setting aria-labels, we should instead
use `aria-hidden="true"` on these images, since they are not useful
to be read out.

I don't consider this a comprehensive review of all icons in the app,
but I knocked out all the low hanging fruit in this commit.
2025-12-11 16:35:17 -05:00

75 lines
2.2 KiB
TypeScript

import { forwardRef } from 'react';
import { CheckIcon } from 'lucide-react';
import { Spinner, DialogButton, InfoHoverCard, ESide } from '@librechat/client';
import type { TDangerButtonProps } from '~/common';
import type { ForwardedRef } from 'react';
import { useLocalize } from '~/hooks';
import { cn } from '~/utils';
const DangerButton = (props: TDangerButtonProps, ref: ForwardedRef<HTMLButtonElement>) => {
const {
id,
onClick,
mutation,
disabled,
confirmClear,
infoTextCode,
actionTextCode,
className = '',
showText = true,
dataTestIdInitial,
dataTestIdConfirm,
infoDescriptionCode,
confirmActionTextCode = 'com_ui_confirm_action',
} = props;
const localize = useLocalize();
const renderMutation = (node: React.ReactNode | string) => {
if (mutation && mutation.isLoading) {
return <Spinner className="h-5 w-5" />;
}
return node;
};
return (
<div className="flex items-center justify-between">
{showText && (
<div className={`flex items-center ${infoDescriptionCode ? 'space-x-2' : ''}`}>
<div>{localize(infoTextCode)}</div>
{infoDescriptionCode && <InfoHoverCard side={ESide.Bottom} text={infoDescriptionCode} />}
</div>
)}
<DialogButton
id={id}
ref={ref}
disabled={disabled}
onClick={onClick}
className={cn(
'btn relative border-none bg-red-500 text-white hover:bg-red-700 dark:hover:bg-red-700',
className,
)}
>
{confirmClear ? (
<div
className="flex w-full items-center justify-center gap-2"
id={`${id}-text`}
data-testid={dataTestIdConfirm}
>
{renderMutation(<CheckIcon className="h-5 w-5" aria-hidden="true" />)}
{mutation && mutation.isLoading ? null : localize(confirmActionTextCode)}
</div>
) : (
<div
className="flex w-full items-center justify-center gap-2"
id={`${id}-text`}
data-testid={dataTestIdInitial}
>
{renderMutation(localize(actionTextCode))}
</div>
)}
</DialogButton>
</div>
);
};
export default forwardRef(DangerButton);