Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for #76, add tabindex attribute to input element #108

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -198,6 +198,10 @@ DatePicker component. Renders as a [React-Bootstrap InputGroup](https://react-bo
* **Optional**
* **Type:** `React.Component`
* **Example:** `<CustomControl />`
* `tabIndex` - The tabIndex specifies the tab order of the input element. If a `customControl` is used, this property is passed down to it as well.
* **Optional**
* **Type:** `number`
* **Example:** `2`

* **Methods:**

Expand Down
35 changes: 35 additions & 0 deletions example/app.jsx
Expand Up @@ -422,6 +422,41 @@ const App = React.createClass({
</FormGroup>
</Col>
</Row>
<Row>
<Col xs={12}>
<h2>Tab Indexes</h2>
</Col>
</Row>
<Row>
<Col sm={3}>
<FormGroup>
<ControlLabel>Third</ControlLabel>
<DatePicker placeholder="Placeholder" tabIndex={103} />
<HelpBlock>The focus will jump here after Second</HelpBlock>
</FormGroup>
</Col>
<Col sm={3}>
<FormGroup>
<ControlLabel>Second</ControlLabel>
<DatePicker placeholder="Placeholder" tabIndex={102} />
<HelpBlock>The focus will jump here after First.</HelpBlock>
</FormGroup>
</Col>
<Col sm={3}>
<FormGroup>
<ControlLabel>Fourth</ControlLabel>
<DatePicker placeholder="Placeholder" tabIndex={104} />
<HelpBlock>The focus will jump here after Third</HelpBlock>
</FormGroup>
</Col>
<Col sm={3}>
<FormGroup>
<ControlLabel>First</ControlLabel>
<DatePicker placeholder="Placeholder" tabIndex={101} />
<HelpBlock>Focus on this element to start!</HelpBlock>
</FormGroup>
</Col>
</Row>
</Grid>;
}
});
Expand Down
5 changes: 4 additions & 1 deletion src/index.jsx
Expand Up @@ -268,7 +268,8 @@ export default React.createClass({
children: React.PropTypes.oneOfType([
React.PropTypes.arrayOf(React.PropTypes.node),
React.PropTypes.node
])
]),
tabIndex: React.PropTypes.number
},

getDefaultProps() {
Expand Down Expand Up @@ -612,6 +613,7 @@ export default React.createClass({
className: this.props.className,
style: this.props.style,
autoComplete: this.props.autoComplete,
tabIndex: this.props.tabIndex
})
: <FormControl
onKeyDown={this.handleKeyDown}
Expand All @@ -628,6 +630,7 @@ export default React.createClass({
onBlur={this.handleBlur}
onChange={this.handleInputChange}
autoComplete={this.props.autoComplete}
tabIndex={this.props.tabIndex}
/>;

return <InputGroup
Expand Down
18 changes: 18 additions & 0 deletions test/core.test.jsx
Expand Up @@ -1100,4 +1100,22 @@ describe("Date Picker", function() {
assert.notEqual(popover, null);
ReactDOM.unmountComponentAtNode(container);
}));
it("should set a tabindex on the input control", co.wrap(function *(){
const id = UUID.v4();
const App = React.createClass({
render: function(){
return <div>
<DatePicker id={id} tabIndex={101} />
</div>;
}
});
yield new Promise(function(resolve, reject){
ReactDOM.render(<App />, container, resolve);
});
const inputElement = document.querySelector("input.form-control");
TestUtils.Simulate.focus(inputElement);
assert.notEqual(inputElement, null);
assert.equal(inputElement.getAttribute('tabindex'), 101);
ReactDOM.unmountComponentAtNode(container);
}));
});