mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 08:50:15 +01:00
fix: sort by header withi keyboard nav now retains focus on press
This commit is contained in:
parent
a5d17e08ce
commit
49284dd993
1 changed files with 30 additions and 32 deletions
|
|
@ -63,14 +63,6 @@ export default function SharedLinks() {
|
||||||
refetchOnMount: false,
|
refetchOnMount: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
const handleSort = useCallback((sortField: string, sortOrder: 'asc' | 'desc') => {
|
|
||||||
setQueryParams((prev) => ({
|
|
||||||
...prev,
|
|
||||||
sortBy: sortField as 'title' | 'createdAt',
|
|
||||||
sortDirection: sortOrder,
|
|
||||||
}));
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const handleFilterChange = useCallback((value: string) => {
|
const handleFilterChange = useCallback((value: string) => {
|
||||||
const encodedValue = encodeURIComponent(value.trim());
|
const encodedValue = encodeURIComponent(value.trim());
|
||||||
setQueryParams((prev) => ({
|
setQueryParams((prev) => ({
|
||||||
|
|
@ -169,26 +161,28 @@ export default function SharedLinks() {
|
||||||
() => [
|
() => [
|
||||||
{
|
{
|
||||||
accessorKey: 'title',
|
accessorKey: 'title',
|
||||||
header: () => {
|
header: ({ column }) => {
|
||||||
const isSorted = queryParams.sortBy === 'title';
|
const sortState = column.getIsSorted();
|
||||||
const sortDirection = queryParams.sortDirection;
|
let SortIcon = ArrowUpDown;
|
||||||
|
let ariaSort: 'ascending' | 'descending' | 'none' = 'none';
|
||||||
|
if (sortState === 'desc') {
|
||||||
|
SortIcon = ArrowDown;
|
||||||
|
ariaSort = 'descending';
|
||||||
|
} else if (sortState === 'asc') {
|
||||||
|
SortIcon = ArrowUp;
|
||||||
|
ariaSort = 'ascending';
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<Button
|
<Button
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
|
onClick={() => column.toggleSorting(column.getIsSorted() === 'asc')}
|
||||||
className="px-2 py-0 text-xs hover:bg-surface-hover sm:px-2 sm:py-2 sm:text-sm"
|
className="px-2 py-0 text-xs hover:bg-surface-hover sm:px-2 sm:py-2 sm:text-sm"
|
||||||
onClick={() =>
|
aria-sort={ariaSort}
|
||||||
handleSort('title', isSorted && sortDirection === 'asc' ? 'desc' : 'asc')
|
|
||||||
}
|
|
||||||
aria-label={localize('com_ui_name_sort')}
|
aria-label={localize('com_ui_name_sort')}
|
||||||
|
aria-current={sortState ? 'true' : 'false'}
|
||||||
>
|
>
|
||||||
{localize('com_ui_name')}
|
{localize('com_ui_name')}
|
||||||
{isSorted && sortDirection === 'asc' && (
|
<SortIcon className="ml-2 h-3 w-4 sm:h-4 sm:w-4" />
|
||||||
<ArrowUp className="ml-2 h-3 w-4 sm:h-4 sm:w-4" />
|
|
||||||
)}
|
|
||||||
{isSorted && sortDirection === 'desc' && (
|
|
||||||
<ArrowDown className="ml-2 h-3 w-4 sm:h-4 sm:w-4" />
|
|
||||||
)}
|
|
||||||
{!isSorted && <ArrowUpDown className="ml-2 h-3 w-4 sm:h-4 sm:w-4" />}
|
|
||||||
</Button>
|
</Button>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
@ -219,24 +213,28 @@ export default function SharedLinks() {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
accessorKey: 'createdAt',
|
accessorKey: 'createdAt',
|
||||||
header: () => {
|
header: ({ column }) => {
|
||||||
const isSorted = queryParams.sortBy === 'createdAt';
|
const sortState = column.getIsSorted();
|
||||||
const sortDirection = queryParams.sortDirection;
|
let SortIcon = ArrowUpDown;
|
||||||
|
let ariaSort: 'ascending' | 'descending' | 'none' = 'none';
|
||||||
|
if (sortState === 'desc') {
|
||||||
|
SortIcon = ArrowDown;
|
||||||
|
ariaSort = 'descending';
|
||||||
|
} else if (sortState === 'asc') {
|
||||||
|
SortIcon = ArrowUp;
|
||||||
|
ariaSort = 'ascending';
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<Button
|
<Button
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
|
onClick={() => column.toggleSorting(column.getIsSorted() === 'asc')}
|
||||||
className="px-2 py-0 text-xs hover:bg-surface-hover sm:px-2 sm:py-2 sm:text-sm"
|
className="px-2 py-0 text-xs hover:bg-surface-hover sm:px-2 sm:py-2 sm:text-sm"
|
||||||
|
aria-sort={ariaSort}
|
||||||
aria-label={localize('com_ui_creation_date_sort' as TranslationKeys)}
|
aria-label={localize('com_ui_creation_date_sort' as TranslationKeys)}
|
||||||
aria-current={sortState ? 'true' : 'false'}
|
aria-current={sortState ? 'true' : 'false'}
|
||||||
>
|
>
|
||||||
{localize('com_ui_date')}
|
{localize('com_ui_date')}
|
||||||
{isSorted && sortDirection === 'asc' && (
|
<SortIcon className="ml-2 h-3 w-4 sm:h-4 sm:w-4" />
|
||||||
<ArrowUp className="ml-2 h-3 w-4 sm:h-4 sm:w-4" />
|
|
||||||
)}
|
|
||||||
{isSorted && sortDirection === 'desc' && (
|
|
||||||
<ArrowDown className="ml-2 h-3 w-4 sm:h-4 sm:w-4" />
|
|
||||||
)}
|
|
||||||
{!isSorted && <ArrowUpDown className="ml-2 h-3 w-4 sm:h-4 sm:w-4" />}
|
|
||||||
</Button>
|
</Button>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
@ -299,7 +297,7 @@ export default function SharedLinks() {
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
[isSmallScreen, localize, queryParams, handleSort],
|
[isSmallScreen, localize],
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue