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: close AM / PM element by selecting #1663

Merged
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
6 changes: 6 additions & 0 deletions src/components/TimePicker/__test__/ampmSelect.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ describe('<AmPmSelect/>', () => {
const fieldsetDataId = component.find('input').prop('aria-label');
expect(focusedElementAriaLabel).toBe(fieldsetDataId);
});
it('should call onClick when input option "AM" or "PM" is clicked', () => {
const onClickMockFn = jest.fn();
const component = mount(<AmPmSelect isFocused onClick={onClickMockFn} />);
component.find('input[value="AM"]').simulate('click');
expect(onClickMockFn).toHaveBeenCalledTimes(1);
});
it('should call event.stopPropagation when component is focused and the input with value "AM" is blurred', () => {
const stopPropagationMockFn = jest.fn();
const component = mount(<AmPmSelect isFocused />);
Expand Down
7 changes: 5 additions & 2 deletions src/components/TimePicker/ampmSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ export default class AmPmSelect extends PureComponent {
}

render() {
const { isFocused } = this.props;
const { tabIndex, onFocus, value } = this.props;
const { isFocused, tabIndex, onFocus, value, onClick } = this.props;

Choose a reason for hiding this comment

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

good job!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you (: 💯


if (isFocused) {
return (
Expand All @@ -71,6 +70,7 @@ export default class AmPmSelect extends PureComponent {
value="AM"
checked={this.isInputChecked('AM')}
onChange={this.handleOnChange}
onClick={onClick}
onBlur={handleAmPmBlur}
/>

Expand All @@ -83,6 +83,7 @@ export default class AmPmSelect extends PureComponent {
value="PM"
checked={this.isInputChecked('PM')}
onChange={this.handleOnChange}
onClick={onClick}
onBlur={handleAmPmBlur}
/>

Expand All @@ -107,6 +108,7 @@ AmPmSelect.propTypes = {
value: PropTypes.string,
defaultValue: PropTypes.string,
onChange: PropTypes.func,
onClick: PropTypes.func,
onFocus: PropTypes.func,
tabIndex: PropTypes.string,
isFocused: PropTypes.bool,
Expand All @@ -115,6 +117,7 @@ AmPmSelect.propTypes = {
AmPmSelect.defaultProps = {
value: undefined,
defaultValue: undefined,
onClick: () => {},
onChange: () => {},
onFocus: () => {},
tabIndex: undefined,
Expand Down
9 changes: 8 additions & 1 deletion src/components/TimePicker/timeSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export default class TimeSelect extends Component {
this.handleBlurHour = this.handleBlurHour.bind(this);
this.handleChangeMinutes = this.handleChangeMinutes.bind(this);
this.handleFocusMinutes = this.handleFocusMinutes.bind(this);
this.handleClickAmPm = this.handleClickAmPm.bind(this);
this.handleAmPmChange = this.handleAmPmChange.bind(this);
this.hanldeFocusAmPm = this.hanldeFocusAmPm.bind(this);
this.handleKeyDown = this.handleKeyDown.bind(this);
Expand Down Expand Up @@ -205,11 +206,16 @@ export default class TimeSelect extends Component {

handleAmPmChange(value) {
this.setState({
inputFocusedIndex: -1,
ampm: value,
});
}

handleClickAmPm() {
this.setState({
inputFocusedIndex: -1,
});
}

hanldeFocusAmPm() {
this.setState({ inputFocusedIndex: 2 });
}
Expand Down Expand Up @@ -438,6 +444,7 @@ export default class TimeSelect extends Component {
value={ampm}
defaultValue={this.defaultAmPM}
onFocus={this.hanldeFocusAmPm}
onClick={this.handleClickAmPm}
onChange={this.handleAmPmChange}
isFocused={inputFocusedIndex === 2}
ref={this.amPmInputRef}
Expand Down