Skip to content

Commit 1017d44

Browse files
committed
refactor(DatePicker, DateRangePicker, TimePicker): improve accessibility
1 parent 9ba0e5a commit 1017d44

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

js/src/date-range-picker.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const DATA_KEY = 'coreui.date-range-picker'
2424
const EVENT_KEY = `.${DATA_KEY}`
2525
const DATA_API_KEY = '.data-api'
2626

27+
const ENTER_KEY = 'Enter'
2728
const ESCAPE_KEY = 'Escape'
2829
const TAB_KEY = 'Tab'
2930
const RIGHT_MOUSE_BUTTON = 2
@@ -184,8 +185,8 @@ class DateRangePicker extends BaseComponent {
184185
this._calendarDate = this._config.calendarDate
185186
this._startDate = this._config.date || this._config.startDate
186187
this._endDate = this._config.endDate
187-
this._initialStartDate = new Date(this._startDate)
188-
this._initialEndDate = new Date(this._endDate)
188+
this._initialStartDate = null
189+
this._initialEndDate = null
189190
this._mobile = window.innerWidth < 768
190191
this._popper = null
191192
this._selectEndDate = this._config.selectEndDate
@@ -230,6 +231,9 @@ class DateRangePicker extends BaseComponent {
230231
return
231232
}
232233

234+
this._initialStartDate = new Date(this._startDate)
235+
this._initialEndDate = new Date(this._endDate)
236+
233237
EventHandler.trigger(this._element, EVENT_SHOW)
234238
this._element.classList.add(CLASS_NAME_SHOW)
235239
this._element.setAttribute('aria-expanded', true)
@@ -314,8 +318,8 @@ class DateRangePicker extends BaseComponent {
314318
}
315319
})
316320

317-
EventHandler.on(this._indicatorElement, EVENT_KEYDOWN, () => {
318-
if (!this._config.disabled) {
321+
EventHandler.on(this._indicatorElement, EVENT_KEYDOWN, event => {
322+
if (!this._config.disabled && event.key === ENTER_KEY) {
319323
this.toggle()
320324
}
321325
})

js/src/time-picker.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ class TimePicker extends BaseComponent {
135135

136136
this._config = this._getConfig(config)
137137
this._date = this._convertStringToDate(this._config.time)
138-
this._initialDate = new Date(this._date)
138+
this._initialDate = null
139139
this._ampm = this._date ?
140140
getAmPm(new Date(this._date), this._config.locale) :
141141
'am'
@@ -183,6 +183,8 @@ class TimePicker extends BaseComponent {
183183
return
184184
}
185185

186+
this._initialDate = new Date(this._date)
187+
186188
EventHandler.trigger(this._element, EVENT_SHOW)
187189
this._element.classList.add(CLASS_NAME_SHOW)
188190
this._element.setAttribute('aria-expanded', true)
@@ -264,8 +266,8 @@ class TimePicker extends BaseComponent {
264266
}
265267
})
266268

267-
EventHandler.on(this._indicatorElement, EVENT_KEYDOWN, () => {
268-
if (!this._config.disabled) {
269+
EventHandler.on(this._indicatorElement, EVENT_KEYDOWN, event => {
270+
if (!this._config.disabled && event.key === ENTER_KEY) {
269271
this.toggle()
270272
}
271273
})

0 commit comments

Comments
 (0)