-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(DateRangeInput3) Add keyboard accessibility (#7080)
- Loading branch information
Showing
4 changed files
with
454 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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
52 changes: 52 additions & 0 deletions
52
packages/datetime2/src/components/date-range-input3/dateRangeInputUilts.ts
This file contains 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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* ! | ||
* (c) Copyright 2024 Palantir Technologies Inc. All rights reserved. | ||
*/ | ||
|
||
const DAY_IN_MILLIS = 1000 * 60 * 60 * 24; | ||
const WEEK_IN_MILLIS = 7 * DAY_IN_MILLIS; | ||
|
||
export function getTodayAtMidnight() { | ||
return new Date(new Date().setHours(0, 0, 0, 0)); | ||
} | ||
|
||
export function shiftDateByDays(date: Date, days: number): Date { | ||
return new Date(date.valueOf() + days * DAY_IN_MILLIS); | ||
} | ||
|
||
export function shiftDateByWeeks(date: Date, weeks: number): Date { | ||
return new Date(date.valueOf() + weeks * WEEK_IN_MILLIS); | ||
} | ||
|
||
export function shiftDateByArrowKey(date: Date, key: string): Date { | ||
switch (key) { | ||
case "ArrowUp": | ||
return shiftDateByWeeks(date, -1); | ||
case "ArrowDown": | ||
return shiftDateByWeeks(date, 1); | ||
case "ArrowLeft": | ||
return shiftDateByDays(date, -1); | ||
case "ArrowRight": | ||
return shiftDateByDays(date, 1); | ||
default: | ||
return date; | ||
} | ||
} | ||
|
||
export function clampDate(date: Date, minDate: Date | null | undefined, maxDate: Date | null | undefined) { | ||
let result = date; | ||
if (minDate != null && date < minDate) { | ||
result = minDate; | ||
} | ||
if (maxDate != null && date > maxDate) { | ||
result = maxDate; | ||
} | ||
return result; | ||
} | ||
|
||
export function isEntireInputSelected(element: HTMLInputElement | null) { | ||
if (element == null) { | ||
return false; | ||
} | ||
|
||
return element.selectionStart === 0 && element.selectionEnd === element.value.length; | ||
} |
This file contains 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
Oops, something went wrong.
dc7c104
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
feat(DateRangeInput3) Add keyboard accessibility (#7080)
Build artifact links for this commit: documentation | landing | table | demoThis is an automated comment from the deploy-preview CircleCI job.