-
Notifications
You must be signed in to change notification settings - Fork 275
feat(ui5-daterange-picker): keyboard handling improvement #2179
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
507d9a4
fix(ui5-daterange-picker): keyboard handling improvement
unazko d830138
feat(ui5-daterange-picker): documentation added for keyboard handling
unazko f470914
Merge branch 'master' of https://github.com/unazko/ui5-webcomponents …
unazko 2af45ff
feat(ui5-daterange-picker): documentation added for keyboard handling
unazko 8f8291c
Merge branch 'master' of https://github.com/unazko/ui5-webcomponents …
unazko dc96cde
JS documentation is now accurate and helper function,
unazko b133650
Merge branch 'master' of https://github.com/unazko/ui5-webcomponents …
unazko b2c777f
Merge branch 'master' of https://github.com/unazko/ui5-webcomponents …
unazko 3ac69b2
Merge branch 'master' of https://github.com/unazko/ui5-webcomponents …
unazko 8e5eec9
fix(ui5-daterange-picker): keyboard handling improvement
unazko bfdfdf2
feat(ui5-daterange-picker): keyboard handling improvement
unazko 064c017
Merge branch 'master' of https://github.com/unazko/ui5-webcomponents …
unazko 05e9c79
Merge branch 'master' of https://github.com/unazko/ui5-webcomponents …
unazko c0df5ef
fix(ui5-daterange-picker): keyboard handling improvement
unazko db3da35
feat(ui5-daterange-picker): keyboard handling improvement
unazko 29d0021
Merge branch 'master' of https://github.com/unazko/ui5-webcomponents …
unazko be5b7ff
feat(ui5-daterange-picker): keyboard handling improvement
unazko 5980803
Merge branch 'master' of https://github.com/unazko/ui5-webcomponents …
unazko f813c41
Merge branch 'master' of https://github.com/unazko/ui5-webcomponents …
unazko 366545d
Merge branch 'master' of https://github.com/unazko/ui5-webcomponents …
unazko c8bb02f
Unnecessary calls to the CalendarDate instances are now removed.
unazko ed2f49c
CalendarDate intances created with "CalendarDate.fromTimestamp" method
unazko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ import Integer from "@ui5/webcomponents-base/dist/types/Integer.js"; | |
import ValueState from "@ui5/webcomponents-base/dist/types/ValueState.js"; | ||
import CalendarDate from "@ui5/webcomponents-localization/dist/dates/CalendarDate.js"; | ||
import DateRangePickerTemplate from "./generated/templates/DateRangePickerTemplate.lit.js"; | ||
import RenderScheduler from "../../base/src/RenderScheduler.js"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This breaks several builds, please use the "@ui5/webcomponents-base/dist/RenderScheduler.js" form There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will for the future. Thanks. |
||
|
||
// Styles | ||
import DateRangePickerCss from "./generated/themes/DateRangePicker.css.js"; | ||
|
@@ -63,6 +64,25 @@ const metadata = { | |
* <h3>ES6 Module Import</h3> | ||
* | ||
* <code>import @ui5/webcomponents/dist/DateRangePicker.js";</code> | ||
* | ||
* <h3>Keyboard Handling</h3> | ||
* The <code>ui5-daterange-picker</code> provides advanced keyboard handling. | ||
* <br> | ||
* | ||
* When the <code>ui5-daterange-picker</code> input field is focused the user can | ||
* increment or decrement the corresponding field of the JS date object referenced by <code>_firstDateTimestamp</code> propery | ||
* if the caret symbol is before the delimiter character or <code>_lastDateTimestamp</code> property if the caret symbol is | ||
* after the delimiter character. | ||
* The following shortcuts are enabled: | ||
* <br> | ||
* <ul> | ||
* <li>[PAGEDOWN] - Decrements the corresponding day of the month by one</li> | ||
* <li>[SHIFT] + [PAGEDOWN] - Decrements the corresponding month by one</li> | ||
* <li>[SHIFT] + [CTRL] + [PAGEDOWN] - Decrements the corresponding year by one</li> | ||
* <li>[PAGEUP] - Increments the corresponding day of the month by one</li> | ||
* <li>[SHIFT] + [PAGEUP] - Increments the corresponding month by one</li> | ||
* <li>[SHIFT] + [CTRL] + [PAGEUP] - Increments the corresponding year by one</li> | ||
* </ul> | ||
* | ||
* @constructor | ||
* @author SAP SE | ||
|
@@ -368,6 +388,95 @@ class DateRangePicker extends DatePicker { | |
} | ||
} | ||
|
||
/** | ||
* Adds or extracts a given number of measuring units from the "dateValue" property value | ||
* | ||
* @param {boolean} years indicates that the measuring unit is in years | ||
* @param {boolean} months indicates that the measuring unit is in months | ||
* @param {boolean} days indicates that the measuring unit is in days | ||
* @param {boolean} forward if true indicates addition | ||
unazko marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* @param {int} step number of measuring units to substract or add defaults ot 1 | ||
*/ | ||
async _changeDateValueWrapper(forward, years, months, days, step = 1) { | ||
const emptyValue = this.value === ""; | ||
const isValid = emptyValue || this._checkValueValidity(this.value); | ||
|
||
if (!isValid) { | ||
return; | ||
} | ||
|
||
const dates = this._splitValueByDelimiter(this.value); | ||
const innerInput = this.shadowRoot.querySelector("ui5-input").shadowRoot.querySelector(".ui5-input-inner"); | ||
const caretPos = this._getCaretPosition(innerInput); | ||
const first = dates[0] && caretPos <= dates[0].trim().length + 1; | ||
const last = dates[1] && (caretPos >= this.value.length - dates[1].trim().length - 1 && caretPos <= this.value.length); | ||
let firstDate = this.getFormat().parse(dates[0]); | ||
let lastDate = this.getFormat().parse(dates[1]); | ||
|
||
if (first && firstDate) { | ||
firstDate = this._changeDateValue(firstDate, forward, years, months, days, step); | ||
} else if (last && lastDate) { | ||
lastDate = this._changeDateValue(lastDate, forward, years, months, days, step); | ||
} | ||
|
||
if (firstDate > lastDate) { | ||
const temp = firstDate; | ||
firstDate = lastDate; | ||
lastDate = temp; | ||
} | ||
|
||
const newValue = this._formatValue(firstDate.valueOf() / 1000, lastDate.valueOf() / 1000); | ||
|
||
this._setValue(newValue); | ||
await RenderScheduler.whenFinished(); | ||
|
||
// Return the carent on the previous position after rendering | ||
this._setCaretPosition(innerInput, caretPos); | ||
|
||
this.fireEvent("change", { value: newValue, valid: isValid }); | ||
} | ||
|
||
/** | ||
* Returns the caret (cursor) position of the specified text field (field). | ||
* Return value range is 0-field.value.length. | ||
*/ | ||
_getCaretPosition(field) { | ||
// Initialize | ||
let caretPos = 0; | ||
|
||
// IE Support | ||
if (document.selection) { | ||
// Set focus on the element | ||
field.focus(); | ||
|
||
// To get cursor position, get empty selection range | ||
const selection = document.selection.createRange(); | ||
|
||
// Move selection start to 0 position | ||
selection.moveStart("character", -field.value.length); | ||
|
||
// The caret position is selection length | ||
caretPos = selection.text.length; | ||
} else if (field.selectionStart || field.selectionStart === "0") { // Firefox support | ||
caretPos = field.selectionDirection === "backward" ? field.selectionStart : field.selectionEnd; | ||
} | ||
|
||
return caretPos; | ||
} | ||
|
||
_setCaretPosition(field, caretPos) { | ||
if (field.createTextRange) { | ||
const range = field.createTextRange(); | ||
range.move("character", caretPos); | ||
range.select(); | ||
} else if (field.selectionStart) { | ||
field.focus(); | ||
field.setSelectionRange(caretPos, caretPos); | ||
} else { | ||
field.focus(); | ||
} | ||
} | ||
|
||
_handleCalendarSelectedDatesChange() { | ||
this._updateValueCalendarSelectedDatesChange(); | ||
this._cleanHoveredAttributeFromVisibleItems(); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.