Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(BaseHeaderCell): sorting on resize fixed #55

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 19 additions & 14 deletions src/components/BaseHeaderCell/BaseHeaderCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
} from '../../utils';
import type {BaseResizeHandleProps} from '../BaseResizeHandle';
import {BaseResizeHandle} from '../BaseResizeHandle';
import {BaseSort} from '../BaseSort';
import type {BaseSortIndicatorProps} from '../BaseSortIndicator';
import {BaseSortIndicator} from '../BaseSortIndicator';
import {b} from '../BaseTable/BaseTable.classname';
Expand Down Expand Up @@ -58,25 +59,29 @@ export const BaseHeaderCell = <TData, TValue>({
className={b('header-cell', getHeaderCellClassModes(header), className)}
colSpan={header.colSpan > 1 ? header.colSpan : undefined}
rowSpan={rowSpan > 1 ? rowSpan : undefined}
onClick={header.column.getToggleSortingHandler()}
aria-sort={getAriaSort(header.column.getIsSorted())}
aria-colindex={getHeaderCellAriaColIndex(header)}
{...attributes}
style={getCellStyles(header, attributes?.style)}
>
{flexRender(header.column.columnDef.header, header.getContext())}{' '}
{header.column.getCanSort() &&
(renderSortIndicator ? (
renderSortIndicator({
className: b('sort-indicator', sortIndicatorClassName),
header,
})
) : (
<BaseSortIndicator
className={b('sort-indicator', sortIndicatorClassName)}
header={header}
/>
))}
{header.column.getCanSort() ? (
<BaseSort header={header}>
{flexRender(header.column.columnDef.header, header.getContext())}{' '}
{renderSortIndicator ? (
renderSortIndicator({
className: b('sort-indicator', sortIndicatorClassName),
header,
})
) : (
<BaseSortIndicator
className={b('sort-indicator', sortIndicatorClassName)}
header={header}
/>
)}
</BaseSort>
) : (
flexRender(header.column.columnDef.header, header.getContext())
)}
{header.column.getCanResize() &&
(renderResizeHandle ? (
renderResizeHandle({
Expand Down
35 changes: 35 additions & 0 deletions src/components/BaseSort/BaseSort.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React from 'react';

import {useActionHandlers} from '@gravity-ui/uikit';
import type {Header} from '@tanstack/react-table';

import {b} from '../BaseTable/BaseTable.classname';

export interface BaseSortProps<TData, TValue>
extends Omit<React.HTMLAttributes<HTMLSpanElement>, 'className' | 'onClick'> {
className?: string;
header: Header<TData, TValue>;
}

export const BaseSort = <TData, TValue>({
header,
className,
children,
...restProps
}: BaseSortProps<TData, TValue>) => {
const handleKeyDown = header.column.getToggleSortingHandler();
const {onKeyDown} = useActionHandlers(handleKeyDown);

return (
<span
className={b('sort', className)}
role="button"
tabIndex={0}
onClick={handleKeyDown}
onKeyDown={onKeyDown}
{...restProps}
>
{children}
</span>
);
};
1 change: 1 addition & 0 deletions src/components/BaseSort/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './BaseSort';
12 changes: 5 additions & 7 deletions src/components/BaseTable/BaseTable.scss
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,6 @@ $block: '.#{variables.$ns}table';
font-weight: 500;
}

&__header-cell {
&_sortable {
cursor: pointer;
user-select: none;
}
}

&__cell,
&__header-cell,
&__footer-cell {
Expand All @@ -63,6 +56,11 @@ $block: '.#{variables.$ns}table';
}
}

&__sort {
cursor: pointer;
user-select: none;
}

&_with-row-virtualization {
display: grid;

Expand Down
Loading