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

New: AlertInput onFocus prop addition #636

Merged
merged 1 commit into from
Oct 18, 2017
Merged
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
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);
Copy link
Contributor

Choose a reason for hiding this comment

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

probably just default to _.noop so you don't have to make this check

Copy link
Contributor

Choose a reason for hiding this comment

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

I disagree, I think this check is valid and preferable to a noop for consistency with other types and for providing explicitness with the optional parameters.

}
}

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