Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions projects/ion-test-app/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1188,6 +1188,13 @@ export class AppComponent implements OnInit {
disabled: true,
multiple: true,
},
{
key: 'data_abertura',
className: 'col-6',
type: 'datepicker',
label: 'Data de Abertura',
disabled: true,
},
{
key: 'bio',
className: 'col-12',
Expand Down
1 change: 1 addition & 0 deletions projects/ion/src/lib/core/bn-form/bn-form.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ import { BnMaskDirective } from '../../mask/mask.directive';
[rangePicker]="field.rangePicker ?? false"
[direction]="field.direction"
[disabledDate]="field.disabledDate"
[disabled]="isDisabled(field)"
[predefinedRanges]="field.predefinedRanges ?? []"
[value]="formGroup().get(field.key)?.value"
(event)="onValueChange(field.key, $event)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
data-testid="container-input"
>
<ion-input
data-testid="date-picker-input-element"
[value]="date() || ''"
[placeholder]="placeholder()"
[iconInput]="date() ? '' : 'calendar'"
iconDirection="right"
[inputButton]="!!date()"
[inputButtonConfig]="clearButtonConfig"
[readonly]="true"
[disabled]="disabled()"
(clickButton)="clearDateValue()"
></ion-input>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,30 @@ describe('IonDatePickerInputComponent', () => {

expect(clearSpy).toHaveBeenCalled();
});

it('should be disabled when disabled input is true', () => {
const fixture = TestBed.createComponent(IonDatePickerInputComponent);
fixture.componentRef.setInput('disabled', true);
fixture.detectChanges();

const inputElement = screen.getByTestId('input-div');
expect(inputElement).toHaveClass('disabled');
});

it('should not emit clearDate when disabled', () => {
const fixture = TestBed.createComponent(IonDatePickerInputComponent);
fixture.componentRef.setInput('date', '2023-01-28');
fixture.componentRef.setInput('disabled', true);
fixture.detectChanges();

const clearSpy = jest.fn();
fixture.componentRef.instance.clearDate.subscribe(clearSpy);

const clearButton = screen.queryByTestId('input-button');
if (clearButton) {
fireEvent.click(within(clearButton).getByRole('button'));
}

expect(clearSpy).not.toHaveBeenCalled();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export class IonDatePickerInputComponent {
rangePicker = input<boolean>(false);
placeholder = input<string>('Selecione a data');
clearDate = output<void>();
disabled = input<boolean>(false);

public clearButtonConfig: IonButtonProps = {
iconType: 'close-solid',
Expand All @@ -34,6 +35,7 @@ export class IonDatePickerInputComponent {
};

clearDateValue(): void {
if(this.disabled()) return;
this.clearDate.emit();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#trigger="cdkOverlayOrigin"
[date]="inputDate()"
[rangePicker]="rangePicker()"
[disabled]="disabled()"
(click)="setVisibleCalendar(!showDatepicker())"
(clearDate)="clearDate()"
></date-picker-input>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,31 @@ describe('IonDatepickerComponent with CDK Overlay', () => {
overlayContainerElement.querySelector('.container-calendar'),
).toBeFalsy();
});

it('should not open overlay when disabled and clicked', () => {
fixture.componentRef.setInput('disabled', true);
fixture.detectChanges();

const inputDebug = fixture.debugElement.query(By.css('date-picker-input'));
inputDebug.triggerEventHandler('click', null);
fixture.detectChanges();

const calendarContainer = overlayContainerElement.querySelector(
'.container-calendar',
);
expect(calendarContainer).toBeFalsy();
});

it('should not open overlay via setVisibleCalendar when disabled', () => {
fixture.componentRef.setInput('disabled', true);
fixture.detectChanges();

component.setVisibleCalendar(true);
fixture.detectChanges();

const calendarContainer = overlayContainerElement.querySelector(
'.container-calendar',
);
expect(calendarContainer).toBeFalsy();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export class IonDatepickerComponent {
>(undefined);
goToMonth = signal<string | undefined>(undefined);
goToYear = signal<string | undefined>(undefined);
disabled = input<boolean>(false);

overlayPositions = computed<ConnectedPosition[]>(() => {
const direction = String(
Expand Down Expand Up @@ -159,6 +160,9 @@ export class IonDatepickerComponent {
}

setVisibleCalendar(visible: boolean): void {
if (this.disabled()) {
return;
}
this.showDatepicker.set(visible);
}

Expand Down