mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
fix(datetime): add dev warnings when setting out of bounds value (#25513)
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import { printIonWarning } from '@utils/logging';
|
||||
|
||||
import type { DatetimeParts } from '../datetime-interface';
|
||||
|
||||
/**
|
||||
@@ -36,3 +38,14 @@ export const isAfter = (baseParts: DatetimeParts, compareParts: DatetimeParts) =
|
||||
baseParts.day > compareParts.day!)
|
||||
);
|
||||
};
|
||||
|
||||
export const warnIfValueOutOfBounds = (value: DatetimeParts, min: DatetimeParts, max: DatetimeParts) => {
|
||||
if ((min && isBefore(value, min)) || (max && isAfter(value, max))) {
|
||||
printIonWarning(
|
||||
'The value provided to ion-datetime is out of bounds.\n\n' +
|
||||
`Min: ${JSON.stringify(min)}\n` +
|
||||
`Max: ${JSON.stringify(max)}\n` +
|
||||
`Value: ${JSON.stringify(value)}`
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user