Skip to content

Commit

Permalink
Merge pull request #636 from Adslot/alert-input-onfocus-prop
Browse files Browse the repository at this point in the history
New: AlertInput onFocus prop addition
  • Loading branch information
mdotwills authored Oct 18, 2017
2 parents 1fd0ae2 + 7580eb1 commit a7a2977
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
3 changes: 3 additions & 0 deletions docs/examples/AlertInputExample.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ const exampleProps = {
}, {
propType: 'onBlur',
type: 'func',
}, {
propType: 'onFocus',
type: 'func',
}, {
propType: 'type',
type: "oneOf: 'text', 'number'",
Expand Down
5 changes: 5 additions & 0 deletions src/components/adslot-ui/AlertInput/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ export default class AlertInput extends Component {
isFocused: true,
isPopoverVisible: Boolean(this.props.alertMessage),
});

if (this.props.onFocus) {
this.props.onFocus(event);
}
}

handleInputBlur(event) {
Expand Down Expand Up @@ -127,6 +131,7 @@ AlertInput.propTypes = {
alertMessage: PropTypes.string,
onValueChange: PropTypes.func,
onBlur: PropTypes.func,
onFocus: PropTypes.func,
};

AlertInput.defaultProps = {
Expand Down
20 changes: 20 additions & 0 deletions src/components/adslot-ui/AlertInput/index.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,26 @@ describe('AlertInput', () => {
});
expect(focusEvent.target.select.callCount).to.equal(1);
});

it('should call prop `onFocus` if exists', () => {
const onFocusSpy = sinon.spy();
const focusEvent = {
target: {
select: sinon.spy(),
},
};
const component = shallow(<AlertInput onFocus={onFocusSpy} />);
const inputElement = component.find('.alert-input-component-input');

inputElement.simulate('focus', focusEvent);

expect(component.state()).to.eql({
isFocused: true,
isPopoverVisible: false,
});
expect(focusEvent.target.select.callCount).to.equal(1);
expect(onFocusSpy.callCount).to.equal(1);
});
});

describe('handleInputBlur ()', () => {
Expand Down

0 comments on commit a7a2977

Please sign in to comment.