File tree Expand file tree Collapse file tree 2 files changed +20
-2
lines changed
Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -3,7 +3,10 @@ var React = require('react');
33var LazyInput = React . createClass ( {
44 displayName : "LazyInput" ,
55 propTypes : {
6- type : React . PropTypes . string , // ['text'] type of input/textarea
6+ type : React . PropTypes . oneOfType ( [ // by defaut it will use a React.DOM.input (type='text')
7+ React . PropTypes . string , // ['text'] type of input ('textarea' will create a textarea element, anything else will pass to input)
8+ React . PropTypes . func // a React component class
9+ ] ) ,
710 lazyLevel : React . PropTypes . number // [1000] number of ms to wait before responding to changes in prop.value
811 // note: passes through everything but lazyLevel
912 } ,
@@ -56,7 +59,12 @@ var LazyInput = React.createClass({
5659 return props ;
5760 } ,
5861 render : function ( ) {
59- return React . createElement ( this . props . type === "textarea" ? "textarea" : "input" , this . getProps ( ) ) ;
62+ var type = this . props . type ;
63+ if ( ! type || type === "text" ) {
64+ type = "input" ;
65+ }
66+
67+ return React . createElement ( type , this . getProps ( ) ) ;
6068 }
6169
6270} ) ;
Original file line number Diff line number Diff line change @@ -32,6 +32,16 @@ describe('LazyInput', function() {
3232 var input = TestUtils . renderIntoDocument ( < LazyInput type = "textarea" /> ) ;
3333 expect ( TestUtils . findRenderedDOMComponentWithTag ( input , 'textarea' ) ) . not . to . be ( undefined ) ;
3434 } ) ;
35+ it ( 'should render a custom type when a React class is given' , function ( ) {
36+ var CustomType = React . createClass ( {
37+ render : function ( ) {
38+ return < input className = "custom" { ...this . props } />
39+ }
40+ } ) ;
41+
42+ var input = TestUtils . renderIntoDocument ( < LazyInput type = { CustomType } /> ) ;
43+ expect ( TestUtils . findRenderedDOMComponentWithClass ( input , 'custom' ) ) . not . to . be ( undefined ) ;
44+ } ) ;
3545
3646 describe ( "props" , function ( ) {
3747 // specificially import props
You can’t perform that action at this time.
0 commit comments