Skip to content

Commit

Permalink
codestyle
Browse files Browse the repository at this point in the history
  • Loading branch information
pan-kot committed Sep 17, 2023
1 parent 7048d40 commit 5a8211c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/table/__tests__/resizable-columns.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ describe('resize with keyboard', () => {
});

test('resizes columns with keyboard', async () => {
mockWidth = 150;
const onChange = jest.fn();
const { wrapper } = renderTable(<Table {...defaultProps} onColumnWidthsChange={event => onChange(event.detail)} />);
const columnResizerWrapper = wrapper.findColumnResizer(1)!;
Expand Down
2 changes: 1 addition & 1 deletion src/table/header-cell/th-element.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ interface TableThElementProps {
resizableColumns?: boolean;
columnId: PropertyKey;
stickyState: StickyColumnsModel;
cellRef?: React.Ref<HTMLElement>;
cellRef?: React.RefCallback<HTMLElement>;
tableRole: TableRole;
children: React.ReactNode;
}
Expand Down
12 changes: 7 additions & 5 deletions src/table/resizer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export function Resizer({
useEffect(() => setHeaderCellWidth(resizerDom.current.header.getBoundingClientRect().width), []);

const handlers = useMemo(() => {
const { left: leftEdge, right: rightEdge } = resizerDom.current.scrollParent.getBoundingClientRect();

const updateTrackerPosition = (newOffset: number) => {
const { left: scrollParentLeft } = resizerDom.current.table.getBoundingClientRect();
resizerDom.current.tracker.style.top = resizerDom.current.header.getBoundingClientRect().height + 'px';

Check warning on line 51 in src/table/resizer/index.tsx

View check run for this annotation

Codecov / codecov/patch

src/table/resizer/index.tsx#L50-L51

Added lines #L50 - L51 were not covered by tests
Expand All @@ -52,8 +54,7 @@ export function Resizer({
};

const updateColumnWidth = (newWidth: number) => {
const right = resizerDom.current.header.getBoundingClientRect().right;
const width = resizerDom.current.header.getBoundingClientRect().width;
const { right, width } = resizerDom.current.header.getBoundingClientRect();

Check warning on line 57 in src/table/resizer/index.tsx

View check run for this annotation

Codecov / codecov/patch

src/table/resizer/index.tsx#L57

Added line #L57 was not covered by tests
const updatedWidth = newWidth < minWidth ? minWidth : newWidth;
updateTrackerPosition(right + updatedWidth - width);
if (newWidth >= minWidth) {
Expand All @@ -64,24 +65,25 @@ export function Resizer({
};

const resizeColumn = (offset: number) => {
if (offset > resizerDom.current.scrollParent.getBoundingClientRect().left) {
if (offset > leftEdge) {
const newWidth = offset - resizerDom.current.header.getBoundingClientRect().left;

Check warning on line 69 in src/table/resizer/index.tsx

View check run for this annotation

Codecov / codecov/patch

src/table/resizer/index.tsx#L69

Added line #L69 was not covered by tests
// callbacks must be the last calls in the handler, because they may cause an extra update
updateColumnWidth(newWidth);
}
};

const onAutoGrow = () => {
const { width } = resizerDom.current.header.getBoundingClientRect();

Check warning on line 76 in src/table/resizer/index.tsx

View check run for this annotation

Codecov / codecov/patch

src/table/resizer/index.tsx#L76

Added line #L76 was not covered by tests
autoGrowTimeout.current = setTimeout(onAutoGrow, AUTO_GROW_INTERVAL);
// callbacks must be the last calls in the handler, because they may cause an extra update
updateColumnWidth(resizerDom.current.header.getBoundingClientRect().width + AUTO_GROW_INCREMENT);
updateColumnWidth(width + AUTO_GROW_INCREMENT);
resizerDom.current.scrollParent.scrollLeft += AUTO_GROW_INCREMENT;

Check warning on line 80 in src/table/resizer/index.tsx

View check run for this annotation

Codecov / codecov/patch

src/table/resizer/index.tsx#L80

Added line #L80 was not covered by tests
};

const onMouseMove = (event: MouseEvent) => {
clearTimeout(autoGrowTimeout.current);
const offset = event.pageX;
if (offset > resizerDom.current.scrollParent.getBoundingClientRect().right) {
if (offset > rightEdge) {
autoGrowTimeout.current = setTimeout(onAutoGrow, AUTO_GROW_START_TIME);
} else {
resizeColumn(offset);
Expand Down

0 comments on commit 5a8211c

Please sign in to comment.