Skip to content
This repository has been archived by the owner on Oct 19, 2021. It is now read-only.

fix(NumberInput): add button type and disabled #360

Merged
merged 3 commits into from
Dec 5, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 9 additions & 4 deletions src/components/NumberInput/NumberInput-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,13 @@ describe('NumberInput', () => {
);

const input = wrapper.find('input');
const upArrow = wrapper.find('.up-icon');
const downArrow = wrapper.find('.down-icon');
const upArrow = wrapper.find('.up-icon').parent();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

target the element that has the actual event handler

const downArrow = wrapper.find('.down-icon').parent();

it('should be disabled when numberInput is disabled', () => {
expect(upArrow.prop('disabled')).toEqual(true);
expect(downArrow.prop('disabled')).toEqual(true);
});

it('should not invoke onClick when up arrow is clicked', () => {
upArrow.simulate('click');
Expand Down Expand Up @@ -187,8 +192,8 @@ describe('NumberInput', () => {
);

const input = wrapper.find('input');
const upArrow = wrapper.find('.up-icon').last();
const downArrow = wrapper.find('.down-icon').last();
const upArrow = wrapper.find('Icon.up-icon').closest('button');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this would use parent as well but there is a bug in enzyme with mount that I opened

const downArrow = wrapper.find('Icon.down-icon').closest('button');

it('should invoke onClick when numberInput is clicked', () => {
input.simulate('click');
Expand Down
10 changes: 8 additions & 2 deletions src/components/NumberInput/NumberInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ export default class NumberInput extends Component {
value: this.state.value,
};

const buttonProps = {
disabled,
type: 'button',
className: 'bx--number__control-btn',
};

return (
<div className="bx--form-item">
<label htmlFor={id} className="bx--label">
Expand All @@ -120,7 +126,7 @@ export default class NumberInput extends Component {
<input type="number" pattern="[0-9]*" {...other} {...props} />
<div className="bx--number__controls">
<button
className="bx--number__control-btn"
{...buttonProps}
onClick={evt => this.handleArrowClick(evt, 'up')}>
<Icon
className="up-icon"
Expand All @@ -130,7 +136,7 @@ export default class NumberInput extends Component {
/>
</button>
<button
className="bx--number__control-btn"
{...buttonProps}
onClick={evt => this.handleArrowClick(evt, 'down')}>
<Icon
className="down-icon"
Expand Down