mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 00:40:14 +01:00
TooltipAnchor was automatically adding an `aria-describedby` tag which often duplicated the labeling already present inside of the anchor. E.g., the screen reader might say "New Chat, New Chat, button" instead of just "New Chat, button." I've removed the TooltipAnchor's automatic `aria-describedby` and worked to make sure that anyone using TooltipAnchor properly defines its labeling.
84 lines
2.3 KiB
TypeScript
84 lines
2.3 KiB
TypeScript
import React, { useState } from 'react';
|
|
import { MenuButton } from '@ariakit/react';
|
|
import { History, Check } from 'lucide-react';
|
|
import { DropdownPopup, TooltipAnchor, Button, useMediaQuery } from '@librechat/client';
|
|
import { useLocalize } from '~/hooks';
|
|
|
|
interface ArtifactVersionProps {
|
|
currentIndex: number;
|
|
totalVersions: number;
|
|
onVersionChange: (index: number) => void;
|
|
}
|
|
|
|
export default function ArtifactVersion({
|
|
currentIndex,
|
|
totalVersions,
|
|
onVersionChange,
|
|
}: ArtifactVersionProps) {
|
|
const localize = useLocalize();
|
|
const [isPopoverActive, setIsPopoverActive] = useState(false);
|
|
const isSmallScreen = useMediaQuery('(max-width: 768px)');
|
|
const menuId = 'version-dropdown-menu';
|
|
|
|
const handleValueChange = (value: string) => {
|
|
const index = parseInt(value, 10);
|
|
onVersionChange(index);
|
|
setIsPopoverActive(false);
|
|
};
|
|
|
|
if (totalVersions <= 1) {
|
|
return null;
|
|
}
|
|
|
|
const options = Array.from({ length: totalVersions }, (_, index) => ({
|
|
value: index.toString(),
|
|
label: localize('com_ui_version_var', { 0: String(index + 1) }),
|
|
}));
|
|
|
|
const dropdownItems = options.map((option) => {
|
|
const isSelected = option.value === String(currentIndex);
|
|
return {
|
|
label: option.label,
|
|
onClick: () => handleValueChange(option.value),
|
|
value: option.value,
|
|
icon: isSelected ? (
|
|
<Check size={16} className="text-text-primary" aria-hidden="true" />
|
|
) : undefined,
|
|
};
|
|
});
|
|
|
|
return (
|
|
<DropdownPopup
|
|
menuId={menuId}
|
|
portal
|
|
focusLoop
|
|
unmountOnHide
|
|
isOpen={isPopoverActive}
|
|
setIsOpen={setIsPopoverActive}
|
|
trigger={
|
|
<TooltipAnchor
|
|
description={localize('com_ui_change_version')}
|
|
render={
|
|
<Button
|
|
size="icon"
|
|
variant="ghost"
|
|
asChild
|
|
aria-label={localize('com_ui_change_version')}
|
|
>
|
|
<MenuButton>
|
|
<History
|
|
size={18}
|
|
className="text-text-secondary"
|
|
aria-hidden="true"
|
|
focusable="false"
|
|
/>
|
|
</MenuButton>
|
|
</Button>
|
|
}
|
|
/>
|
|
}
|
|
items={dropdownItems}
|
|
className={isSmallScreen ? '' : 'absolute right-0 top-0 mt-2'}
|
|
/>
|
|
);
|
|
}
|