fix(datetime): ionChange is no longer called for out of range dates (#23940)

resolves #23939
This commit is contained in:
Liam DeBeasi
2021-09-16 10:44:20 -04:00
committed by GitHub
parent 23994e211a
commit ea39c6e5b3
2 changed files with 20 additions and 3 deletions

View File

@ -1091,6 +1091,17 @@ export class Datetime implements ComponentInterface {
const activeElement = this.el!.shadowRoot!.elementFromPoint(x, y)!; const activeElement = this.el!.shadowRoot!.elementFromPoint(x, y)!;
const value = parseInt(activeElement.getAttribute('data-value')!, 10); const value = parseInt(activeElement.getAttribute('data-value')!, 10);
/**
* When scrolling to a month that is out of
* bounds, the hour/minute column values may
* be updated, triggering a scroll callback.
* Check to make sure there is a valid
* hour/minute element so we do not emit NaN.
*/
if (Number.isNaN(value)) {
return;
}
if (colType === 'hour') { if (colType === 'hour') {
this.setWorkingParts({ this.setWorkingParts({
...this.workingParts, ...this.workingParts,

View File

@ -44,9 +44,8 @@
<h2>Value inside Bounds</h2> <h2>Value inside Bounds</h2>
<ion-datetime <ion-datetime
id="inside" id="inside"
min="2021-06-05" min="2021-09"
max="2021-06-29" max="2021-10"
value="2021-06-20"
></ion-datetime> ></ion-datetime>
</div> </div>
<div class="grid-item"> <div class="grid-item">
@ -60,6 +59,13 @@
</div> </div>
</div> </div>
</ion-content> </ion-content>
<script>
const datetime = document.querySelector('ion-datetime');
datetime.addEventListener('ionChange', (ev) => {
console.log('Change', ev.detail.value);
})
</script>
</ion-app> </ion-app>
</body> </body>
</html> </html>