From bf24091672c87a709b21275442b06cbeff9c3b6e Mon Sep 17 00:00:00 2001 From: "Rong Sen Ng (motss)" Date: Sun, 3 Apr 2022 19:08:09 +0800 Subject: [PATCH] fix: fix initial render issue, input closes on hidden day Signed-off-by: Rong Sen Ng (motss) --- src/__demo__/demo-app.ts | 42 +++++++++++++------ .../date-picker-input-surface.ts | 2 +- src/date-picker-input/date-picker-input.ts | 16 +++---- 3 files changed, 38 insertions(+), 22 deletions(-) diff --git a/src/__demo__/demo-app.ts b/src/__demo__/demo-app.ts index caa3b986..2f44e37f 100644 --- a/src/__demo__/demo-app.ts +++ b/src/__demo__/demo-app.ts @@ -17,6 +17,7 @@ import type { CustomEventDetail } from '../typings.js'; @customElement('demo-app') export class DemoApp extends RootElement { + @state() _editable = false; @state() _outlined = false; @queryAsync(appDatePickerDialogName) dialog!: Promise; @@ -83,7 +84,7 @@ export class DemoApp extends RootElement { > + { + this._outlined = !this._outlined; + + const el = this.query('#datePickerInputOutlined1'); + + if (el) { + /** + * NOTE(motss): Initial render with defined `outlined` and other properties will render + * everything correctly. However, updating any property that causes re-render will + * render the floating label incorrectly for unknown reasons. This is the workaround to + * always call `.layout()` manually and it cannot be done by the `DatePickerInput` + * internally. + */ + await el.updateComplete; + await el.layout(); + } + }} /> + - { - this._outlined = !this._outlined; - }} /> - - + + + diff --git a/src/date-picker-input-surface/date-picker-input-surface.ts b/src/date-picker-input-surface/date-picker-input-surface.ts index 0dcaba31..c49652a4 100644 --- a/src/date-picker-input-surface/date-picker-input-surface.ts +++ b/src/date-picker-input-surface/date-picker-input-surface.ts @@ -25,7 +25,7 @@ export class DatePickerInputSurface extends ElementMixin(MenuSurface) { (ev.composedPath() as HTMLElement[]) .filter(({ nodeType }) => nodeType === Node.ELEMENT_NODE); const shouldClose = - elements.some(n => n.classList.contains('calendar-day')) || + elements.some(n => n.classList.contains('calendar-day') && !n.hasAttribute('aria-hidden')) || !elements.some( n => alwaysOpenElementSet.has(n.localName as InferredFromSet) diff --git a/src/date-picker-input/date-picker-input.ts b/src/date-picker-input/date-picker-input.ts index ebbbd37d..0593b33c 100644 --- a/src/date-picker-input/date-picker-input.ts +++ b/src/date-picker-input/date-picker-input.ts @@ -108,6 +108,14 @@ export class DatePickerInput extends ElementMixin(DatePickerMixin(DatePickerMinM input.removeEventListener('click', onClick); }; } + + /** + * NOTE(motss): This is a workaround to ensure all inner dependencies of `TextField` + * will be updated accordingly and `.layout()` is called correctly. + */ + /* c8 ignore next */ + await this.outlineElement?.updateComplete; + await this.layout(); } public override willUpdate(changedProperties: ChangedProperties): void { @@ -136,14 +144,6 @@ export class DatePickerInput extends ElementMixin(DatePickerMixin(DatePickerMinM picker?.queryAll?.(appIconButtonName).forEach(n => n.layout()); } - - if (this.placeholder || this.label) { - /** - * NOTE(motss): This is a workaround to force the layout to update with any defined - * `placeholder` and/ or `label`. - */ - this.layout(); - } } public override render(): TemplateResult {