Skip to content

Commit

Permalink
[changed] reorder onKeyDown and respect preventDefault
Browse files Browse the repository at this point in the history
  • Loading branch information
jquense committed Oct 8, 2015
1 parent 2fa924a commit 3be1b7d
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 8 deletions.
7 changes: 5 additions & 2 deletions src/Combobox.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,11 @@ var ComboBox = React.createClass({
, selectedItem = this.state.selectedItem
, isOpen = this.props.open;

notify(this.props.onKeyDown, [e])

if (e.defaultPrevented)
return

if ( key === 'End' )
if ( isOpen ) this.setState({ focusedItem: list.last() })
else select(list.last(), true)
Expand Down Expand Up @@ -344,8 +349,6 @@ var ComboBox = React.createClass({
}
}

notify(this.props.onKeyDown, [e])

function select(item, fromList) {
if(!item)
return self.change(compat.findDOMNode(self.refs.input).value, false)
Expand Down
9 changes: 7 additions & 2 deletions src/DateTimePicker.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,15 @@ var DateTimePicker = React.createClass({
_keyDown(e){
let { open, calendar, time } = this.props;

notify(this.props.onKeyDown, [e])

if (e.defaultPrevented)
return

if (e.key === 'Escape' && open)
this.close()

else if ( e.altKey ) {
else if (e.altKey) {
e.preventDefault()

if (e.key === 'ArrowDown'){
Expand All @@ -340,7 +345,7 @@ var DateTimePicker = React.createClass({
this.refs.timePopup._keyDown(e)
}

notify(this.props.onKeyDown, [e])

},

@widgetEnabled
Expand Down
8 changes: 5 additions & 3 deletions src/DropdownList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,11 @@ var DropdownList = React.createClass({
, isOpen = this.props.open
, closeWithFocus = () => { this.close(), compat.findDOMNode(this).focus()};

notify(this.props.onKeyDown, [e])

if (e.defaultPrevented)
return

if ( key === 'End' ) {
if ( isOpen) this.setState({ focusedItem: list.last() })
else change(list.last())
Expand Down Expand Up @@ -311,9 +316,6 @@ var DropdownList = React.createClass({
: change(item)
})


notify(this.props.onKeyDown, [e])

function change(item, fromList){
if(!item) return
fromList
Expand Down
6 changes: 5 additions & 1 deletion src/Multiselect.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,11 @@ var Multiselect = React.createClass({
let { list, tagList } = this.refs;
let nullTag = { focusedTag: null };

notify(this.props.onKeyDown, [e])

if (e.defaultPrevented)
return

if ( key === 'ArrowDown') {
var next = list.next(focusedItem)
, creating = (this._shouldShowCreate() && focusedItem === next) || focusedItem === null;
Expand Down Expand Up @@ -446,7 +451,6 @@ var Multiselect = React.createClass({
else if (noSearch && key === 'Backspace')
tagList && tagList.removeNext()

notify(this.props.onKeyDown, [e])
},

@widgetEditable
Expand Down
5 changes: 5 additions & 0 deletions src/NumberPicker.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,11 @@ let NumberPicker = React.createClass({
_keyDown(e) {
var key = e.key;

notify(this.props.onKeyDown, [e])

if (e.defaultPrevented)
return

if ( key === 'End' && isFinite(this.props.max))
this.change(this.props.max)

Expand Down
6 changes: 6 additions & 0 deletions src/SelectList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ var SelectList = React.createClass({
, focusedItem = this.state.focusedItem
, props = this.props;


let moveItem = (dir, item)=> move(dir, item, props, list);
let change = (item) => {
if (item)
Expand All @@ -189,6 +190,11 @@ var SelectList = React.createClass({
: true)
}

notify(this.props.onKeyDown, [e])

if (e.defaultPrevented)
return

if (key === 'End') {
e.preventDefault()

Expand Down

0 comments on commit 3be1b7d

Please sign in to comment.