From 7b7e05aa697a51ebfac42f96aa9510d4d96336de Mon Sep 17 00:00:00 2001 From: Liam DeBeasi Date: Fri, 12 May 2023 11:15:50 -0400 Subject: [PATCH] fix(datetime-button): log error if non-datetime instance is passed (#27456) Issue number: N/A --------- ## What is the current behavior? An issue was filed in https://github.com/ionic-team/ionic-framework/issues/27452 where the `presentation` property was not being respected. The problem ended up being that the ID passed to `ion-datetime-button` was not associated with an `ion-datetime` instance, so it did not pick up on the `presentation` property. I think we can handle this better by logging an error if the ID passed does not belong to an `ion-datetime`. ## What is the new behavior? - Log an error if the ID passed to `ion-datetime-button` exists but does not belong to an `ion-datetime` instance. ## Does this introduce a breaking change? - [ ] Yes - [x] No ## Other information --- .../components/datetime-button/datetime-button.tsx | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/core/src/components/datetime-button/datetime-button.tsx b/core/src/components/datetime-button/datetime-button.tsx index c42fa0edd0..68b4a7ddf0 100644 --- a/core/src/components/datetime-button/datetime-button.tsx +++ b/core/src/components/datetime-button/datetime-button.tsx @@ -75,6 +75,18 @@ export class DatetimeButton implements ComponentInterface { return; } + /** + * The element reference must be an ion-datetime. Print an error + * if a non-datetime element was provided. + */ + if (datetimeEl.tagName !== 'ION-DATETIME') { + printIonError( + `Expected an ion-datetime instance for ID '${datetime}' but received '${datetimeEl.tagName.toLowerCase()}' instead.`, + datetimeEl + ); + return; + } + /** * Since the datetime can be used in any context (overlays, accordion, etc) * we track when it is visible to determine when it is active.