refactor(button): update click handling and aria attributes for better accessibility
This commit is contained in:
@@ -135,7 +135,6 @@
|
|||||||
hostClass="checkout-payment__action-btn"
|
hostClass="checkout-payment__action-btn"
|
||||||
buttonClass="w-100"
|
buttonClass="w-100"
|
||||||
[disabled]="true"
|
[disabled]="true"
|
||||||
(click)="cancelStep.emit()"
|
|
||||||
>
|
>
|
||||||
Cancelar
|
Cancelar
|
||||||
</app-button>
|
</app-button>
|
||||||
|
|||||||
@@ -17,7 +17,9 @@ export type ButtonVariant =
|
|||||||
styleUrl: './button.component.scss',
|
styleUrl: './button.component.scss',
|
||||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||||
host: {
|
host: {
|
||||||
'[class]': 'hostClass()'
|
'[class]': 'hostClasses()',
|
||||||
|
'[attr.aria-disabled]': 'disabled()',
|
||||||
|
'(click)': 'onHostClick($event)'
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
export class ButtonComponent {
|
export class ButtonComponent {
|
||||||
@@ -26,6 +28,9 @@ export class ButtonComponent {
|
|||||||
readonly disabled = input(false);
|
readonly disabled = input(false);
|
||||||
readonly hostClass = input<string>('');
|
readonly hostClass = input<string>('');
|
||||||
readonly buttonClass = input<string>('');
|
readonly buttonClass = input<string>('');
|
||||||
|
protected readonly hostClasses = computed(() =>
|
||||||
|
[this.hostClass(), this.disabled() ? 'app-button--disabled' : ''].filter(Boolean).join(' ')
|
||||||
|
);
|
||||||
|
|
||||||
protected readonly buttonClasses = computed(() => {
|
protected readonly buttonClasses = computed(() => {
|
||||||
const variants: Record<ButtonVariant, string> = {
|
const variants: Record<ButtonVariant, string> = {
|
||||||
@@ -40,4 +45,14 @@ export class ButtonComponent {
|
|||||||
|
|
||||||
return ['btn', variants[this.variant()], this.buttonClass()];
|
return ['btn', variants[this.variant()], this.buttonClass()];
|
||||||
});
|
});
|
||||||
|
|
||||||
|
protected onHostClick(event: Event): void {
|
||||||
|
if (!this.disabled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
|
event.stopImmediatePropagation();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user