-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
151 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
packages/common-ui/lib/bulk-data-editor/useHeaderWidthFix.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { GridSettings } from "handsontable"; | ||
import { useEffect, useRef } from "react"; | ||
|
||
interface HeaderWidthFixParams { | ||
columns: GridSettings[]; | ||
} | ||
|
||
/** Fixes a bug with HandsOnTable where enabling the rowHeaders | ||
* (numbered cells on the left side of the grid) cuts off the right side of the | ||
* column headers. | ||
*/ | ||
export function useHeaderWidthFix({ columns }: HeaderWidthFixParams) { | ||
const tableWrapperRef = useRef<HTMLDivElement>(null); | ||
|
||
// Whenever the columns change, run some code to manually set the width of the header row: | ||
useEffect(() => { | ||
setImmediate(() => { | ||
const wrapper = tableWrapperRef.current; | ||
|
||
if (wrapper) { | ||
const header = wrapper.querySelector<HTMLDivElement>( | ||
".ht_clone_top .wtHider" | ||
); | ||
const htCore = wrapper.querySelector<HTMLDivElement>( | ||
".ht_master .htCore" | ||
); | ||
|
||
if (header && htCore) { | ||
const requiredHeaderWidth = `${htCore.clientWidth}px`; | ||
header.style.width = requiredHeaderWidth; | ||
} | ||
} | ||
}); | ||
}, [columns.map(col => col.data).join()]); | ||
|
||
return { tableWrapperRef }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.