Skip to content

Commit

Permalink
feat(DateField): improve month segment behavior for invalid months st…
Browse files Browse the repository at this point in the history
…arting with 1

When typing invalid months starting with 1 (13-19):
- Keeps 1 as the month value
- Automatically uses the second digit as the initial value for the day segment

For example, when typing "13":
- "1" remains as the month
- Moves to day segment
- "3" becomes the initial value of the day
  • Loading branch information
acabreragnz committed Jan 16, 2025
1 parent 121e305 commit ad0ee78
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions packages/core/src/shared/date/useDateField.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,14 @@ export function useDateField(props: UseDateFieldProps) {
*/

if (digits === 2 || total > max) {

if (prev === 1 && total > 12) {
return {
moveToNext: true,
value: 1,
}
}

/**
* As we're doing elsewhere, we're checking if the number is greater
* than the max start digit (0-3 in most months), and if so, we're
Expand Down Expand Up @@ -645,9 +653,13 @@ export function useDateField(props: UseDateFieldProps) {

if (isNumberString(e.key)) {
const num = Number.parseInt(e.key)
const { value, moveToNext } = updateDayOrMonth(12, num, prevValue)
const { value, moveToNext, nextSegmentInitialValue } = updateDayOrMonth(12, num, prevValue)

props.segmentValues.value.month = value

if (nextSegmentInitialValue) {
props.segmentValues.value.day = nextSegmentInitialValue
}

if (moveToNext)
props.focusNext()
Expand Down Expand Up @@ -825,7 +837,7 @@ export function useDateField(props: UseDateFieldProps) {
return
const segmentKeydownHandlers = {
day: handleDaySegmentKeydown,
month: handleMonthSegmentKeydown,
month: SegmentKeydown,
year: handleYearSegmentKeydown,
hour: handleHourSegmentKeydown,
minute: handleMinuteSegmentKeydown,
Expand Down

0 comments on commit ad0ee78

Please sign in to comment.