diff --git a/projects/ui/src/lib/components/po-field/po-datepicker/po-datepicker-base.component.ts b/projects/ui/src/lib/components/po-field/po-datepicker/po-datepicker-base.component.ts index 9b0d2508b7..692829370f 100644 --- a/projects/ui/src/lib/components/po-field/po-datepicker/po-datepicker-base.component.ts +++ b/projects/ui/src/lib/components/po-field/po-datepicker/po-datepicker-base.component.ts @@ -386,6 +386,21 @@ export abstract class PoDatepickerBaseComponent implements ControlValueAccessor, return this._locale || this.shortLanguage; } + /** + * @optional + * + * @description + * + * Define que o calendário do DatePicker será incluído no body da página, em vez de suspenso junto ao campo de entrada do componente. + * Essa opção é útil em cenários onde o DatePicker precisa ser renderizado fora do conteúdo principal da página, + * como em formulários que utilizam scroll ou containers com overflow escondido. + * + * > Obs: O uso dessa propriedade pode interferir na sequência de tabulação da página, especialmente em formulários longos. + * + * @default `false` + */ + @Input({ alias: 'p-append-in-body', transform: convertToBoolean }) appendBox: boolean = false; + constructor(protected languageService: PoLanguageService) {} set date(value: any) { diff --git a/projects/ui/src/lib/components/po-field/po-datepicker/po-datepicker.component.html b/projects/ui/src/lib/components/po-field/po-datepicker/po-datepicker.component.html index 49cfd9e195..1b2cc39825 100644 --- a/projects/ui/src/lib/components/po-field/po-datepicker/po-datepicker.component.html +++ b/projects/ui/src/lib/components/po-field/po-datepicker/po-datepicker.component.html @@ -6,57 +6,76 @@ [p-required]="required" [p-show-required]="showRequired" > -
-
- -
- - +
+ - - -
-
-
- - + + + +
+
+ +
+
+ + + + + + + + + +
{ }); it(`setCalendarPosition: should call 'controlPosition.setElements' and 'controlPosition.adjustPosition'.`, () => { + component.dialogPicker = { + nativeElement: document.createElement('div') + }; + const setDialogPickerStyleDisplay = spyOn(component, 'setDialogPickerStyleDisplay'); const setElements = spyOn(component['controlPosition'], 'setElements'); const adjustPosition = spyOn(component['controlPosition'], 'adjustPosition'); @@ -958,6 +962,10 @@ describe('PoDatepickerComponent:', () => { }); it('setDialogPickerStyleDisplay: should change style display.', () => { + component.dialogPicker = { + nativeElement: document.createElement('div') + }; + component['setDialogPickerStyleDisplay']('none'); expect(component.dialogPicker.nativeElement.style.display).toBe('none'); diff --git a/projects/ui/src/lib/components/po-field/po-datepicker/po-datepicker.component.ts b/projects/ui/src/lib/components/po-field/po-datepicker/po-datepicker.component.ts index be9c6c2c94..a5f3640175 100644 --- a/projects/ui/src/lib/components/po-field/po-datepicker/po-datepicker.component.ts +++ b/projects/ui/src/lib/components/po-field/po-datepicker/po-datepicker.component.ts @@ -79,7 +79,7 @@ const poCalendarPositionDefault = 'bottom-left'; }) export class PoDatepickerComponent extends PoDatepickerBaseComponent implements AfterViewInit, OnDestroy { @ViewChild('calendar', { static: true }) calendar: PoCalendarComponent; - @ViewChild('dialogPicker', { read: ElementRef, static: true }) dialogPicker: ElementRef; + @ViewChild('dialogPicker', { read: ElementRef, static: false }) dialogPicker: ElementRef; @ViewChild('iconDatepicker') iconDatepicker: PoButtonComponent; @ViewChild('inp', { read: ElementRef, static: true }) inputEl: ElementRef; @@ -434,22 +434,24 @@ export class PoDatepickerComponent extends PoDatepickerBaseComponent implements window.removeEventListener('scroll', this.onScroll, true); } - private setDialogPickerStyleDisplay(value) { - this.dialogPicker.nativeElement.style.display = value; + private setDialogPickerStyleDisplay(value: string): void { + if (this.dialogPicker && this.dialogPicker.nativeElement) { + this.dialogPicker.nativeElement.style.display = value; + } } - private setCalendarPosition() { + private setCalendarPosition(): void { this.setDialogPickerStyleDisplay('block'); - - this.controlPosition.setElements( - this.dialogPicker.nativeElement, - poCalendarContentOffset, - this.inputEl, - ['top-left', 'top-right', 'bottom-left', 'bottom-right'], - false, - true - ); - - this.controlPosition.adjustPosition(poCalendarPositionDefault); + if (this.dialogPicker && this.dialogPicker.nativeElement) { + this.controlPosition.setElements( + this.dialogPicker.nativeElement, + poCalendarContentOffset, + this.inputEl, + ['top-left', 'top-right', 'bottom-left', 'bottom-right'], + false, + true + ); + this.controlPosition.adjustPosition(poCalendarPositionDefault); + } } } diff --git a/projects/ui/src/lib/components/po-field/po-datepicker/po-datepicker.module.ts b/projects/ui/src/lib/components/po-field/po-datepicker/po-datepicker.module.ts index 5d5505169d..f3782c6810 100644 --- a/projects/ui/src/lib/components/po-field/po-datepicker/po-datepicker.module.ts +++ b/projects/ui/src/lib/components/po-field/po-datepicker/po-datepicker.module.ts @@ -8,6 +8,7 @@ import { PoCleanModule } from '../po-clean/po-clean.module'; import { PoButtonModule } from '../../po-button'; import { PoDatepickerComponent } from './po-datepicker.component'; +import { OverlayModule } from '@angular/cdk/overlay'; /** * @description @@ -15,7 +16,15 @@ import { PoDatepickerComponent } from './po-datepicker.component'; * Módulo do componente `po-datepicker`. */ @NgModule({ - imports: [CommonModule, FormsModule, PoFieldContainerModule, PoCleanModule, PoCalendarModule, PoButtonModule], + imports: [ + CommonModule, + FormsModule, + PoFieldContainerModule, + OverlayModule, + PoCleanModule, + PoCalendarModule, + PoButtonModule + ], exports: [PoDatepickerComponent], declarations: [PoDatepickerComponent] })