Skip to content

Commit

Permalink
close AM/PM element (#1663)
Browse files Browse the repository at this point in the history
  • Loading branch information
Anyrob committed Jun 28, 2020
1 parent a9f0fe8 commit 5ea877d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
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;

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

0 comments on commit 5ea877d

Please sign in to comment.