diff --git a/packages/ui-date-time-input/src/DateTimeInput/__tests__/DateTimeInput.test.tsx b/packages/ui-date-time-input/src/DateTimeInput/__tests__/DateTimeInput.test.tsx
index 8c3e3cc469..3af9850cbe 100644
--- a/packages/ui-date-time-input/src/DateTimeInput/__tests__/DateTimeInput.test.tsx
+++ b/packages/ui-date-time-input/src/DateTimeInput/__tests__/DateTimeInput.test.tsx
@@ -850,6 +850,47 @@ describe('', async () => {
expect(timeInput).to.have.value(newDateTime.format('LT'))
})
+ it.only('should clear TimeSelect when DateInput is cleared', async () => {
+ const locale = 'en-US'
+ const timezone = 'US/Eastern'
+ const dateTime = DateTime.parse('2017-05-01T17:30Z', locale, timezone)
+
+ const subject = await mount(
+
+ )
+
+ const dateTimeInput = await DateTimeInputLocator.find()
+ const dateLocator = await dateTimeInput.findDateInput()
+ const timeLocator = await dateTimeInput.findTimeInput()
+ const dateInput = await dateLocator.findInput()
+ const timeInput = await timeLocator.findInput()
+ // 1. clear programmatically
+ await subject.setProps({ value: undefined })
+ expect(dateInput).to.have.value('')
+ expect(timeInput).to.have.value('')
+ // 2. clear via keyboard input
+ const newDateStr = '2022-03-29T19:00Z'
+ await subject.setProps({ value: newDateStr })
+ expect(dateInput).to.have.value('March 29, 2022')
+ expect(timeInput).to.have.value('3:00 PM')
+ await dateInput.change({ target: { value: '' } })
+ await dateInput.keyUp('escape')
+ await wait(() => {
+ expect(dateInput).to.have.value('')
+ expect(timeInput).to.have.value('')
+ })
+ })
+
it('should allow the user to enter any time value if allowNonStepInput is true', async () => {
const onChange = stub()
diff --git a/packages/ui-date-time-input/src/DateTimeInput/index.tsx b/packages/ui-date-time-input/src/DateTimeInput/index.tsx
index 3a97b9f73a..9d3342c0d5 100644
--- a/packages/ui-date-time-input/src/DateTimeInput/index.tsx
+++ b/packages/ui-date-time-input/src/DateTimeInput/index.tsx
@@ -171,12 +171,15 @@ class DateTimeInput extends Component {
}
}
}
+ // if there is no date string clear TimeSelect value
+ const clearTimeSelect = dateStr ? {} : { timeSelectValue: '' }
return {
iso: undefined,
calendarSelectedDate: undefined,
dateInputText: dateStr ? dateStr : '',
renderedDate: DateTime.now(this.locale(), this.timezone()),
- dateInputTextChanged: false
+ dateInputTextChanged: false,
+ ...clearTimeSelect
}
}
@@ -295,7 +298,7 @@ class DateTimeInput extends Component {
this.changeStateIfNeeded(newState, event)
}
- handleTimeChange = (
+ updateStateBasedOnTimeSelect = (
event: SyntheticEvent,
option: { value?: string; inputText: string }
) => {
@@ -566,7 +569,7 @@ class DateTimeInput extends Component {