@@ -51,6 +51,38 @@ class TodoList extends Component {
51
51
}
52
52
}
53
53
54
+ class SVGList extends Component {
55
+ state = {
56
+ items : [ 'hello' , 'world' , 'click' , 'me' ]
57
+ } ;
58
+
59
+ handleAdd ( item ) {
60
+ let { items } = this . state ;
61
+ items = items . concat ( item ) ;
62
+ this . setState ( { items } ) ;
63
+ }
64
+
65
+ handleRemove ( i ) {
66
+ let { items } = this . state ;
67
+ items . splice ( i , 1 ) ;
68
+ this . setState ( { items } ) ;
69
+ }
70
+
71
+ render ( _ , { items } ) {
72
+ return (
73
+ < svg >
74
+ < CSSTransitionGroup transitionName = "example" component = "g" >
75
+ { items . map ( ( item , i ) => (
76
+ < text key = { item } className = "item" >
77
+ { item }
78
+ </ text >
79
+ ) ) }
80
+ </ CSSTransitionGroup >
81
+ </ svg >
82
+ ) ;
83
+ }
84
+ }
85
+
54
86
55
87
const Nothing = ( ) => null ;
56
88
@@ -115,3 +147,60 @@ describe('CSSTransitionGroup', () => {
115
147
} , 1400 ) ;
116
148
} ) ;
117
149
} ) ;
150
+
151
+ describe ( 'CSSTransitionGroup: SVG' , ( ) => {
152
+ let container = document . createElement ( 'div' ) ,
153
+ list , root ;
154
+ document . body . appendChild ( container ) ;
155
+
156
+ let $ = s => [ ] . slice . call ( container . querySelectorAll ( s ) ) ;
157
+
158
+ beforeEach ( ( ) => {
159
+ root = render ( < div > < Nothing /> </ div > , container , root ) ;
160
+ root = render ( < div > < SVGList ref = { c => list = c } /> </ div > , container , root ) ;
161
+ } ) ;
162
+
163
+ afterEach ( ( ) => {
164
+ list = null ;
165
+ } ) ;
166
+
167
+ it ( 'create works' , ( ) => {
168
+ expect ( $ ( '.item' ) ) . to . have . length ( 4 ) ;
169
+ } ) ;
170
+
171
+ it ( 'transitionLeave works' , done => {
172
+ list . handleRemove ( 0 ) ;
173
+
174
+ setTimeout ( ( ) => {
175
+ expect ( $ ( '.item' ) ) . to . have . length ( 4 ) ;
176
+
177
+ expect ( $ ( '.item' ) [ 0 ] . classList . contains ( 'example-leave' ) ) ;
178
+ expect ( $ ( '.item' ) [ 0 ] . classList . contains ( 'example-leave-active' ) ) ;
179
+ } , 100 ) ;
180
+
181
+ setTimeout ( ( ) => {
182
+ expect ( $ ( '.item' ) ) . to . have . length ( 3 ) ;
183
+ done ( ) ;
184
+ } , 1400 ) ;
185
+ } ) ;
186
+
187
+ it ( 'transitionEnter works' , done => {
188
+ list . handleAdd ( Date . now ( ) ) ;
189
+
190
+ setTimeout ( ( ) => {
191
+ expect ( $ ( '.item' ) ) . to . have . length ( 5 ) ;
192
+
193
+ expect ( $ ( '.item' ) [ 4 ] . classList . contains ( 'example-enter' ) ) ;
194
+ expect ( $ ( '.item' ) [ 4 ] . classList . contains ( 'example-enter-active' ) ) ;
195
+ } , 500 ) ;
196
+
197
+ setTimeout ( ( ) => {
198
+ expect ( $ ( '.item' ) ) . to . have . length ( 5 ) ;
199
+
200
+ expect ( ! $ ( '.item' ) [ 4 ] . classList . contains ( 'example-enter' ) ) ;
201
+ expect ( ! $ ( '.item' ) [ 4 ] . classList . contains ( 'example-enter-active' ) ) ;
202
+
203
+ done ( ) ;
204
+ } , 1400 ) ;
205
+ } ) ;
206
+ } ) ;
0 commit comments