Skip to content

Commit ac4c821

Browse files
authored
fix: fix table drag and style bugs (#26)
1 parent 910de99 commit ac4c821

File tree

1 file changed

+8
-6
lines changed
  • packages/components/src/__builtins__

1 file changed

+8
-6
lines changed

packages/components/src/__builtins__/sort.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ export function SortableContainer<T extends React.HTMLAttributes<HTMLElement>>(
3030
}) => {
3131
const _onSortEnd = (event: DragEndEvent) => {
3232
const { active, over } = event
33-
const oldIndex = (active.id as number) - 1
34-
const newIndex = (over?.id as number) - 1
33+
if (!over) return
34+
const oldIndex = +active.id - 1
35+
const newIndex = +over.id - 1
3536
onSortEnd?.({
3637
oldIndex,
3738
newIndex,
@@ -91,13 +92,14 @@ export function SortableElement<T extends React.HTMLAttributes<HTMLElement>>(
9192
}
9293

9394
const style = useMemo(() => {
95+
const zIndex = transform ? 1 : 'none'
9496
const itemStyle: React.CSSProperties = {
9597
position: 'relative',
9698
touchAction: 'none',
97-
zIndex: 1,
98-
transform: `translate3d(${transform?.x || 0}px, ${
99-
transform?.y || 0
100-
}px, 0)`,
99+
zIndex,
100+
transform: transform
101+
? `translate3d(${transform.x}px, ${transform.y}px, 0)`
102+
: 'none',
101103
transition: `${transform ? 'all 200ms ease' : ''}`,
102104
}
103105
const dragStyle = {

0 commit comments

Comments
 (0)