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
91'use strict' ;
102
113const path = require ( 'path' ) ;
@@ -18,18 +10,19 @@ module.exports = {
1810 const assetFilename = JSON . stringify ( path . basename ( filename ) ) ;
1911
2012 if ( filename . match ( / \. s v g $ / ) ) {
21- return `module.exports = {
13+ return `const React = require('react');
14+ module.exports = {
2215 __esModule: true,
2316 default: ${ assetFilename } ,
24- ReactComponent: ( props) => ({
17+ ReactComponent: React.forwardRef(( props, ref ) => ({
2518 $$typeof: Symbol.for('react.element'),
2619 type: 'svg',
27- ref: null ,
20+ ref: ref ,
2821 key: null,
2922 props: Object.assign({}, props, {
3023 children: ${ assetFilename }
3124 })
32- }),
25+ })) ,
3326 };` ;
3427 }
3528
Original file line number Diff line number Diff line change @@ -377,7 +377,7 @@ module.exports = function(webpackEnv) {
377377 {
378378 loaderMap : {
379379 svg : {
380- ReactComponent : '@svgr/webpack?-svgo![path]' ,
380+ ReactComponent : '@svgr/webpack?-svgo,+ref ![path]' ,
381381 } ,
382382 } ,
383383 } ,
Original file line number Diff line number Diff line change 88import React from 'react' ;
99import { ReactComponent as Logo } from './assets/logo.svg' ;
1010
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 77
88import React from 'react' ;
99import ReactDOM from 'react-dom' ;
10- import SvgComponent from './SvgComponent' ;
10+ import SvgComponent , { SvgComponentWithRef } from './SvgComponent' ;
1111
1212describe ( 'svg component' , ( ) => {
1313 it ( 'renders without crashing' , ( ) => {
1414 const div = document . createElement ( 'div' ) ;
1515 ReactDOM . render ( < SvgComponent /> , div ) ;
1616 expect ( div . textContent ) . toBe ( 'logo.svg' ) ;
1717 } ) ;
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+ } ) ;
1827} ) ;
You can’t perform that action at this time.
0 commit comments