Skip to content

Commit

Permalink
feat(stepper): cria a propriedade p-disable-click
Browse files Browse the repository at this point in the history
Cria propriedade `p-disable-click` para desabilitar o clique no step

DTHFUI-9924
  • Loading branch information
jcorrea97 committed Nov 22, 2024
1 parent 4c81889 commit df216b1
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,17 @@ export class PoStepperBaseComponent {
*/
@Input('p-step-icon-active') iconActive?: string | TemplateRef<void>;

/**
* @optional
*
* @description
*
* Desabilita a possibilidade de ir para outra etapa clicando diretamente no step.
*
* @default `false`
*/
@Input('p-disable-click') disabledClick: boolean = false;

private initializeSteps(): void {
const hasStatus = this._steps.some(step => step.status !== PoStepperStatus.Default);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,15 @@ describe('PoStepperStepComponent:', () => {
expect(component.click.emit).not.toHaveBeenCalled();
});

it('onClick: shouldn´t call `click.emit` if `disabledClick` is `true`.', () => {
component.status = PoStepperStatus.Active;
component.disabledClick = true;
spyOn(component.click, 'emit');
component.onClick();

expect(component.click.emit).not.toHaveBeenCalled();
});

it('onEnter: should call `click.emit` if `status` is different of `disabled`.', () => {
component.status = PoStepperStatus.Active;

Expand All @@ -212,6 +221,15 @@ describe('PoStepperStepComponent:', () => {
expect(component.enter.emit).not.toHaveBeenCalled();
});

it('onEnter: shouldn´t call `click.emit` if `disabledClick` is `true`.', () => {
component.status = PoStepperStatus.Active;
component.disabledClick = true;
spyOn(component.enter, 'emit');
component.onEnter();

expect(component.enter.emit).not.toHaveBeenCalled();
});

it('setDefaultStepSize: should increase step size by 8px if status is `Active` and step size is default.', () => {
(component as any)._stepSize = 24;
component.status = PoStepperStatus.Active;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ export class PoStepperStepComponent implements OnChanges {
// Evento que será emitido ao focar no *step* e pressionar a tecla *enter*.
@Output('p-enter') enter = new EventEmitter<any>();

@Input('p-disable-click') disabledClick: boolean = false;

readonly literals = {
...poStepLiteralsDefault[poLocaleDefault],
...poStepLiteralsDefault[getShortBrowserLanguage()]
Expand Down Expand Up @@ -169,13 +171,13 @@ export class PoStepperStepComponent implements OnChanges {
}

onClick(): void {
if (this.status !== PoStepperStatus.Disabled) {
if (this.status !== PoStepperStatus.Disabled && !this.disabledClick) {
this.click.emit();
}
}

onEnter(): void {
if (this.status !== PoStepperStatus.Disabled) {
if (this.status !== PoStepperStatus.Disabled && !this.disabledClick) {
this.enter.emit();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
[p-step-icon-active]="iconActive"
[p-step-icon-done]="iconDone"
[p-vertical-orientation]="isVerticalOrientation"
[p-disable-click]="disabledClick"
(p-activated)="onStepActive(step)"
(p-click)="changeStep(index, step)"
(p-enter)="changeStep(index, step)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
[p-step-size]="properties.stepSize"
[p-step-icon-active]="properties.iconActive"
[p-step-icon-done]="properties.iconDone"
[p-disable-click]="properties.disabledClick"
(p-change-step)="changeStep('change')"
>
<po-step *ngFor="let step of steps" [p-label]="step.label" [p-icon-default]="step.iconDefault">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ export class SamplePoStepperLabsComponent implements OnInit {
help: 'Ex.: ph ph-check-fat',
gridLgColumns: 4,
property: 'iconDone'
},
{
label: 'Disabled click',
property: 'disabledClick',
type: 'boolean'
}
];

Expand Down

0 comments on commit df216b1

Please sign in to comment.