Skip to content

Commit 6d6a3bd

Browse files
committed
more docs
1 parent 25fff00 commit 6d6a3bd

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

src/material/datepicker/calendar-body.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,10 @@ export class MatCalendarBody<D = any> implements OnChanges, OnDestroy, AfterView
455455
}
456456
};
457457

458+
/**
459+
* Triggered on mousedown or touchstart on a date cell.
460+
* Respsonsible for starting a drag sequence.
461+
*/
458462
private _mousedownHandler = (event: Event) => {
459463
this._didDragSinceMouseDown = false;
460464
// Begin a drag if a cell within the current range was targeted.
@@ -471,6 +475,7 @@ export class MatCalendarBody<D = any> implements OnChanges, OnDestroy, AfterView
471475
});
472476
};
473477

478+
/** Triggered on mouseup anywhere. Respsonsible for ending a drag sequence. */
474479
private _mouseupHandler = (event: Event) => {
475480
const cellElement = getCellElement(event.target as HTMLElement);
476481
if (!cellElement) {
@@ -493,6 +498,7 @@ export class MatCalendarBody<D = any> implements OnChanges, OnDestroy, AfterView
493498
});
494499
};
495500

501+
/** Triggered on touchend anywhere. Respsonsible for ending a drag sequence. */
496502
private _touchendHandler = (event: TouchEvent) => {
497503
const target = getActualTouchTarget(event);
498504

@@ -529,6 +535,10 @@ function isTableCell(node: Node | undefined | null): node is HTMLTableCellElemen
529535
return node?.nodeName === 'TD';
530536
}
531537

538+
/**
539+
* Gets the date table cell element that is or contains the specified element.
540+
* Or returns null if element is not part of a date cell.
541+
*/
532542
function getCellElement(element: HTMLElement): HTMLElement | null {
533543
let cell: HTMLElement | undefined;
534544
if (isTableCell(element)) {
@@ -569,6 +579,10 @@ function isInRange(
569579
);
570580
}
571581

582+
/**
583+
* Extracts the element that actually corresponds to a touch event's location
584+
* (rather than the element that initiated the sequence of touch events).
585+
*/
572586
function getActualTouchTarget(event: TouchEvent): Element | null {
573587
const touchLocation = event.changedTouches[0];
574588
return document.elementFromPoint(touchLocation.clientX, touchLocation.clientY);

src/material/datepicker/calendar.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,10 +504,15 @@ export class MatCalendar<D> implements AfterContentInit, AfterViewChecked, OnDes
504504
this.currentView = view;
505505
}
506506

507+
/** Called when the user starts dragging to change a date range. */
507508
_dragStarted(event: MatCalendarUserEvent<D>) {
508509
this._activeDrag = event;
509510
}
510511

512+
/**
513+
* Called when a drag completes. It may end in cancelation or in the selection
514+
* of a new range.
515+
*/
511516
_dragEnded(event: MatCalendarUserEvent<DateRange<D> | null>) {
512517
if (!this._activeDrag) return;
513518

src/material/datepicker/month-view.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,13 @@ export class MatMonthView<D> implements AfterContentInit, OnChanges, OnDestroy {
161161
@Output() readonly _userSelection: EventEmitter<MatCalendarUserEvent<D | null>> =
162162
new EventEmitter<MatCalendarUserEvent<D | null>>();
163163

164+
/** Emits when the user initiates a date range drag via mouse or touch. */
164165
@Output() readonly dragStarted = new EventEmitter<MatCalendarUserEvent<D>>();
165166

167+
/**
168+
* Emits when the user completes or cancels a date range drag.
169+
* Emits null when the drag was canceled or the newly selected date range if completed.
170+
*/
166171
@Output() readonly dragEnded = new EventEmitter<MatCalendarUserEvent<DateRange<D> | null>>();
167172

168173
/** Emits when any date is activated. */
@@ -461,6 +466,10 @@ export class MatMonthView<D> implements AfterContentInit, OnChanges, OnDestroy {
461466
}
462467
}
463468

469+
/**
470+
* Called when the user has ended a drag. If the drag/drop was successful,
471+
* computes and emits the new range selection.
472+
*/
464473
protected _dragEnded(event: MatCalendarUserEvent<D | null>) {
465474
if (!this._activeDrag) return;
466475

@@ -606,6 +615,7 @@ export class MatMonthView<D> implements AfterContentInit, OnChanges, OnDestroy {
606615
return !this.dateFilter || this.dateFilter(date);
607616
}
608617

618+
/** Clears out preview state. */
609619
private _clearPreview() {
610620
this._previewStart = this._previewEnd = null;
611621
}

0 commit comments

Comments
 (0)