Skip to content

Commit b8f52d2

Browse files
committed
Including layoutStyle by default with ability to turn off
1 parent a6b131c commit b8f52d2

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

src/ReactDataList.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react'
22
import DataList from './components/DataList'
33
import DataListOption from './components/DataListOption'
4+
import layout from './styles/react-datalist.styl'
45

56
export default class ReactDataList extends React.Component {
67
constructor(props) {
@@ -13,10 +14,12 @@ export default class ReactDataList extends React.Component {
1314
}
1415
}
1516
render() {
16-
var options = this.filterOptions(this.props.options, this.state.filter, this.useNative())
17+
var options = this.filterOptions(this.props.options, this.state.filter, this.useNative())
1718
var extraClasses = this.props.className? ' ' + this.props.className: '';
19+
var layoutstyle = (this.props.includeLayoutStyle) ? <style>{layout}</style> : null
1820
return (
1921
<div className="react-datalist-container">
22+
{layoutstyle}
2023
<input ref="theInput"
2124
list={this.props.list}
2225
value={this.state.filter}
@@ -168,8 +171,9 @@ export default class ReactDataList extends React.Component {
168171
}
169172
}
170173
ReactDataList.defaultProps = {
171-
blurTimeout : 200,
172-
hideOptionsOnBlur : true,
173-
hideOptionsOnEsc : true
174+
blurTimeout : 200,
175+
includeLayoutStyle : true,
176+
hideOptionsOnBlur : true,
177+
hideOptionsOnEsc : true
174178
}
175179

src/styles/react-datalist.styl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
div.react-datalist
1+
.react-datalist
22
margin : 0 !important
33
border : 1px solid #A1C1E7
44
max-height : 500px
@@ -16,4 +16,4 @@ div.react-datalist
1616
background-color #BAD4FE
1717

1818
&.react-datalist-option-selected
19-
background-color #BAD4FE
19+
background-color #BAD4FE

test/spec.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,4 +339,20 @@ describe('DATALIST', function() {
339339

340340
})
341341

342+
it('includes layout style by default', function(done) {
343+
render({}, function() {
344+
var style = nanodom('style')
345+
assert(style.length == 1)
346+
done()
347+
})
348+
})
349+
350+
it('does not include layout style if includeLayoutStyle=false is passed as prop', function(done) {
351+
render({ includeLayoutStyle : false }, function() {
352+
var style = nanodom('style')
353+
assert(style.length == 0)
354+
done()
355+
})
356+
})
357+
342358
})

0 commit comments

Comments
 (0)