File tree Expand file tree Collapse file tree 4 files changed +23
-15
lines changed
fixtures/kitchensink/src/features/webpack Expand file tree Collapse file tree 4 files changed +23
-15
lines changed Original file line number Diff line number Diff line change 1
- // @remove -on-eject-begin
2
- /**
3
- * Copyright (c) 2014-present, Facebook, Inc.
4
- *
5
- * This source code is licensed under the MIT license found in the
6
- * LICENSE file in the root directory of this source tree.
7
- */
8
- // @remove -on-eject-end
9
1
'use strict' ;
10
2
11
3
const path = require ( 'path' ) ;
@@ -18,18 +10,19 @@ module.exports = {
18
10
const assetFilename = JSON . stringify ( path . basename ( filename ) ) ;
19
11
20
12
if ( filename . match ( / \. s v g $ / ) ) {
21
- return `module.exports = {
13
+ return `const React = require('react');
14
+ module.exports = {
22
15
__esModule: true,
23
16
default: ${ assetFilename } ,
24
- ReactComponent: ( props) => ({
17
+ ReactComponent: React.forwardRef(( props, ref ) => ({
25
18
$$typeof: Symbol.for('react.element'),
26
19
type: 'svg',
27
- ref: null ,
20
+ ref: ref ,
28
21
key: null,
29
22
props: Object.assign({}, props, {
30
23
children: ${ assetFilename }
31
24
})
32
- }),
25
+ })) ,
33
26
};` ;
34
27
}
35
28
Original file line number Diff line number Diff line change @@ -377,7 +377,7 @@ module.exports = function(webpackEnv) {
377
377
{
378
378
loaderMap : {
379
379
svg : {
380
- ReactComponent : '@svgr/webpack?-svgo![path]' ,
380
+ ReactComponent : '@svgr/webpack?-svgo,+ref ![path]' ,
381
381
} ,
382
382
} ,
383
383
} ,
Original file line number Diff line number Diff line change 8
8
import React from 'react' ;
9
9
import { ReactComponent as Logo } from './assets/logo.svg' ;
10
10
11
- export default ( ) => < Logo id = "feature-svg-component" /> ;
11
+ export default ( ) => {
12
+ return < Logo id = "feature-svg-component" /> ;
13
+ } ;
14
+
15
+ export const SvgComponentWithRef = React . forwardRef ( ( props , ref ) => (
16
+ < Logo id = "feature-svg-component-with-ref" ref = { ref } />
17
+ ) ) ;
Original file line number Diff line number Diff line change 7
7
8
8
import React from 'react' ;
9
9
import ReactDOM from 'react-dom' ;
10
- import SvgComponent from './SvgComponent' ;
10
+ import SvgComponent , { SvgComponentWithRef } from './SvgComponent' ;
11
11
12
12
describe ( 'svg component' , ( ) => {
13
13
it ( 'renders without crashing' , ( ) => {
14
14
const div = document . createElement ( 'div' ) ;
15
15
ReactDOM . render ( < SvgComponent /> , div ) ;
16
16
expect ( div . textContent ) . toBe ( 'logo.svg' ) ;
17
17
} ) ;
18
+
19
+ it ( 'svg root element equals the passed ref' , ( ) => {
20
+ const div = document . createElement ( 'div' ) ;
21
+ const someRef = React . createRef ( ) ;
22
+ ReactDOM . render ( < SvgComponentWithRef ref = { someRef } /> , div ) ;
23
+ const svgElement = div . getElementsByTagName ( 'svg' ) ;
24
+ expect ( svgElement ) . toHaveLength ( 1 ) ;
25
+ expect ( svgElement [ 0 ] ) . toBe ( someRef . current ) ;
26
+ } ) ;
18
27
} ) ;
You can’t perform that action at this time.
0 commit comments