From 3be1b7dd5835c4d54bb8366bbb23ccaf181a90ca Mon Sep 17 00:00:00 2001 From: jquense Date: Thu, 8 Oct 2015 19:40:43 -0400 Subject: [PATCH] [changed] reorder onKeyDown and respect preventDefault --- src/Combobox.jsx | 7 +++++-- src/DateTimePicker.jsx | 9 +++++++-- src/DropdownList.jsx | 8 +++++--- src/Multiselect.jsx | 6 +++++- src/NumberPicker.jsx | 5 +++++ src/SelectList.jsx | 6 ++++++ 6 files changed, 33 insertions(+), 8 deletions(-) diff --git a/src/Combobox.jsx b/src/Combobox.jsx index b7eed65b6..8eeb6fa5e 100644 --- a/src/Combobox.jsx +++ b/src/Combobox.jsx @@ -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) @@ -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) diff --git a/src/DateTimePicker.jsx b/src/DateTimePicker.jsx index c9e46a335..fab91b248 100644 --- a/src/DateTimePicker.jsx +++ b/src/DateTimePicker.jsx @@ -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'){ @@ -340,7 +345,7 @@ var DateTimePicker = React.createClass({ this.refs.timePopup._keyDown(e) } - notify(this.props.onKeyDown, [e]) + }, @widgetEnabled diff --git a/src/DropdownList.jsx b/src/DropdownList.jsx index a5a3d10ab..6fe3dfb07 100644 --- a/src/DropdownList.jsx +++ b/src/DropdownList.jsx @@ -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()) @@ -311,9 +316,6 @@ var DropdownList = React.createClass({ : change(item) }) - - notify(this.props.onKeyDown, [e]) - function change(item, fromList){ if(!item) return fromList diff --git a/src/Multiselect.jsx b/src/Multiselect.jsx index cfe0d7a3b..bc0c35387 100644 --- a/src/Multiselect.jsx +++ b/src/Multiselect.jsx @@ -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; @@ -446,7 +451,6 @@ var Multiselect = React.createClass({ else if (noSearch && key === 'Backspace') tagList && tagList.removeNext() - notify(this.props.onKeyDown, [e]) }, @widgetEditable diff --git a/src/NumberPicker.jsx b/src/NumberPicker.jsx index 397c8c100..0042ffdcb 100644 --- a/src/NumberPicker.jsx +++ b/src/NumberPicker.jsx @@ -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) diff --git a/src/SelectList.jsx b/src/SelectList.jsx index 99b3138d7..9c5e564e2 100644 --- a/src/SelectList.jsx +++ b/src/SelectList.jsx @@ -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) @@ -189,6 +190,11 @@ var SelectList = React.createClass({ : true) } + notify(this.props.onKeyDown, [e]) + + if (e.defaultPrevented) + return + if (key === 'End') { e.preventDefault()