File tree Expand file tree Collapse file tree 1 file changed +40
-20
lines changed
Expand file tree Collapse file tree 1 file changed +40
-20
lines changed Original file line number Diff line number Diff line change 1- import React from 'react' ;
1+ import React , { Component } from 'react' ;
22import PropTypes from 'prop-types' ;
33import classNames from 'classnames' ;
44import { mapToCssModules } from './utils' ;
@@ -15,26 +15,46 @@ const propTypes = {
1515const defaultProps = {
1616 tag : 'form' ,
1717} ;
18+ class Form extends Component {
19+ constructor ( props ) {
20+ super ( props ) ;
21+ this . getRef = this . getRef . bind ( this ) ;
22+ this . submit = this . submit . bind ( this ) ;
23+ }
1824
19- const Form = ( props ) => {
20- const {
21- className,
22- cssModule,
23- inline,
24- tag : Tag ,
25- innerRef,
26- ...attributes
27- } = props ;
28-
29- const classes = mapToCssModules ( classNames (
30- className ,
31- inline ? 'form-inline' : false
32- ) , cssModule ) ;
33-
34- return (
35- < Tag { ...attributes } ref = { innerRef } className = { classes } />
36- ) ;
37- } ;
25+ getRef ( ref ) {
26+ if ( this . props . innerRef ) {
27+ this . props . innerRef ( ref ) ;
28+ }
29+ this . ref = ref ;
30+ }
31+
32+ submit ( ) {
33+ if ( this . ref ) {
34+ this . ref . submit ( ) ;
35+ }
36+ }
37+
38+ render ( ) {
39+ const {
40+ className,
41+ cssModule,
42+ inline,
43+ tag : Tag ,
44+ innerRef,
45+ ...attributes
46+ } = this . props ;
47+
48+ const classes = mapToCssModules ( classNames (
49+ className ,
50+ inline ? 'form-inline' : false
51+ ) , cssModule ) ;
52+
53+ return (
54+ < Tag { ...attributes } ref = { innerRef } className = { classes } />
55+ ) ;
56+ }
57+ }
3858
3959Form . propTypes = propTypes ;
4060Form . defaultProps = defaultProps ;
You can’t perform that action at this time.
0 commit comments