Created
June 20, 2021 17:27
-
-
Save lfuelling/da5f069ac6e86d3641623e0dd8a6553b to your computer and use it in GitHub Desktop.
If you use react-beautiful-dnd and are struggling with Atlassians prehistoric example code (wtf does @flow even mean, who still writes class components??) you might find this example component helpful. If you use this in a draggable row instead of td tags, this will make the table keep its dimensions when dragging.
This file contains hidden or 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
import React, {FunctionComponent} from "react"; | |
type TableCellProps = { | |
children: unknown | |
} | |
const DimensionLockingTableCell: FunctionComponent<TableCellProps> = ({children}) => { | |
const ref = React.useRef<HTMLTableDataCellElement>(null); | |
if (ref.current) { | |
return ( | |
<td ref={ref} style={{ | |
width: ref.current.getBoundingClientRect().width, | |
height: ref.current.getBoundingClientRect().height, | |
}}>{children}</td> | |
); | |
} else { | |
return (<td ref={ref}>{children}</td>); | |
} | |
} | |
export default DimensionLockingTableCell; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment