Skip to content

Commit 32fa001

Browse files
committed
fixes #24
wow, numberpicker-input was relying on lodash but it wasn't required
1 parent 74cf6ee commit 32fa001

File tree

17 files changed

+536
-53
lines changed

17 files changed

+536
-53
lines changed

browser/react-widgets.js

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/components/docs.jsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ var Docs = React.createClass({
4747
<div className='nav-aside'>
4848
<Nav className='side-nav' onSelect={this.handleNavItemSelect}>
4949
<NavItem key={0} href='#intro' active={href === '#intro' }>Getting Started</NavItem>
50-
<NavItem key={1} href='#dropdown-list' active={ href === '#dropdown-list' }>Dropdown List</NavItem>
50+
<NavItem key={1} href='#dropdownlist' active={ href === '#dropdownlist' }>Dropdown List</NavItem>
5151
<NavItem key={2} href='#combobox' active={href === '#combobox'}>Combobox</NavItem>
5252
<NavItem key={6} href='#number-picker' active={href === '#number-picker' }>Number Picker</NavItem>
53-
<NavItem key={3} href='#select-list' active={href === '#select-list'}>Select</NavItem>
53+
<NavItem key={3} href='#multiselect' active={href === '#multiselect'}>Select</NavItem>
5454
<NavItem key={4} href='#calendar' active={href === '#calendar'}>Calendar</NavItem>
5555
<NavItem key={5} href='#date-picker' active={href === '#date-picker'}>Date {' & '} Time Picker</NavItem>
5656
</Nav>
@@ -63,10 +63,10 @@ var Docs = React.createClass({
6363

6464
<NumberPicker className={cx({"tab-pane": true, "active": href === '#number-picker' })}/>
6565
<Select className={cx({"tab-pane": true, "active": href === '#multiselect' })}/>
66-
{/*<SelectList className={cx({"tab-pane": true, "active": href === '#selectlist' })}/>*/}
67-
66+
6867
<Calendar className={cx({"tab-pane": true, "active": href === '#calendar' })}/>
6968
<DatePicker className={cx({"tab-pane": true, "active": href === '#date-picker' })}/>
69+
7070
<div className='clearfix'style={{ marginTop: 20 }}>
7171
{ locations.indexOf(href) > 0 &&
7272
<button type='button' className='btn btn-link pull-left' onClick={this.prev}>« prev</button>
@@ -75,6 +75,7 @@ var Docs = React.createClass({
7575
<button type='button' className='btn btn-link pull-right' onClick={this.next}>next »</button>
7676
}
7777
</div>
78+
{/*<SelectList className={cx({"tab-pane": true, "active": href === '#selectlist' })}/>*/}
7879
</article>
7980
</div>
8081
</div>

docs/components/pages/NumberPicker.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ var NumberPicker = React.createClass({
3737

3838
</h1>
3939
<p>
40-
Select an item from the list, or input a custom value. The vombobox can also make suggestions as you type
40+
Spinner for selecting numbers. Supports multiple formats for display and editing through Globalize.js
4141
</p>
4242
<NumberPickerExample/>
4343
<Example code={
@@ -47,8 +47,8 @@ var NumberPicker = React.createClass({
4747
" <NumberPicker \n"+
4848
" value={this.state.value}\n"+
4949
" onChange={this._change}\n"+
50-
" min='2'\n"+
51-
" max='10'/>\n\n"+
50+
" min={2}\n"+
51+
" max={10}/>\n\n"+
5252
" <NumberPicker \n"+
5353
" format='c'\n" +
5454
" step={1.5}/>\n\n"+

example/example.jsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,18 @@ var CheckboxList = require('../src/select/SelectList.jsx')
1010
var chance = new (require('chance'))
1111
//var _ = require('lodash')
1212

13+
function test(...args){
14+
console.log(args)
15+
}
16+
17+
function test2(first, sec, ...args){
18+
console.log(first, sec, args)
19+
}
20+
21+
test(1,2,3,5)
22+
test2(1,2,3,5)
23+
24+
1325
var ListItem = React.createClass({
1426

1527
render: function(){
@@ -72,6 +84,13 @@ var App = React.createClass({
7284

7385
onChange={change.bind(null, 'selectValues')}/>
7486
</section>
87+
<section className="example" style={{ marginBottom: 20 }}>
88+
<NumberPicker id='AwesomeNumPicker'
89+
isRtl={false}
90+
format="D"
91+
value={this.state.numberValue}
92+
onChange={change.bind(null, 'numberValue')}/>
93+
</section>
7594
{/*
7695
<section className="example" style={{ marginBottom: 20 }}>
7796
<DropdownList

lib/common/busy-overlay.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* React.DOM
3+
*/
4+
5+
var React = require('react');
6+
7+
var BusyOverlay = React.createClass({displayName: 'BusyOverlay',
8+
9+
render: function() {
10+
return (
11+
React.DOM.div({className: "rw-loading-mask"},
12+
React.DOM.div({className: "rw-loading-backdrop"}),
13+
React.DOM.div({className: "rw-loading-image"})
14+
)
15+
);
16+
}
17+
});
18+
19+
module.exports = BusyOverlay;

lib/common/list.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ module.exports = React.createClass({
7272
var emptyList = React.DOM.li(null, this.props.messages.emptyList)
7373
, emptyFilter = React.DOM.li(null, this.props.messages.emptyFilter)
7474
, items;
75-
7675

7776
items = _.map(this.props.data, function(item, idx){
7877
var focused = this.props.focusedIndex === idx;

lib/dropdowns/dropdown-list.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ var DropdownList = React.createClass({
114114
onBlur: _.partial(this._focus, false),
115115
'aria-expanded': this.props.open,
116116
'aria-haspopup': true,
117+
'aria-busy': !!this.props.busy,
117118
'aria-activedescendent': this.props.open ? optID : undefined,
118119
'aria-disabled': this.props.disabled,
119120
'aria-readonly': this.props.readOnly,
@@ -207,7 +208,7 @@ var DropdownList = React.createClass({
207208
else if ( key === 'Escape' && isOpen ) {
208209
this.close()
209210
}
210-
else if ( key === 'Enter' && isOpen ) {
211+
else if ( (key === 'Enter' || key === ' ') && isOpen ) {
211212
change(this.state.focusedIndex)
212213
}
213214
else if ( key === 'ArrowDown' ) {

lib/mixins/DataIndexStateMixin.js

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ var React = require('react')
88

99

1010

11-
module.exports = function(stateKey) {
11+
module.exports = function(stateKey, disabled) {
1212
var methodName = stateKey.charAt(0).toUpperCase() + stateKey.substr(1)
1313

1414
, ifValueChanges = compose.provided(function(props){
@@ -31,30 +31,38 @@ module.exports = function(stateKey) {
3131

3232
mixin['set' + methodName] = fluent(setIndex)
3333

34-
mixin['prev' + methodName] = function(){
34+
mixin['prev' + methodName] = function(nextIdx){
3535
var data = this._data()
36-
, nextIdx = this.state && this.state[stateKey] || 0;
36+
, stateIdx = this.state && this.state[stateKey] || 0;
37+
38+
nextIdx = (nextIdx === undefined ? stateIdx : nextIdx) -1;
3739

38-
nextIdx -= 1
40+
while( nextIdx > -1 && isDisabled(this, data[nextIdx])) nextIdx--
3941

40-
if ( nextIdx < 0 )
41-
nextIdx = 0
42+
if ( nextIdx < 0 )
43+
nextIdx = disabled ? -1 : 0
4244

4345
return nextIdx;
4446
}
4547

46-
mixin['next' + methodName] = function(){
48+
mixin['next' + methodName] = function(nextIdx){
4749
var data = this._data()
48-
, nextIdx = this.state && this.state[stateKey] || 0;
50+
, stateIdx = this.state && this.state[stateKey] || 0;
51+
52+
nextIdx = (nextIdx === undefined ? stateIdx : nextIdx) + 1
4953

50-
nextIdx += 1
54+
while( nextIdx < data.length && isDisabled(this, data[nextIdx])) nextIdx++
5155

5256
if ( nextIdx >= data.length )
53-
nextIdx = data.length -1;
57+
nextIdx = disabled ? -1 : data.length - 1;
5458

5559
return nextIdx;
5660
}
5761

62+
function isDisabled(ctx, item){
63+
return disabled && ctx[disabled](item)
64+
}
65+
5866
return mixin;
5967
}
6068

lib/mixins/TextSearchMixin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ module.exports = {
3333
, self = this;
3434

3535
return _.findIndex(self._data(), function(item, i) {
36-
return i != current
36+
return i >= current
3737
&& matcher(
3838
helper._dataText.call(self, item).toLowerCase()
3939
, word.toLowerCase())

lib/pickers/numberpicker.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ var NumberPicker = React.createClass({
5858

5959
getDefaultProps: function(){
6060
return {
61-
value: '',
61+
value: null,
6262
open: false,
6363

6464
format: 'd',
@@ -135,8 +135,8 @@ var NumberPicker = React.createClass({
135135
role: "spinbutton",
136136
min: this.props.min,
137137
'aria-valuenow': val,
138-
'aria-valuemin': _.isFinite(this.props.min) ? this.props.min : '',
139-
'aria-valuemax': _.isFinite(this.props.max) ? this.props.max : '',
138+
'aria-valuemin': _.isFinite(this.props.min) ? this.props.min : null,
139+
'aria-valuemax': _.isFinite(this.props.max) ? this.props.max : null,
140140
'aria-disabled': this.props.disabled,
141141
'aria-readonly': this.props.readonly,
142142
disabled: this.props.disabled,
@@ -220,18 +220,20 @@ var NumberPicker = React.createClass({
220220
},
221221

222222
change: function(val){
223-
val = this.inRangeValue(val)
223+
val = this.inRangeValue(val === '' ? null : val)
224+
224225
if ( this.props.value !== val )
225226
this.notify('onChange', val)
226227
},
227228

228229
inRangeValue: function(value){
229-
if( !_.isFinite(this.props.min) && value == null || value === '' )
230+
var max = this.props.max == null ? Infinity : this.props.max
231+
, min = this.props.min == null ? -Infinity : this.props.min;
232+
233+
if( value == null )
230234
return value
231235

232-
return Math.max(
233-
Math.min(value, this.props.max)
234-
, this.props.min)
236+
return Math.max(Math.min(value, max), min)
235237
}
236238

237239
})

0 commit comments

Comments
 (0)