11import type { NSlideTransitionProps } from 'src/components'
2- import { ref } from 'vue'
32
43const CLOSED_SIZE = '0px'
54
@@ -51,7 +50,7 @@ function prepareElement(element: HTMLElement, initialStyle: initialStyle) {
5150 return initialStyle . height && initialStyle . height != CLOSED_SIZE ? initialStyle . height : height
5251}
5352
54- function getEnterKeyframes ( height : string , initialStyle : initialStyle ) {
53+ function getEnterKeyframes ( height : string , initialStyle : initialStyle , parentGap : string | null ) {
5554 return [
5655 {
5756 height : CLOSED_SIZE ,
@@ -60,7 +59,8 @@ function getEnterKeyframes(height: string, initialStyle: initialStyle) {
6059 paddingBottom : CLOSED_SIZE ,
6160 borderTopWidth : CLOSED_SIZE ,
6261 borderBottomWidth : CLOSED_SIZE ,
63- marginTop : CLOSED_SIZE ,
62+ /* Handle case, where item is inside flexbox and gap is used */
63+ marginTop : parentGap ? `-${ parentGap } ` : CLOSED_SIZE ,
6464 marginBottom : CLOSED_SIZE ,
6565 } ,
6666 {
@@ -94,11 +94,25 @@ function animateTransition(
9494 return animation
9595}
9696
97+ function getParentGap ( element : Element ) : string | null {
98+ const parentElement = element . parentElement
99+ if ( ! parentElement ) {
100+ return null
101+ }
102+
103+ const { rowGap, display} = getComputedStyle ( element . parentElement ! )
104+ if ( display !== 'flex' || rowGap === 'normal' ) {
105+ return null
106+ }
107+
108+ return rowGap
109+ }
110+
97111export function useSlideTransition ( props : NSlideTransitionProps ) {
98112 function enterTransition ( element : Element , doneCallback : ( ) => void ) {
99113 const initialStyle = getElementStyle ( < HTMLElement > element )
100114 const height = prepareElement ( < HTMLElement > element , initialStyle )
101- const keyframes = getEnterKeyframes ( height , initialStyle )
115+ const keyframes = getEnterKeyframes ( height , initialStyle , getParentGap ( element ) )
102116 const options = { duration : props . duration , easing : 'ease-in-out' }
103117
104118 animateTransition ( < HTMLElement > element , initialStyle , doneCallback , keyframes , options )
@@ -111,7 +125,7 @@ export function useSlideTransition(props: NSlideTransitionProps) {
111125 ; ( < HTMLElement > element ) . style . height = height
112126 ; ( < HTMLElement > element ) . style . overflow = 'hidden'
113127
114- const keyframes = getEnterKeyframes ( height , initialStyle ) . reverse ( )
128+ const keyframes = getEnterKeyframes ( height , initialStyle , getParentGap ( element ) ) . reverse ( )
115129 const options = { duration : props . duration , easing : 'ease-in-out' }
116130 animateTransition ( < HTMLElement > element , initialStyle , doneCallback , keyframes , options )
117131 }
0 commit comments