@@ -333,32 +333,40 @@ export class Datetime implements ComponentInterface {
333
333
* This allows us to update the current value's date/time display without
334
334
* refocusing or shifting the user's display (leaves the user in place).
335
335
*/
336
- // TODO: most of this will need a decent restructure
337
336
const valueDateParts = parseDate ( this . value ) ;
338
337
if ( valueDateParts ) {
339
338
warnIfValueOutOfBounds ( valueDateParts , this . minParts , this . maxParts ) ;
340
339
341
- const { month, day, year, hour, minute } = valueDateParts ;
342
- const ampm = hour >= 12 ? 'pm' : 'am' ;
343
-
344
- this . activePartsClone = {
345
- ...this . activeParts ,
346
- month,
347
- day,
348
- year,
349
- hour,
350
- minute,
351
- ampm,
352
- } ;
340
+ if ( Array . isArray ( valueDateParts ) ) {
341
+ this . activePartsClone = [ ...valueDateParts ] ;
342
+ } else {
343
+ const { month, day, year, hour, minute } = valueDateParts ;
344
+ const ampm = hour ?
345
+ hour >= 12 ? 'pm' : 'am'
346
+ : undefined ;
347
+
348
+ this . activePartsClone = {
349
+ ...this . activeParts ,
350
+ month,
351
+ day,
352
+ year,
353
+ hour,
354
+ minute,
355
+ ampm,
356
+ } ;
353
357
354
- /**
355
- * The working parts am/pm value must be updated when the value changes, to
356
- * ensure the time picker hour column values are generated correctly.
357
- */
358
- this . setWorkingParts ( {
359
- ...this . workingParts ,
360
- ampm,
361
- } ) ;
358
+ /**
359
+ * The working parts am/pm value must be updated when the value changes, to
360
+ * ensure the time picker hour column values are generated correctly.
361
+ *
362
+ * Note that we don't need to do this if valueDateParts is an array, since
363
+ * multiple="true" does not apply to time pickers.
364
+ */
365
+ this . setWorkingParts ( {
366
+ ...this . workingParts ,
367
+ ampm,
368
+ } ) ;
369
+ }
362
370
} else {
363
371
printIonWarning ( `Unable to parse date string: ${ this . value } . Please provide a valid ISO 8601 datetime string.` ) ;
364
372
}
@@ -551,10 +559,19 @@ export class Datetime implements ComponentInterface {
551
559
} ;
552
560
553
561
private setActiveParts = ( parts : DatetimeParts , removeDate = false ) => {
554
- const { multiple, activeParts , highlightActiveParts } = this ;
562
+ const { multiple, activePartsClone , highlightActiveParts } = this ;
555
563
556
564
if ( multiple ) {
557
- const activePartsArray = Array . isArray ( activeParts ) ? activeParts : [ activeParts ] ;
565
+ /**
566
+ * We read from activePartsClone here because valueChanged() only updates that,
567
+ * so it's the more reliable source of truth. If we read from activeParts, then
568
+ * if you click July 1, manually set the value to July 2, and then click July 3,
569
+ * the new value would be [July 1, July 3], ignoring the value set.
570
+ *
571
+ * We can then pass the new value to activeParts (rather than activePartsClone)
572
+ * since the clone will be updated automatically by activePartsChanged().
573
+ */
574
+ const activePartsArray = Array . isArray ( activePartsClone ) ? activePartsClone : [ activePartsClone ] ;
558
575
if ( removeDate ) {
559
576
this . activeParts = activePartsArray . filter ( p => ! isSameDay ( p , parts ) ) ;
560
577
} else if ( highlightActiveParts ) {
0 commit comments