Skip to content

Commit

Permalink
[added] autoFocus support to dropdown, calendar, and selectlist
Browse files Browse the repository at this point in the history
  • Loading branch information
jquense committed Jul 11, 2016
1 parent 7e0d4a7 commit 4168df5
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/Calendar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ let Calendar = React.createClass({

mixins: [
require('./mixins/TimeoutMixin'),
require('./mixins/AutoFocusMixin'),
require('./mixins/PureRenderMixin'),
require('./mixins/RtlParentContextMixin'),
require('./mixins/AriaDescendantMixin')(),
Expand Down
1 change: 1 addition & 0 deletions src/DateTimePicker.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ var DateTimePicker = React.createClass({
id={id}
tabIndex='-1'
value={value}
autoFocus={false}
onChange={this.handleDateSelect}
// #75: need to aggressively reclaim focus from the calendar otherwise
// disabled header/footer buttons will drop focus completely from the widget
Expand Down
5 changes: 1 addition & 4 deletions src/DropdownList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,10 @@ var propTypes = {
groupBy: CustomPropTypes.accessor,

onSelect: React.PropTypes.func,

searchTerm: React.PropTypes.string,
onSearch: React.PropTypes.func,

busy: React.PropTypes.bool,

delay: React.PropTypes.number,

dropUp: React.PropTypes.bool,
duration: React.PropTypes.number, //popup

Expand All @@ -72,6 +68,7 @@ var DropdownList = React.createClass({

mixins: [
require('./mixins/TimeoutMixin'),
require('./mixins/AutoFocusMixin'),
require('./mixins/PureRenderMixin'),
require('./mixins/DataFilterMixin'),
require('./mixins/PopupScrollToMixin'),
Expand Down
1 change: 1 addition & 0 deletions src/SelectList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ var SelectList = React.createClass({

mixins: [
require('./mixins/TimeoutMixin'),
require('./mixins/AutoFocusMixin'),
require('./mixins/RtlParentContextMixin'),
require('./mixins/AriaDescendantMixin')(),
require('./mixins/FocusMixin')({
Expand Down
15 changes: 15 additions & 0 deletions src/mixins/AutoFocusMixin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react';
import { findDOMNode } from 'react-dom';

export default {
propTypes: {
autoFocus: React.PropTypes.bool
},

componentDidMount() {
let { autoFocus } = this.props;

if (autoFocus)
this.focus ? this.focus() : findDOMNode(this).focus()
}
};
8 changes: 8 additions & 0 deletions test/dropdown.browser.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ describe('DROPDOWNS', function(){
expect(openSpy.calledWith(true)).to.be(true);
})

it('should respect autoFocus', () => {
expect(
tsp(<ControlledDropdownList autoFocus />)
.render(true)
.dom()
).to.equal(document.activeElement);
})

it('should not open when clicked while disabled or readOnly', () => {
let openSpy = sinon.spy();

Expand Down

0 comments on commit 4168df5

Please sign in to comment.