Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,12 @@ online example: http://react-component.github.io/input-number/examples/
<td></td>
<td>Specifies a regex pattern to be added to the input number element - useful for forcing iOS to open the number pad instead of the normal keyboard (supply a regex of "\d*" to do this) or form validation</td>
</tr>
<tr>
<td>inputClassName</td>
<td>string</td>
<td></td>
<td>Specifies the custom className for input element</td>
</tr>
</tbody>
</table>

Expand Down
6 changes: 5 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export default class InputNumber extends React.Component {
precision: PropTypes.number,
required: PropTypes.bool,
pattern: PropTypes.string,
inputClassName: PropTypes.string,
}

static defaultProps = {
Expand Down Expand Up @@ -447,6 +448,9 @@ export default class InputNumber extends React.Component {
[`${prefixCls}-disabled`]: disabled,
[`${prefixCls}-focused`]: this.state.focused,
});
const inputClasses = classNames(`${prefixCls}-input`, {
[props.inputClassName]: !!props.inputClassName,
});
let upDisabledClass = '';
let downDisabledClass = '';
const { value } = this.state;
Expand Down Expand Up @@ -564,7 +568,7 @@ export default class InputNumber extends React.Component {
type={props.type}
placeholder={props.placeholder}
onClick={props.onClick}
className={`${prefixCls}-input`}
className={inputClasses}
tabIndex={props.tabIndex}
autoComplete="off"
onFocus={this.onFocus}
Expand Down
12 changes: 12 additions & 0 deletions tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1123,6 +1123,18 @@ describe('inputNumber', () => {
expect(inputElement.value).to.be('$ 6 boeing 737');
});
});

describe('inputClassName prop', () => {
it(`should render with a custom className for input if it is supplied`, () => {
ReactDOM.render(
<InputNumber id="pattern-input-test" inputClassName="custom-class" />,
container
);
expect(container
.querySelector('#pattern-input-test')
.className.indexOf('custom-class') > 0).to.be(true);
});
});
});

describe('Mobile inputNumber use TouchEvents', () => {
Expand Down