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

feat(ui5-datetime-picker): improve keyboard handling support #2137

Merged
merged 2 commits into from
Aug 25, 2020
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
39 changes: 39 additions & 0 deletions packages/main/src/DateTimePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import getLocale from "@ui5/webcomponents-base/dist/locale/getLocale.js";
import LocaleData from "@ui5/webcomponents-localization/dist/LocaleData.js";
import CalendarDate from "@ui5/webcomponents-localization/dist/dates/CalendarDate.js";
import "@ui5/webcomponents-icons/dist/icons/date-time.js";
import {
isLeft,
isRight,
} from "@ui5/webcomponents-base/dist/Keys.js";
import Button from "./Button.js";
import ToggleButton from "./ToggleButton.js";
import SegmentedButton from "./SegmentedButton.js";
Expand Down Expand Up @@ -245,6 +249,7 @@ class DateTimePicker extends DatePicker {
await this.setSlidersValue();
this.expandHoursSlider();
this.storePreviousValue();
this._slidersDomRefs = await this.slidersDomRefs();
}

/**
Expand All @@ -265,6 +270,11 @@ class DateTimePicker extends DatePicker {
return super.isValid(value); // in order to be displayed in the DateTimePicker API reference
}

async slidersDomRefs() {
await this.getPicker();
return this.responsivePopover.getElementsByClassName("ui5-dt-wheel");
}

/**
* Read-only getters
*/
Expand Down Expand Up @@ -680,6 +690,35 @@ class DateTimePicker extends DatePicker {
}
}

async _ontimekeydown(event) {
if (isLeft(event)) {
let expandedSliderIndex = 0;
for (let i = 0; i < this._slidersDomRefs.length; i++) {
if (this._slidersDomRefs[i]._expanded) {
expandedSliderIndex = i;
}
}
if (this._slidersDomRefs[expandedSliderIndex - 1]) {
this._slidersDomRefs[expandedSliderIndex - 1].focus();
} else {
this._slidersDomRefs[this._slidersDomRefs.length - 1].focus();
}
} else if (isRight(event)) {
let expandedSliderIndex = 0;

for (let i = 0; i < this._slidersDomRefs.length; i++) {
if (this._slidersDomRefs[i]._expanded) {
expandedSliderIndex = i;
}
}
if (this._slidersDomRefs[expandedSliderIndex + 1]) {
this._slidersDomRefs[expandedSliderIndex + 1].focus();
} else {
this._slidersDomRefs[0].focus();
}
}
}

normalizeDigit(value) {
const valueAsString = value.toString();
return valueAsString.length === 1 ? `0${value}` : valueAsString;
Expand Down
2 changes: 1 addition & 1 deletion packages/main/src/DateTimePickerPopover.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<span class="ui5-dt-picker-separator"></span>
{{/unless}}

<div class="ui5-dt-time {{classes.dateTimeView}}">
<div class="ui5-dt-time {{classes.dateTimeView}}" @keydown="{{_ontimekeydown}}">
{{#if shouldBuildHoursSlider}}
<ui5-wheelslider
label = "{{hoursLabel}}"
Expand Down