Skip to content

Commit

Permalink
Fix Clock opening behind AM/PM dropdown
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtekmaj committed Sep 27, 2021
1 parent 81e227b commit f9081c8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/TimeInput/AmPm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export default function AmPm({
`${className}__${name}`,
)}
data-input="true"
data-select="true"
disabled={disabled}
name={name}
onChange={onChange}
Expand Down
4 changes: 4 additions & 0 deletions src/TimePicker.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ export default class TimePicker extends PureComponent {
}

if (openClockOnFocus) {
if (event.target.getAttribute('data-select') === 'true') {
return;
}

this.openClock();
}
}
Expand Down
18 changes: 18 additions & 0 deletions src/TimePicker.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,24 @@ describe('TimePicker', () => {

expect(clock2).toHaveLength(0);
});

it('does not open Clock component when focusing on a select element', () => {
const component = mount(
<TimePicker format="hh:mm:ss a" />,
);

const clock = component.find('Clock');
const select = component.find('select[name="amPm"]');

expect(clock).toHaveLength(0);

select.simulate('focus');
component.update();

const clock2 = component.find('Clock');

expect(clock2).toHaveLength(0);
});
});

it('closes Clock component when clicked outside', () => {
Expand Down

0 comments on commit f9081c8

Please sign in to comment.